// JavaScript Document
var modern_medium_x;
var modern_medium_y;
var modern_medium_w;
var modern_medium_h;
var modern_large_x;
var modern_large_y;
var modern_large_w;
var modern_large_h;
var ie=document.all;

function setZoomIconParameters()
{
    var offset_y=106;
    var offset_x=168;
    if (ie) {
        offset_y=56;
        offset_x=-39;
    }
    document.getElementById("ZoomIcon").style.top=modern_medium_y+modern_medium_h+offset_y;
    document.getElementById("ZoomIcon").style.left=modern_medium_x+modern_medium_w+offset_x;
}

function setResizeParameters(medium_x, medium_y, medium_w, medium_h, large_x, large_y, large_w, large_h)
{
	modern_medium_x = medium_x;
	modern_medium_y = medium_y;
	modern_medium_w = medium_w;
	modern_medium_h = medium_h;
	modern_large_x = large_x;
	modern_large_y = large_y;
	modern_large_w = large_w;
	modern_large_h = large_h;
	setZoomIconParameters();
}

function opacity(id, opacStart, opacEnd, millisec, hideOnZero) { 
    //speed for each frame 
    //var speed = Math.round(millisec / 100); 
    var speed = 100;
    var timer = 0; 
    delta = Math.abs(opacEnd-opacStart) / (millisec/speed);

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i-=delta) { 
            setTimeout("changeOpac(" + i + ",'" + id + "'," + hideOnZero + ")",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i+=delta) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "'," + hideOnZero + ")",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id, hideOnZero) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")";
	if ((opacity==0) && hideOnZero) object.visibility="hidden";
}

function postResizeUp() {
	changeOpac(0,"ClickCapture");
	makeVisible("visible", "ClickCapture");
}

function postResizeDown() {
	makeVisible("hidden", "ClickBlock");
}

function resize(id, se, frames, millisec, hideOnEnd, reShow) { 
    //speed for each frame 
    var speed = Math.round(millisec / frames); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
	for(i=0;i<=frames;i++) {
		var top = Math.round(i*(se.topEnd-se.topStart)/frames+se.topStart);
		var left = Math.round(i*(se.leftEnd-se.leftStart)/frames+se.leftStart);
		var width = Math.round(i*(se.widthEnd-se.widthStart)/frames+se.widthStart);
		var height = Math.round(i*(se.heightEnd-se.heightStart)/frames+se.heightStart);
		setTimeout("changeSizePos(" + top + ", " + left + ", " + width + ", " + height + ", '" + id + "')", (timer * speed)); 
		timer++;
	}
	if (se.widthStart < se.widthEnd) setTimeout("postResizeUp()", (timer * speed));
	else setTimeout("postResizeDown()", (timer * speed));
	if (reShow != "") setTimeout("makeVisible('visible','" + reShow + "')", (timer * speed));
	if (hideOnEnd)  setTimeout("makeVisible('hidden','ZoomCanvas')", (timer * speed));
} 

function changeSizePos(top, left, width, height, id) { 
    var object = document.getElementById(id).style; 
	object.top = top;
	object.left = left;
	object.width = width;
	object.height = height;
}

function makeVisible(visible, id, display) {
	if (!isNotNullObject(document.getElementById(id))) return;
    var object = document.getElementById(id).style;
	object.visibility=visible;
	if (!ie) if (display!="") object.display=display;
}

function reveal(id) {
	if (!isNotNullObject(document.getElementById(id))) return;
    var object = document.getElementById(id).style;
	changeOpac(0, id, false);
	object.visibility="visible";
	opacity(id, 0, 100, 500, false)
}

function removeCloth(id, promoteZ) {
	changeOpac(100, id, false);
	opacity(id, 100, 0, 500, true)
	if (promoteZ != "") setTimeout("document.getElementById('FlashDIV').style.zIndex=2", 500);
}

var syncLoad = false;

function srcSet(objectToSet, imageLoading)
{
	objectToSet.src = imageLoading.src;
	syncLoad = true;
}

function setSrcAfterLoadComplete(id, imagePath, waitSync)
{
    syncLoad=false;
    var object = document.getElementById(id);
	var imageToLoad = new Image();
	imageToLoad.src = imagePath;
	imageToLoad.onLoad=srcSet(object,imageToLoad);
	if (waitSync) while(!syncLoad);
}

function StartEnd(topStart, topEnd, leftStart, leftEnd, widthStart, widthEnd, heightStart, heightEnd) {
	this.topStart=topStart;
	this.topEnd=topEnd;
	this.leftStart=leftStart;
	this.leftEnd=leftEnd;
	this.widthStart=widthStart;
	this.widthEnd=widthEnd;
	this.heightStart=heightStart;
	this.heightEnd=heightEnd;
	return this;
}

function Reverse() {
	with (this) return StartEnd(topEnd, topStart, leftEnd, leftStart, widthEnd, widthStart, heightEnd, heightStart);
}
StartEnd.prototype.Reverse=Reverse;

var startEnd;
var imgToHide;
var bFadeOrigCanvas;
var zoomFrames;
var zoomTime;

function ShowLargeImage(id, newSrc, newSrcMed, se, fadeOrigCanvas, HideImage, frames)
{
	changeSizePos(se.topStart,se.leftStart,se.widthStart,se.heightStart,id);
	setSrcAfterLoadComplete(id, newSrcMed, true);
	changeOpac(100,"ZoomCanvas");
	makeVisible("visible", "ZoomCanvas");

    zoomFrames = frames;
    zoomTime= Math.floor(500/frames)*frames;
	bFadeOrigCanvas = fadeOrigCanvas;

	setSrcAfterLoadComplete(id, newSrc, false);

	changeOpac(0,"ClickBlock");
	makeVisible("visible", "ClickBlock");
	startEnd = se;
	resize(id, startEnd, zoomFrames, zoomTime, false);

	imgToHide = HideImage;
	makeVisible("hidden", imgToHide);

	if (bFadeOrigCanvas) {
		changeOpac(0,"SwatchCover");
		makeVisible("visible", "SwatchCover");
		opacity("SwatchCover", 0, 100, 500, false);
	}
}

function HideLargeImage()
{
	makeVisible("hidden", "ClickCapture");
	resize("ZoomImage", startEnd.Reverse(), zoomFrames, zoomTime, true, imgToHide);
	if (bFadeOrigCanvas) {
		opacity("SwatchCover", 100, 0, 500, true);
	}
}

