// JavaScript Document

/*******************************************************************************************************
LOGIC FOR MOUSEOVER, CLICK, and CLICKNEW
PRELOAD
-------
1. Create and set variables for each size to true

MOUSEOVER and MOUSEOUT
----------------------
1. The onMouseOver event calls MM_swapImage('[name of image to be swapped]','','[file to swap in]',1)
2. OnMouseOut, call MM_swapImageRestore([size value])
	2a. MM_swapImageRestore evaluates the size var passed in against the list of Restore variables.
	2b. When it finds a match, it checks the state of that restore variable. if it is true, it swaps the image back to its original image.
	2c. If the var has been set to false, it does not swap the image back (the click event changes it to false).

ONCLICK
-------
1. Click event calls noRestore(size) to flip Restore variable to false.
2. noRestore first calls JG_SwitchBack() which uses a series of If statements to evaluate if any of the Restore variables are false (they were clicked before).
3. For each variable, if it is False, it calls JG_swapImage('[name of previous selection]','','[original load file]',1) to change the previously 
   clicked image back to unclicked.
4. It then sets the Restore variable for that size back to true (able to be flipped).
5. For all other variables that are not false, it ignores them since they are already true.
6. Program then returns to noRestore and compares the size var passed in to a switch case for each size.
7. If the size matches, it changes the corresponding restore variable to false, and then calls JG_SwapImage([vars]) to switch the image to the selected image. 

********************************************************************************************************
*/

//TODO: function to change images onmouseover
//TODO: function to change header image, order box image onclick

// By default, restore is enabled for each button

//JG: 10-05-06: Adding sizes 8-13 small
var Restore08 = true;
var Restore09 = true;
var Restore10 = true;
var Restore11 = true;
var Restore12 = true;
var Restore1301 = true;

var Restore13 = true;
var Restore14 = true;
var Restore15 = true;
var Restore16 = true;
var Restore17 = true;
var Restore18 = true;
var Restore19 = true;
var Restore20 = true;
var Restore21 = true;
var Restore22 = true;

function noRestore (size) {
//Evaluate all switches first. if any switch is false, call the restore function for that image
JG_SwitchBack ();

	switch(size){
		//JG: 10-05-06: Adding small sizes
	case 08:
	smCollars = window.open('small_collars.htm', 'smCollars', 'width=450, height=540');
	 				smCollars.moveTo(500, 400);
		Restore08 = false; //flip the flag to false
		JG_swapImage('TL_small_8','','images/TL_products_size_bar_edi-45.gif',1);
		JG_swapImage('TL_order_06','','images/TL_order_box_8.gif',1);  // add to order box
		break; //call swapImage to change image
	
	case 09:
		smCollars = window.open('small_collars.htm', 'smCollars', 'width=450, height=540');
	 				smCollars.moveTo(500, 400);

		Restore09 = false; //flip the flag to false
		JG_swapImage('TL_small_9','','images/TL_products_size_bar_edi-48.gif',1);
		JG_swapImage('TL_order_06','','images/TL_order_box_9.gif',1);  // add to order box
		break; //call swapImage to change image
	
	case 10:
		smCollars = window.open('small_collars.htm', 'smCollars', 'width=450, height=540');
	 				smCollars.moveTo(500, 400);

		Restore10 = false; //flip the flag to false
		JG_swapImage('TL_small_10','','images/TL_products_size_bar_edi-52.gif',1);
		JG_swapImage('TL_order_06','','images/TL_order_box_10.gif',1);  // add to order box
		break; //call swapImage to change image
		
	case 11:
		smCollars = window.open('small_collars.htm', 'smCollars', 'width=450, height=540');
	 				smCollars.moveTo(500, 400);

		Restore11 = false; //flip the flag to false
		JG_swapImage('TL_small_11','','images/TL_products_size_bar_edi-57.gif',1);
		JG_swapImage('TL_order_06','','images/TL_order_box_11.gif',1);  // add to order box
		break; //call swapImage to change image
	
	case 12:
		smCollars = window.open('small_collars.htm', 'smCollars', 'width=450, height=540');
	 				smCollars.moveTo(500, 400);

		Restore12 = false; //flip the flag to false
		JG_swapImage('TL_small_12','','images/TL_products_size_bar_edi-60.gif',1);
		JG_swapImage('TL_order_06','','images/TL_order_box_12.gif',1);  // add to order box
		break; //call swapImage to change image
	
	case 1301:
		smCollars = window.open('small_collars.htm', 'smCollars', 'width=450, height=540');
	 				smCollars.moveTo(500, 400);

		Restore1301 = false; //flip the flag to false
		JG_swapImage('TL_small_13','','images/13_small-over.gif',1);
		JG_swapImage('TL_order_06','','images/TL_order_box_1301.gif',1);  // add to order box
		break; //call swapImage to change image
		
	case 13:
		Restore13 = false; //flip the flag to false
		JG_swapImage('TL_products_size_bar_02','','images/TL_products_size_bar_02--05.gif',1);
		JG_swapImage('TL_order_06','','images/TL_order_box_13_LARGE.gif',1);  // add to order box
		break; //call swapImage to change image
	case 14:
		Restore14 = false; //flip the flag to false
		JG_swapImage('TL_products_size_bar_03','','images/TL_products_size_bar_03--09.gif',1); //call swapImage to change image
		JG_swapImage('TL_order_06','','images/TL_order_06-TL_order_03_14.gif',1);  // add to order box
		break;
	case 15:
		Restore15 = false; //flip the flag to false
		JG_swapImage('TL_products_size_bar_04','','images/TL_products_size_bar_04--13.gif',1); //call swapImage to change image
		JG_swapImage('TL_order_06','','images/TL_order_06-TL_order_03_15.gif',1);  // add to order box
		break;
	case 16:
		Restore16 = false; //flip the flag to false
		JG_swapImage('TL_products_size_bar_05','','images/TL_products_size_bar_05--17.gif',1); //call swapImage to change image
		JG_swapImage('TL_order_06','','images/TL_order_06-TL_order_03_16.gif',1);  // add to order box
		break;
	case 17:
		Restore17 = false; //flip the flag to false
		JG_swapImage('TL_products_size_bar_06','','images/TL_products_size_bar_06-ove.gif',1); //call swapImage to change image
		JG_swapImage('TL_order_06','','images/TL_order_06-TL_order_03_17.gif',1);  // add to order box
		break;
	case 18:
		Restore18 = false; //flip the flag to false
		JG_swapImage('TL_products_size_bar_07','','images/TL_products_size_bar_07--25.gif',1); //call swapImage to change image
		JG_swapImage('TL_order_06','','images/TL_order_06-TL_order_03_18.gif',1);  // add to order box
		break;
	case 19:
		Restore19 = false; //flip the flag to false
		JG_swapImage('TL_products_size_bar_08','','images/TL_products_size_bar_08--29.gif',1); //call swapImage to change image
		JG_swapImage('TL_order_06','','images/TL_order_06-TL_order_03_19.gif',1);  // add to order box
		break;
	case 20:
		Restore20 = false; //flip the flag to false
		JG_swapImage('TL_products_size_bar_09','','images/TL_products_size_bar_09--33.gif',1); //call swapImage to change image
		JG_swapImage('TL_order_06','','images/TL_order_06-TL_order_03_20.gif',1);  // add to order box
		break;
	case 21:
		Restore21 = false; //flip the flag to false
		JG_swapImage('TL_products_size_bar_10','','images/TL_products_size_bar_10--37.gif',1);
		JG_swapImage('TL_order_06','','images/TL_order_06-TL_order_03_21.gif',1);  // add to order box
		break; //call swapImage to change image
	case 22:
		Restore22 = false; //flip the flag to false
		JG_swapImage('TL_products_size_bar_11','','images/TL_products_size_bar_11-ove.gif',1);
		JG_swapImage('TL_order_06','','images/TL_order_06-TL_order_03_22.gif',1);  // add to order box
		break; //call swapImage to change image
	}
}

function JG_SwitchBack () { //this function should call swapImage to set an image back to its original state if it is currently set to false.
//logic here is to evaluate if any of the switches are flipped. if false, then flip to true.

	if (Restore08 == false) {
		JG_swapImage('TL_small_8','','images/TL_products_size_bar_edi-43.gif',1);
				Restore08 = true;} //reset the flag
	if (Restore09 == false) {
		JG_swapImage('TL_small_9','','images/TL_products_size_bar_edi-47.gif',1);
				Restore09 = true;} //reset the flag
	if (Restore10 == false) {
		JG_swapImage('TL_small_10','','images/TL_products_size_bar_edi-51.gif',1);
				Restore10 = true;} //reset the flag
	if (Restore11 == false) {
		JG_swapImage('TL_small_11','','images/TL_products_size_bar_edi-55.gif',1);
				Restore11 = true;} //reset the flag
	if (Restore12 == false) {
		JG_swapImage('TL_small_12','','images/TL_products_size_bar_edi-59.gif',1);
				Restore12 = true;} //reset the flag
	if (Restore1301 == false) {
		JG_swapImage('TL_small_13','','images/13_small.gif',1);
				Restore1301 = true;} //reset the flag

	if (Restore13 == false) {
		JG_swapImage('TL_products_size_bar_02','','images/TL_products_size_bar_02.gif',1);
		Restore13 = true;} //reset the flag
	if (Restore14 == false) {
		JG_swapImage('TL_products_size_bar_03','','images/TL_products_size_bar_03.gif',1);
		Restore14 = true;} //reset the flag}
	if (Restore15 == false) {
		JG_swapImage('TL_products_size_bar_04','','images/TL_products_size_bar_04.gif',1);
		Restore15 = true;} //reset the flag}
	if (Restore16 == false) {
		JG_swapImage('TL_products_size_bar_05','','images/TL_products_size_bar_05.gif',1);
		Restore16 = true;} //reset the flag}
	if (Restore17 == false) {
		JG_swapImage('TL_products_size_bar_06','','images/TL_products_size_bar_06.gif',1);
		Restore17 = true;} //reset the flag}
	if (Restore18 == false) {
		JG_swapImage('TL_products_size_bar_07','','images/TL_products_size_bar_07.gif',1);
		Restore18 = true;} //reset the flag}
	if (Restore19 == false) {
		JG_swapImage('TL_products_size_bar_08','','images/TL_products_size_bar_08.gif',1);
		Restore19 = true;} //reset the flag}
	if (Restore20 == false) {
		JG_swapImage('TL_products_size_bar_09','','images/TL_products_size_bar_09.gif',1);
		Restore20 = true;} //reset the flag}
	if (Restore21 == false) {
		JG_swapImage('TL_products_size_bar_10','','images/TL_products_size_bar_10.gif',1);
		Restore21 = true;} //reset the flag}
	if (Restore22 == false) {
		JG_swapImage('TL_products_size_bar_11','','images/TL_products_size_bar_11.gif',1);
		Restore22 = true;} //reset the flag}
}

function JG_swapImage() { //v3.0
  var i,j=0,x,a=JG_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var swapImage = true;
/*
function MM_preloadImages() { //v3.0
  //JG_TEST();
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
*/
function JG_restoreImage (size) {
	//window.alert ("swapimgrestore with size var "+size)

	switch (size) {
		case 08 : 
	//window.alert("restore13 evaluated");
	if (Restore08 == true) {
	//window.alert("Restore13 is "+Restore13);
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
	//else {//window.alert("Restore13 = "+Restore13)
	//};
	break;
		case 09 : 
	//window.alert("restore13 evaluated");
	if (Restore09 == true) {
	//window.alert("Restore13 is "+Restore13);
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
	//else {//window.alert("Restore13 = "+Restore13)
	//};
	break;
		case 10 : 
	//window.alert("restore13 evaluated");
	if (Restore10 == true) {
	//window.alert("Restore13 is "+Restore13);
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
	//else {//window.alert("Restore13 = "+Restore13)
	//};
	break;
		case 11 : 
	//window.alert("restore13 evaluated");
	if (Restore11 == true) {
	//window.alert("Restore13 is "+Restore13);
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
	//else {//window.alert("Restore13 = "+Restore13)
	//};
	break;
		case 12 : 
	//window.alert("restore13 evaluated");
	if (Restore12 == true) {
	//window.alert("Restore13 is "+Restore13);
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
	//else {//window.alert("Restore13 = "+Restore13)
	//};
	break;
		case 1301 : 
	//window.alert("restore13 evaluated");
	if (Restore1301 == true) {
	//window.alert("Restore13 is "+Restore13);
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
	//else {//window.alert("Restore13 = "+Restore13)
	//};
	break;
		
	case 13 : 
	//window.alert("restore13 evaluated");
	if (Restore13 == true) {
	//window.alert("Restore13 is "+Restore13);
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
	//else {//window.alert("Restore13 = "+Restore13)
	//};
	break;
	case 14 : 
	//window.alert("restore14 evaluated");
	if (Restore14 == true) {
	//window.alert("Restore14 is "+Restore14);
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
	//else {window.alert("Restore14 = "+Restore14)};
	break;
	case 15 : 
	//window.alert("restore15 evaluated");
	if (Restore15 == true) {
	//window.alert("Restore15 is "+Restore15);
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
	//else {window.alert("Restore15 = "+Restore15)};
	break;
	case 16 : 
	//window.alert("restore16 evaluated");
	if (Restore16 == true) {
	//window.alert("Restore16 is "+Restore16);
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
	//else {window.alert("Restore16 = "+Restore16)};
	break;
	case 17 : 
	//window.alert("restore17 evaluated");
	if (Restore17 == true) {
	//window.alert("Restore17 is "+Restore17);
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
	//else {window.alert("Restore17 = "+Restore17)};
	break;
	case 18 : 
	//window.alert("restore18 evaluated");
	if (Restore18 == true) {
	//window.alert("Restore18 is "+Restore18);
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
	//else {window.alert("Restore18 = "+Restore18)};
	break;
	case 19 : 
	//window.alert("restore19 evaluated");
	if (Restore19 == true) {
	//window.alert("Restore19 is "+Restore19);
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
	//else {window.alert("Restore19 = "+Restore19)};
	break;
	case 20 : 
	//window.alert("restore20 evaluated");
	if (Restore20 == true) {
	//window.alert("Restore20 is "+Restore20);
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
	//else {window.alert("Restore20 = "+Restore20)};
	break;
	case 21 : 
	//window.alert("restore21 evaluated");
	if (Restore21 == true) {
	//window.alert("Restore21 is "+Restore21);
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
	//else {window.alert("Restore21 = "+Restore21)};
	break;
	case 22 : 
	//window.alert("restore13 evaluated");
	if (Restore22 == true) {
	//window.alert("Restore22 is "+Restore22);
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
	//else {window.alert("Restore22 = "+Restore22)};
	break;
	}
}


function TurnOnRestore(size) {  //This function flips the bits of all but the passed in var
/* if the name of the var passed in does not equal the name of the size below, flip the bit to true.
*/
// array mapped to the global vars for restore on and off
var sizeVariableArray = new Array(10)
	sizeVariableArray[0]=Restore13;
	sizeVariableArray[1]=Restore14;
	sizeVariableArray[2]=Restore15;
	sizeVariableArray[3]=Restore16;
	sizeVariableArray[4]=Restore17;
	sizeVariableArray[5]=Restore18;
	sizeVariableArray[6]=Restore19;
	sizeVariableArray[7]=Restore20;
	sizeVariableArray[8]=Restore21;
	sizeVariableArray[9]=Restore22;
//set all flags to true (go ahead and restore)
	var x=0;
	for (x=0; x<10; x++) {
	sizeVariableArray[x] = true;
	};
// now flip the switch on the the one that was passed in
	window.alert(size);
	switch (size) {
	case 13 : 
		Restore13 = false;
		break;
	case 14 : 
		Restore14 = false;
		break;
	case 15 : 
		Restore15 = false;
		break;
	case 16 : 
		Restore16 = false;
		break;
	case 17 : 
		Restore17 = false;
		break;
	case 18 : 
		Restore18 = false;
		break;
	case 19 : 
		Restore19 = false;
		break;
	case 20 : 
		Restore20 = false;
		break;
	case 21 : 
		Restore21 = false;
		break;
	case 22 : 
		Restore22 = false;
		break;
	}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/*function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3)
  //window.alert (swapImage);
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
*/
function JG_swapSizeImage() { //v3.0
  var i,j=0,x,a=JG_swapSizeImage.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3)
  //window.alert (swapImage);
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//function JG_restoreImage() { //v3.0
//  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
//}