﻿var pageURL = "index.jsp";

var stepImages = new Array("panel4a.png","panel4b.png","panel4c.png");
var imageId=1,
	curleft,
	curtop,
	targetOpacity=100,
	opacityTimerMS=15,
	stepTimer,
	opacityTimer,
	imageURL;

function init()
{
    for (var i=0; i<stepImages.length; ++i){
    	imageURL = stepImages[i];
    	stepImages[i] = new Image();
    	stepImages[i].src = "images/"+imageURL;
    }
    setTimeout('rotateStep(2);',5000);
//    xRight('countryR',-210,0,200);
//    xLeft('countryL',-210,0,200);
//    hideCountries();
    setupZoom();
}
function showStep(id)
{
	clearTimeout(stepTimer);
	clearTimeout(opacityTimer);
	opacityTimerMS=1;
	fadeInImage(id);
}
function fadeInImage(id)
{
	for(var i=1; i<=stepImages.length; ++i){
//		document.getElementById("step"+i).style.backgroundColor=(i==id ? "#3366FF" : "");
//		document.getElementById("step"+i).style.color=(i==id ? "#FFFFFF" : "");
//		document.getElementById("stepDesc"+i).style.visibility=(i==id ? "visible" : "hidden");
	}
	imageId=id;
//	xMoveTo("fadeImage", 100,100); // xLeft("infoPanel"), xTop("infoPanel"));
	document.getElementById("fadeImage").src=stepImages[imageId-1].src;
	opacityTimer = setTimeout("changeOpacity(0)",opacityTimerMS) // ;opacity(0,100,750);
	return(false);
}
function rotateStep(id)
{
	fadeInImage(id);
	if (++id<=stepImages.length)
		stepTimer = setTimeout("rotateStep('"+id+"')", 5000);
}


function prepZooms() {
	if (! document.getElementsByTagName) {
		return;
	}
	var links = document.getElementsByTagName("img");
	for (i = 0; i < links.length; i++) {
		if (links[i].getAttribute("src").search(/(.*)\.(jpg|jpeg|gif|png|bmp|tif|tiff)/gi) != -1) {
			if (links[i].getAttribute("class") == "zoom") {
//				links[i].onclick = function (event) { return zoomClick(this, event); };
//				links[i].onmouseover = function () { zoomPreload(this); };
	           links[i].style.cursor="url(images/zoom/zoomin.cur), auto";
	           links[i].onclick = function (event) { toggleZoom(this); };
//	           links[i].onmouseout = function (event) { return zoomOut(this, event); };
			}
		}
	}
}

// Zoom: Load an image into an image object. When done loading, function sets preloadActive to false,
// so other bits know that they can proceed with the zoom.
// Preloaded image is stored in imgPreload and swapped out in the zoom function.
function toggleZoom(from){
    if(!zoomOpen){
        zoomPreload(from)
    	xGetElementById(from).style.cursor="url(images/zoom/zoomout.cur), auto";
	}else{
        zoomOut(from);
        xGetElementById(from).style.cursor="url(images/zoom/zoomin.cur), auto";
	}
}
function zoomPreload(from) {

	var theimage = from.getAttribute("src");

	// Only preload if we have to, i.e. the image isn't this image already

	if (imgPreload.src.indexOf(from.getAttribute("src").substr(from.getAttribute("src").lastIndexOf("/"))) == -1) {
		preloadActive = true;
		imgPreload = new Image();

		// Set a function to fire when the preload is complete, setting flags along the way.

		imgPreload.onload = function() {
			preloadActive = false;
		}

		// Load it!
		imgPreload.src = theimage;
		preloadActive = false;
	}
	zoomClick(from);
}
// Zoom: Move an element in to endH endW, using zoomHost as a starting point.
// "from" is an object reference to the href that spawned the zoom.

function zoomIn(from, shift) {

	zoomimg.src = from.getAttribute("src");

	// Determine the zoom settings from where we came from, the element in the <a>.
	// If there's no element in the <a>, or we can't get the width, make stuff up

	if (from.width) {
		startW = from.width;
		startH = from.height;
		startPos = findElementPos(from);
	} else {
		startW = 50;
		startH = 12;
		startPos = findElementPos(from);
	}

	hostX = startPos[0];
	hostY = startPos[1];

	// Make up for a scrolled containing div.
	// TODO: This HAS to move into findElementPos.

	if (document.getElementById('scroller')) {
		hostX = hostX - document.getElementById('scroller').scrollLeft;
	}

	// Determine the target zoom settings from the preloaded image object

	endW = imgPreload.width;
	endH = imgPreload.height;

	// Start! But only if we're not zooming already!

	if (zoomActive[theID] != true) {

		// Clear everything out just in case something is already open

		if (document.getElementById("ShadowBox")) {
			document.getElementById("ShadowBox").style.visibility = "hidden";
		} else if (! browserIsIE) {

			// Wipe timer if shadow is fading in still
			if (fadeActive["ZoomImage"]) {
				clearInterval(fadeTimer["ZoomImage"]);
				fadeActive["ZoomImage"] = false;
				fadeTimer["ZoomImage"] = false;
			}

			document.getElementById("ZoomImage").style.webkitBoxShadow = shadowSettings + '0.0)';
		}

		document.getElementById("ZoomClose").style.visibility = "hidden";

		// Setup the CAPTION, if existing. Hide it first, set the text.

		if (includeCaption) {
			document.getElementById(zoomCaptionDiv).style.visibility = "hidden";
			if (from.getAttribute('title') && includeCaption) {
				// Yes, there's a caption, set it up
				document.getElementById(zoomCaption).innerHTML = from.getAttribute('title');
			} else {
				document.getElementById(zoomCaption).innerHTML = "";
			}
		}

		// Store original position in an array for future zoomOut.

		zoomOrigW[theID] = startW;
		zoomOrigH[theID] = startH;
		zoomOrigX[theID] = hostX;
		zoomOrigY[theID] = hostY;

		// Now set the starting dimensions

		zoomimg.style.width = startW + 'px';
		zoomimg.style.height = startH + 'px';
		zoomdiv.style.left = hostX + 'px';
		zoomdiv.style.top = hostY + 'px';

		// Show the zooming image container, make it invisible

		if (includeFade == 1) {
			setOpacity(0, zoomID);
		}
		zoomdiv.style.visibility = "visible";

		// If it's too big to fit in the window, shrink the width and height to fit (with ratio).

		sizeRatio = endW / endH;
		if (endW > myWidth - minBorder) {
			endW = myWidth - minBorder;
			endH = endW / sizeRatio;
		}
		if (endH > myHeight - minBorder) {
			endH = myHeight - minBorder;
			endW = endH * sizeRatio;
		}

		zoomChangeX = ((myWidth / 2) - (endW / 2) - hostX);
//		zoomChangeY = (((myHeight / 2) - (endH / 2) - hostY) + myScroll);
        zoomChangeY = xTop("featuredGlasses") - 280;

		zoomChangeW = (endW - startW);
		zoomChangeH = (endH - startH);

		// Shift key?

		if (shift) {
			tempSteps = zoomSteps * 7;
		} else {
			tempSteps = zoomSteps;
		}

		// Setup Zoom

		zoomCurrent = 0;

		// Setup Fade with Zoom, If Requested

		if (includeFade == 1) {
			fadeCurrent = 0;
			fadeAmount = (0 - 100) / tempSteps;
		} else {
			fadeAmount = 0;
		}

		// Do It!

		zoomTimer[theID] = setInterval("zoomElement('"+zoomID+"', '"+theID+"', "+zoomCurrent+", "+startW+", "+zoomChangeW+", "+startH+", "+zoomChangeH+", "+hostX+", "+zoomChangeX+", "+hostY+", "+zoomChangeY+", "+tempSteps+", "+includeFade+", "+fadeAmount+", 'zoomDoneIn(zoomID)')", zoomTime);
		zoomActive[theID] = true;
	}
}