// JavaScript functions to manipulate the images on the VRSG 3D content pages and define standard variables
//	used on all the 3D model pages

// Ultimate client-side JavaScript client sniff. Version 3.03
// (C) Netscape Communications 1999-2001.  Permission granted to reuse and distribute.

// convert all characters to lowercase to simplify testing

    var agt = navigator.userAgent.toLowerCase();

// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.

    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

//alert("agt="+agt+" is_major="+is_major+" is_minor="+is_minor);

   var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
	var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );
    var is_gecko = (agt.indexOf('gecko') != -1);

    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5")!=-1));
	var is_ie5_1   = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.1")!=-1));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie3    = (is_ie && (is_major < 4));

    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_1);
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);	
    var is_ie4up  = (is_ie && (is_major >= 4));

// Define variables

	var i;
	var prevModel;
	var currModel;
	var thumbPath;
	var bigPath;
	var tempvar;

// Define arrays that will contain each 3d model skin.  No need to edit this unless more than four models per
//	row or 5 rows will be displayed on a page.

	var a1 = new Array();
	a1[0] = 1;
	var a2 = new Array();
	a2[0] = 1;
	var a3 = new Array();	
	a3[0] = 1;
	var a4 = new Array();
	a4[0] = 1;

	var b1 = new Array();
	b1[0] = 1;
	var b2 = new Array();	
	b2[0] = 1;
	var b3 = new Array();
	b3[0] = 1;
	var b4 = new Array();
	b4[0] = 1;

	var c1 = new Array();
	c1[0] = 1;
	var c2 = new Array();	
	c2[0] = 1;
	var c3 = new Array();
	c3[0] = 1;
	var c4 = new Array();
	c4[0] = 1;

	var d1 = new Array();
	d1[0] = 1;
	var d2 = new Array();	
	d2[0] = 1;
	var d3 = new Array();
	d3[0] = 1;
	var d4 = new Array();
	d4[0] = 1;

	var e1 = new Array();
	e1[0] = 1;
	var e2 = new Array();	
	e2[0] = 1;
	var e3 = new Array();
	e3[0] = 1;
	var e4 = new Array();
	e4[0] = 1;

//////////////////////////////////////
//
// Function to pop up a window with the larger image of the thumbnail
//
//////////////////////////////////////	

function modelWin(loc) {

    win = window.open('', 'ModelWin', 'width=525,height=525,resizable=yes,scrollbars=yes');
    if (win != null) {
        win.location.href = loc;
		win.focus();
    }
}


//////////////////////////////////////
//
// Function to cycle the skins backward for each model
//
//////////////////////////////////////	

function prevSkin(model) {

	if (document.images) {

// Check model array index 0 to see if it's greater than 1.  By default all model array index 0's are set to 1,
//	the first index at which a skin is stored.  If it's greater than one, then this a skin on this model has 
//	been viewed before, it not it is a new model that is being viewed.

		if (eval(model)[0]>1) {		

// Set i equal to the number stored in the array to the next skin in the series can be pulled in order

			i = eval(model)[0];
		} 		

// Only cycle down a skin if higher than first one, index 1

		if (i>1) {
				
			i --;			
			document.images[model].src = thumbPath + eval(model)[i];

// Change right arrow back to blue because now the next skin is available again

			rightArrow = model + "right";
			document.images[rightArrow].src = "vrsg3dcontent/flipper_right_blue.gif";

// Change zoom icon to gray (unavailable option)

			zoom = model + "zoom";
			document.images[zoom].src = "vrsg3dcontent/zoom_grey.gif";
			
// Define zoom links for the larger image

			link1 = model + "link1";
			link2 = model + "link2";

// Change left arrow to gray, zoom icon to blue, and reset zoom links for the larger images since the model
//	is back to its first skin.

			if (i==1) {
				leftArrow = model + "left";
				
				document.images[leftArrow].src = "vrsg3dcontent/flipper_left_grey.gif";
				document.images[zoom].src = "vrsg3dcontent/zoom_blue.gif";
				
				if (document.all) {	//IE

					document.all[link1].href = "JavaScript:modelWin('" + bigPath + eval(model)[1] + "')";
					document.all[link2].href = "JavaScript:modelWin('" + bigPath + eval(model)[1] + "')";

				} else if (document.layers) { 	// Netscape 4

//	Nothing.  Netscape 4 doesn't seem to support changing the url of a link
//					for (a = 0; a < document.anchors.length; a++) {
//						if (document.anchors[a].name == link1) {
//        					document.anchors[a].src = "JavaScript:modelWin('" + bigPath + eval(model)[1] + "')";
//						} else if (document.anchors[a].name == link2) {
//         					document.anchors[a].src = "JavaScript:modelWin('" + bigPath + eval(model)[1] + "')";
//						}
//					}	

				} else if (document.links) {	// Netscape 6+				

					document.links[link1].href = "JavaScript:modelWin('" + bigPath+ eval(model)[1] + "')";
					document.links[link2].href = "JavaScript:modelWin('" + bigPath + eval(model)[1] + "')";
				}
			}

// Update the array to store the index of the last skin that was viewed.

			if (is_ie3 || is_ie4 || is_ie5 || is_ie5_1) {	// IE 5 and lower don't support the splice method for replacing 
				eval(model)[0] = i;							// 	array elements.  While newer versions and Netscape require it.
			} else {	
				tempvar = eval(model).splice(0, 1, i);	
			}	
		}	
	}
}


//////////////////////////////////////
//
// Function to cycle the skins forward for each model
//
//////////////////////////////////////	

function nextSkin(model) {

	if (document.images) {

// Check model array index 0 to see if it's greater than 1.  By default all model array index 0's are set to 1,
//	the first index at which a skin is stored.  If it's greater than one, then this a skin on this model has 
//	been viewed before, it not it is a new model that is being viewed.

		if (eval(model)[0]>1) {
		
// Set i equal to the number stored in the array to the next skin in the series can be pulled in order

			i = eval(model)[0];			

// Else it's a new model being viewed.  Define i = 1 to start with the first index and skin.

		} else {
			i = 1;
		}

// Prevent scrolling the image array past its defined indices

		if (i<eval(model).length-1) {
		
			i ++;
			document.images[model].src = thumbPath + eval(model)[i];

// Change left arrow to blue because now the previous skin is available

			leftArrow = model + "left";
			document.images[leftArrow].src = "vrsg3dcontent/flipper_left_blue.gif";

// Change the zoom icon to gray since we're no longer on the first image

			zoom = model + "zoom";
			document.images[zoom].src = "vrsg3dcontent/zoom_grey.gif";

// Change the zoom links for the larger image to void

			link1 = model + "link1";
			link2 = model + "link2";

			if (document.all) {		// IE

					document.all[link1].href = "JavaScript:void(0)";
					document.all[link2].href = "JavaScript:void(0)";

			} else if (document.layers) {	// Netscape 4

//	Nothing.  Netscape 4 doesn't seem to support changing the url of a link
//				for (a = 0; a < document.layers.length; a++) {
//					if (document.anchors[a].name == link1) {
//        				document.anchors[a].src = "JavaScript:void(0)";
//					} else if (document.anchors[a].name == link2) {
//        				document.anchors[a].src = "JavaScript:void(0)";
//					}
//				}

			} else if (document.links) {	// Netscape 6+

				document.links[link1].href = "JavaScript:void(0)";
				document.links[link2].href = "JavaScript:void(0)";
			} 						

// If at the last index, change forward arrow to gray (unavailable option)

			if (i==eval(model).length-1) {

				rightArrow = model + "right";
				document.images[rightArrow].src = "vrsg3dcontent/flipper_right_grey.gif";
			}

// Update the array to store the index of the last skin that was viewed			

			if (is_ie3 || is_ie4 || is_ie5 || is_ie5_1) {	// IE 5 and lower don't support the splice method for replacing
				eval(model)[0] = i;							// 	array elements.  While newer versions and Netscape require it.
			} else {
				tempvar = eval(model).splice(0, 1, i);
			}
		}
	}
}