var r = 0;
var i = 0;
var pathwidth;
var pathheight;
var x = 0;
var y = 0;
// Hide timeout.
var menutime = 0;
var menutimeout=500;

var currentthumbnail = '';
function loadMainImage(contID, currentthumbnailpath, picIDprefix, selectedpictureid, totalnoofpic) {

    for (n = 0; n <= totalnoofpic; n++) {
        document.getElementById(picIDprefix + n).style.opacity = 1; //non-IE;
        document.getElementById(picIDprefix + n).style.filter = 'alpha(opacity=' + 100 + ')'; //IE
    }
    document.getElementById(contID).src = currentthumbnailpath;
    frosty(selectedpictureid);
}

function frosty(num) {
    document.getElementById(num).style.opacity = 0.4; //non-IE;
    document.getElementById(num).style.filter = 'alpha(opacity=' + 40 + ')'; //IE

}

function redir(newurl) {
        if (newurl.indexOf('~menu') > 0) {
            breakURL = newurl.split('~menu');
            newurl = breakURL[0] + urlsuffix;
        }
        else {
            newurl = newurl + urlsuffix;
        }
    window.location.href = newurl;
}

function changeBG(menuID) {
    document.getElementById(menuID).style.color = '#ffaf22'; //orange
}

function restoreBG(elemID) {
    document.getElementById(elemID).style.color = '#ffaf22';
}

function showProdSpecs(theDiv) {
    if (theDiv == 'producthighlights') {
        document.getElementById('currprodcathdr').style.visibility = 'hidden';
        document.getElementById('producthighlights').style.visibility = 'visible';
        document.getElementById('tabph').style.color = '#000000';
        document.getElementById('tabph').style.fontWeight = 'bold';
        document.getElementById('tabph').style.backgroundColor = '#ff0000';
        document.getElementById('tabac').style.color = '#707070';
        document.getElementById('tabac').style.fontWeight = 'normal';
        document.getElementById('tabac').style.backgroundColor = '';
    }
    if (theDiv == 'currprodcathdr') {
        document.getElementById('producthighlights').style.visibility = 'hidden';
        document.getElementById('currprodcathdr').style.visibility = 'visible';
        document.getElementById('tabph').style.color = '#707070';
        document.getElementById('tabph').style.fontWeight = 'normal';
        document.getElementById('tabph').style.backgroundColor = '';
        document.getElementById('tabac').style.color = '#000000';
        document.getElementById('tabac').style.fontWeight = 'bold';
        document.getElementById('tabac').style.backgroundColor = '#ff0000';
    }
}


/*function() {
    $("#example").dialog({
        modal: true,
        resizable: false,
        overlay: {
            opacity: 0, 4,
            background: "black"
        },
        buttons: {
            "OK": function() {
                $(this).dialog("close");
            }
        }
    });
};*/


function loadImg(path, hyper, imgno)
{
	e=event;
	//e = (e) ? e : ((window.event) ? window.event : null);
	var m1= document.getElementById("divpiczoom");
	//alert(m1.style.display);
	var itm =  document.getElementById("imgZoom",e);
	m1.style.display = "block";

	//x = e.clientX;
	//y = e.clientY;
	
	//x = itm.style.left + (itm.offsetWidth / 2); dock to top left
	//y = itm.style.top + (itm.offsetHeight / 2); dock to top left
	
	
	x = GetX(document.getElementById(imgno));
	y = GetY(document.getElementById(imgno));
	x = x + (document.getElementById(imgno).offsetWidth / 2);
	y = y + (document.getElementById(imgno).offsetHeight / 2);
	//alert(x);
	//alert(y);
	


	if (e.clientX > (document.body.offsetWidth / 2)) {//alert(itm.offsetWidth);
		//m1.style.left = e.clientX - 350;
		//m1.style.left = e.clientX - 125;
		//m1.style.left = (e.clientX - itm.offsetWidth) + 'px';
		}
	else {
		//m1.style.left = e.clientX + 100;
		//m1.style.left = e.clientX - 125;
		//m1.style.left = e.clientX + 'px';
		}
	//m1.style.top = (e.clientY + document.body.scrollTop - (itm.offsetHeight/2)) + 'px';
	r = 0;
	img=new Image;
	img.src = path;
	pathwidth = img.width;
	pathheight = img.height;

	m1.style.width = '0px';
	m1.style.height = '0px';
	m1.style.visibility = "hidden";

	document.getElementById("imgZoom").style.width=0;
	document.getElementById("imgZoom").style.height=0;
	document.getElementById("imgZoom").src = path;
	document.getElementById("imgZoomHyper").href = hyper;
	
	r = 0;
	m1.style.top = y;
	m1.style.left = x; 
	aniZoom(pathwidth, pathheight);
}

function loadDictionary(imgno, content, kw, event) {
    //var isIE = document.all;
    //e=event;
    var e = ((window.event) ? window.event : event);
    var temp;
    var m1 = document.getElementById("divdictzoom");
    //alert(m1.style.display);
    m1.style.display = "block";

    x = e.clientX + document.body.scrollLeft;
    y = e.clientY + document.body.scrollTop;
    
    //x = GetX(document.getElementById(imgno));
    //y = GetY(document.getElementById(imgno));
    x = x + (document.getElementById(imgno).offsetWidth / 2);
    y = y + (document.getElementById(imgno).offsetHeight / 2);
    //alert(x);
    //alert(y);

    //if (e.clientX > (document.body.offsetWidth / 2)) {//alert(itm.offsetWidth);
    //m1.style.left = e.clientX - 350;
    //m1.style.left = e.clientX - 125;
    //m1.style.left = (e.clientX - itm.offsetWidth) + 'px';
    //	}
    //else {
    //m1.style.left = e.clientX + 100;
    //m1.style.left = e.clientX - 125;
    //m1.style.left = e.clientX + 'px';
    //	}
    //m1.style.top = (e.clientY + document.body.scrollTop - (itm.offsetHeight/2)) + 'px';
    r = 0;

    m1.style.width = '350px';
    m1.style.height = (content.length) / 3 + 10 + 'px';
    if (y < m1.style.height.replace('px', '')) {
        m1.style.height = y - 80 + 'px';
        m1.style.top = y - m1.style.height.replace('px', '') - 75 + 'px';
    }
    else {
        m1.style.top = y - m1.style.height.replace('px', '') - 60 + 'px';
    }

    temp = '<table class="dictionarycontent" border="0" width="100%" cellspacing="0" cellpadding="0">';
    temp = temp + '<tr><td class="menu_text" style="text-align:left; padding-left: 8px;">What is ' + kw + '?</td><td class="menu_text"><span style="text-align:right; padding-right: 5px;"><img style="cursor:pointer; float: right; padding-right:5px;" alt="Close" onclick="hideDict();" src="images/removefilter.gif"></span></td></tr>';
    temp = temp + '<tr><td colspan="2"><span style="text-align:left;">' + content + '</span></td></tr></table>';
    m1.innerHTML = temp;
    //document.getElementById("content").innerHTML = content;
    //m1.style.visibility = "hidden";

    r = 0;
    //m1.style.top = y - m1.style.height.replace('px', '') - 60 + 'px';
    if ((x + 180) < document.documentElement.clientWidth) { //IF RIGHT EDGE OF BOX GOES PAST BROWSER WINDOW
        m1.style.left = x - 180 + 'px';
    }
    else {
        m1.style.left = x - 360 + 'px';
    }

    showDict();
}
function showDict() {
    r = r + .1;
    document.getElementById("divdictzoom").visibility = 'visible';
    document.getElementById("divdictzoom").style.display = 'block';
    if (r <= 1) {
        document.getElementById("divdictzoom").style.opacity = r; //non-IE
        document.getElementById("divdictzoom").style.filter = 'alpha(opacity=' + r * 100 + ')'; //IE
        setTimeout('showDict()', 50);
    }
}

function hideDict() {
    document.getElementById("divdictzoom").style.display = "none";
    //aniUnZoom();
}

function GetX(oElement) {
	var ix = 0;
	
	while(oElement != null) {
		ix += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return ix;
}
function GetY(oElement) {
	var iy = 0;
	
	while(oElement != null) {
		iy += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iy;
}

function hideImg()
{
	document.getElementById("divpiczoom").style.display = "none";
	//aniUnZoom();
}

function aniZoom() {
	var m1 = document.getElementById("divpiczoom");
	m1.style.visibility = "visible";
	r = r + 2;
	
	//alert(x - (r/2));
	if (pathwidth <= pathheight) {
		if (r <= pathwidth) {
		m1.style.left = x - (r/2) + 'px';
		m1.style.top = y - (r/2) + 'px';
		document.getElementById("imgZoom").style.width= r + 'px';
		document.getElementById("imgZoom").style.height= r + 'px';
		setTimeout('aniZoom()', 2);
		}
		if (r >= pathwidth && r <= pathheight) {
		m1.style.top = y - (r/2) + 'px';
		document.getElementById("imgZoom").style.width= pathwidth + 'px';
		document.getElementById("imgZoom").style.height= r + 'px';
		setTimeout('aniZoom()', 2);
		}
		}
	else {
	
		if (r <= pathheight) {
		m1.style.left = x - (r/2) + 'px';
		m1.style.top = y - (r/2) + 'px';
		document.getElementById("imgZoom").style.width= r + 'px';
		document.getElementById("imgZoom").style.height= r + 'px';
		setTimeout('aniZoom()', 2);
		}
		if (r >= pathheight && r <= pathwidth) {
		m1.style.left = x - (r/2) + 'px';
		document.getElementById("imgZoom").style.width= r + 'px';
		document.getElementById("imgZoom").style.height= pathheight  + 'px';
		setTimeout('aniZoom()', 2);
		}
		}
}
function aniUnZoom() {
	var m1 = document.getElementById("divpiczoom");
	m1.style.visibility = "visible";
	r = r - 2;
	
	if (pathwidth <= pathheight) {
	//alert(r);
		if (r <= pathwidth && r >= 1) {
		m1.style.left = x - (r/2) + 'px';
		m1.style.top = y - (r/2) + 'px';
		document.getElementById("imgZoom").style.width= r + 'px';
		document.getElementById("imgZoom").style.height= r + 'px';
		setTimeout('aniUnZoom()', 2);
		}
		if (r > pathwidth && r <= pathheight && r >= 1) {
		m1.style.top = y - (r/2) + 'px';
		document.getElementById("imgZoom").style.width= pathwidth + 'px';
		document.getElementById("imgZoom").style.height= r + 'px';
		setTimeout('aniUnZoom()', 2);
		}
 		if (r <=1) {document.getElementById("divpiczoom").style.display = "none";}
		}
	else {
		if (r <= pathheight && r >= 1) {
		m1.style.left = x - (r/2) + 'px';
		m1.style.top = y - (r/2) + 'px';
		document.getElementById("imgZoom").style.width= r + 'px';
		document.getElementById("imgZoom").style.height= r + 'px';
		setTimeout('aniUnZoom()', 2);
		}
		if (r > pathheight && r <= pathwidth && r >= 1) {
		m1.style.left = x - (r/2) + 'px';
		document.getElementById("imgZoom").style.width= r + 'px';
		document.getElementById("imgZoom").style.height= pathheight  + 'px';
		setTimeout('aniUnZoom()', 2);
		}
 		if (r <=1) {document.getElementById("divpiczoom").style.display = "none";}
		}
}

function link() {
	window.location.href="default.asp?WCI=Products&amp;%20WCE=%5especialpromotions%5eSpecials"
}