/*
var delay = 7000;
var delay2 = 700;

var img1 = new Image();
img1.src = 'images/eamb_logo.png';
var img2 = new Image();
img2.src = 'images/kalishL.gif';
var img3 = new Image();
img3.src = 'images/kalishR.gif';

function headerLogo() {
	document.getElementById('headerImg').src = 'images/eamb_logo.png';
	setTimeout('headerKL()',delay);
}
function headerKL() {
	document.getElementById('headerImg').src = 'images/kalishL.gif';
	setTimeout('headerLogo2()',delay2);
}
function headerLogo2() {
	document.getElementById('headerImg').src = 'images/eamb_logo.png';
	setTimeout('headerKR()',delay);
}
function headerKR() {
	document.getElementById('headerImg').src = 'images/kalishR.gif';
	setTimeout('headerLogo()',delay2);
}
*/

window.onload = function()
{
	//headerLogo();
	document.getElementById('fisheye_menu').style.display='inline';
	document.getElementById('fisheye_menu2').style.display='inline';
	curveIt();
}

function curveIt() {
	var settings = {
        tl: { radius: 20 },
        tr: { radius: 20 },
        bl: { radius: 20 },
        br: { radius: 20 },
        antiAlias: true
    }

    curvyCorners(settings, '.curved');
}


/* Fisheye Menu v1.0 
   Written by Marc Grabanski (m@marcgrabanski.com)

   Copyright (c) 2007 Marc Grabanski (http://marcgrabanski.com/code/fisheye-menu)
   Dual licensed under the GPL (http://www.gnu.org/licenses/gpl-3.0.txt) and 
   CC (http://creativecommons.org/licenses/by/3.0/) licenses. "Share or Remix it but please Attribute the authors."
   Date: 10-05-2007  */

var fisheyemenu = {
	startSize : 86,
	endSize : 86,
	imgType : ".png",
	init : function () {
		var animElements = document.getElementById("fisheye_menu").getElementsByTagName("img");
		var animElements2 = document.getElementById("fisheye_menu2").getElementsByTagName("img");
		//var titleElements = document.getElementById("fisheye_menu").getElementsByTagName("span");
		//for(var j=0; j<titleElements.length; j++) {
			//titleElements[j].style.display = 'none';
		//}
		for(var i=0; i<animElements.length; i++) {
			var y = animElements[i];
			y.style.width = fisheyemenu.endSize+'px';
			y.style.height = fisheyemenu.endSize+'px';
			fisheyemenu.imgSmall(y);
			// commented out by wiley for iPhone compatability
			//animElements[i].onmouseover = changeSize;
			//animElements[i].onmouseout = restoreSize;
		}
		for(var i=0; i<animElements2.length; i++) {
			var y = animElements2[i];
			y.style.width = fisheyemenu.endSize+'px';
			y.style.height = fisheyemenu.endSize+'px';
			fisheyemenu.imgSmall(y);
			// commented out by wiley for iPhone compatability
			//animElements2[i].onmouseover = changeSize;
			//animElements2[i].onmouseout = restoreSize;
		}
		function changeSize() {
			fisheyemenu.imgLarge(this);
			//var x = this.parentNode.getElementsByTagName("span");
			//x[0].style.display = 'block';
			if (!this.currentWidth) this.currentWidth = fisheyemenu.startSize;
			fisheyemenu.resizeAnimation(this,this.currentWidth,fisheyemenu.endSize,15,10,0.333);
		}
		function restoreSize() {
			//var x = this.parentNode.getElementsByTagName("span");
			//x[0].style.display = 'none';
			if (!this.currentWidth) return;
			fisheyemenu.resizeAnimation(this,this.currentWidth,fisheyemenu.startSize,15,10,0.5);
			fisheyemenu.imgSmall(this);
		}
	},
	resizeAnimation : function (elem,startWidth,endWidth,steps,intervals,powr) {
		if (elem.widthChangeMemInt) window.clearInterval(elem.widthChangeMemInt);
		var actStep = 0;
		elem.widthChangeMemInt = window.setInterval(
			function() {
				elem.currentWidth = fisheyemenu.easeInOut(startWidth,endWidth,steps,actStep,powr);
				elem.style.width = elem.currentWidth+"px";
				elem.style.height = elem.currentWidth+"px";
				actStep++;
				if (actStep > steps) window.clearInterval(elem.widthChangeMemInt);
			}
			,intervals)
	},
	easeInOut : function (minValue,maxValue,totalSteps,actualStep,powr) {
	//Generic Animation Step Value Generator By www.hesido.com
		var delta = maxValue - minValue;
		var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
		return Math.ceil(stepp)
	},
	imgSmall : function (obj) {
		imgSrc = obj.getAttribute("src");
		var typePos = imgSrc.indexOf(fisheyemenu.imgType, 0);
		var imgName = imgSrc.substr(0, typePos);
		//obj.setAttribute("src", imgName+"_small"+fisheyemenu.imgType);
		//changed to this for iPhone compatibility
		obj.setAttribute("src", imgName+fisheyemenu.imgType);
	},
	imgLarge : function (obj) {
		imgSrc = obj.getAttribute("src");
		var typePos = imgSrc.indexOf("_small", 0);
		var imgName = imgSrc.substr(0, typePos);
		obj.setAttribute("src", imgName+fisheyemenu.imgType);
	}
}

// Add event with wide browser support
if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fisheyemenu.init, false );
else if ( typeof window.attachEvent != "undefined" )
    window.attachEvent( "onload", fisheyemenu.init );
else {
    if ( window.onload != null ) {
        var oldOnload = window.onload;
        window.onload = function ( e ) {
            oldOnload( e );
            fisheyemenu.init();
        };
    }
    else
        window.onload = fisheyemenu.init;
}


function closebox() {
	document.getElementById('litebox').innerHTML = 'Loading . . .';
	document.getElementById('greybox').style.display='none';
	document.getElementById('litebox').style.display='none';
}
function setLB(x,y) {
	document.getElementById('litebox').style.height = y +'px';
	document.getElementById('litebox').style.width= x + 'px';
	document.getElementById('litebox').style.marginTop = String((y/2)*(-1)) + 'px';
	document.getElementById('litebox').style.marginLeft = String((x/2)*(-1)) + 'px';
}
function showVid(x) {
	setLB(680,600);
	
	var xmlHttp;
	try {
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		try {
			xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e) {
				alert('Your browser does not support AJAX!');
				return false;
			}
		}
	}

	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			document.getElementById('litebox').innerHTML = 'Loading . . .';
			document.getElementById('greybox').style.display='block';
			document.getElementById('litebox').style.display='block';
			
			document.getElementById('litebox').innerHTML=xmlHttp.responseText;
		}
	}
	
	var queryString = "?ID=" + x;
	
	xmlHttp.open('GET',"scripts/showVid.php" + queryString,true);
	xmlHttp.send(null);
}
function validate() {
	document.getElementById('from').style.background = 'white';
	document.getElementById('email').style.background = 'white';
	document.getElementById('subject').style.background = 'white';
	document.getElementById('msg').style.background = 'white';
	
	var frm = document.getElementById('from').value;
	var mal = document.getElementById('email').value;
	var sub = document.getElementById('subject').value;
	var msg = document.getElementById('msg').value;
	
	if (frm.length < 2) {
		document.getElementById('from').focus();
		document.getElementById('from').style.background = 'yellow';
		alert('Please check your name.');
		return false;
	}
	if (mal.length < 5) {
		document.getElementById('email').focus();
		document.getElementById('email').style.background = 'yellow';
		alert('Please check your email address.');
		return false;
	}
	if (sub == "0") {
		document.getElementById('subject').focus();
		document.getElementById('subject').style.background = 'yellow';
		alert('Please select a subject.');
		return false;
	}
	if (msg.length < 5) {
		document.getElementById('msg').focus();
		document.getElementById('msg').style.background = 'yellow';
		alert('Please enter a longer message.');
		return false;
	}
	return true;
}
function showLinks() {
	setLB(680,600);
	
	var xmlHttp;
	try {
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		try {
			xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e) {
				alert('Your browser does not support AJAX!');
				return false;
			}
		}
	}

	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			document.getElementById('litebox').innerHTML = 'Loading . . .';
			document.getElementById('greybox').style.display='block';
			document.getElementById('litebox').style.display='block';
			
			document.getElementById('litebox').innerHTML=xmlHttp.responseText;
		}
	}
	
	xmlHttp.open('GET',"scripts/showLinks.php",true);
	xmlHttp.send(null);
}
function checkColorAvailability(x) {
	document.getElementById(x+'_color').innerHTML = '<option value="-">--select size--</option>';
	
	var xmlHttp;
	try {
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		try {
			xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e) {
				alert('Your browser does not support AJAX!');
				return false;
			}
		}
	}

	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			document.getElementById(x+'_color').innerHTML=xmlHttp.responseText;
		}
	}
	
	var size = document.getElementById(x+'_size').value;
	
	var queryString = "?ID=" + x + '&size=' + size;
	
	xmlHttp.open('GET',"scripts/checkColorAvailability.php" + queryString,true);
	xmlHttp.send(null);
}
function addToCart(flag,item) {
	var xmlHttp;
	try {
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}

	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			viewCart();
		}
	}
	
	var qty = document.getElementById(item).value;
	
	if (flag == 'sized') {
		var size = document.getElementById(item + '_size').value;
		var color = document.getElementById(item + '_color').value;
		
		if (size == '-') {
			document.getElementById(item + '_size').focus;
			document.getElementById(item + '_size').style.backgroundColor = 'yellow';
			alert('Please select a size.');
			return;
		}
		if (color == '-') {
			document.getElementById(item + '_color').focus;
			document.getElementById(item + '_color').style.backgroundColor = 'yellow';
			alert('Please select a color.');
			return;
		}
		
		var queryString = "?item=" + item + "&size=" + size + "&color=" + color + "&qty=" + qty;
	} else {
		var queryString = "?item=" + item + "&qty=" + qty;
	}

	xmlHttp.open("GET","scripts/addtocart.php" + queryString,true);
	xmlHttp.send(null);
}
function forceUpdate() {
	document.getElementById('paypalbtn').disabled = true;
}
function updatecart() {
	for (i=0;i<updatecart.arguments.length;i++){
		udpatecart2(updatecart.arguments[i]);
	}
}
function udpatecart2(field) {
	var xmlHttp;
	try {
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}

	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			if (xmlHttp.responseText == 'bad number') {
				alert('Please check your quantity values. They must be numeric.');
			} else {
				viewCart();
			}
		}
	}
	
	var fieldvalue = document.getElementById(field).value

	var queryString = "?field=" + field + "&fieldvalue=" + fieldvalue;
	
	xmlHttp.open("GET","scripts/updatecart.php" + queryString, true);
	xmlHttp.send(null);
}
function viewCart() {
	setLB(750,600);
	
	var xmlHttp;
	try {
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		try {
			xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e) {
				alert('Your browser does not support AJAX!');
				return false;
			}
		}
	}

	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			document.getElementById('litebox').innerHTML = 'Loading . . .';
			document.getElementById('greybox').style.display='block';
			document.getElementById('litebox').style.display='block';
			
			document.getElementById('litebox').innerHTML=xmlHttp.responseText;
		}
	}
	
	xmlHttp.open('GET',"scripts/viewCart.php",true);
	xmlHttp.send(null);
}
function saveOrder(cartID) {
	var xmlHttp;
	try {
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		try {
			xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e) {
				alert('Your browser does not support AJAX!');
				return false;
			}
		}
	}

	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			return false;
		}
	}
	
	xmlHttp.open('GET',"scripts/saveOrder.php?cartID="+cartID,true);
	xmlHttp.send(null);
}
function announce() {
	setLB(750,600);
	
	var xmlHttp;
	try {
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		try {
			xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e) {
				alert('Your browser does not support AJAX!');
				return false;
			}
		}
	}

	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			document.getElementById('litebox').innerHTML = 'Loading . . .';
			document.getElementById('greybox').style.display='block';
			document.getElementById('litebox').style.display='block';
			
			document.getElementById('litebox').innerHTML=xmlHttp.responseText;
		}
	}
	
	xmlHttp.open('GET',"scripts/announce.php",true);
	xmlHttp.send(null);
}
function showpic(x) {
	setLB(750,600);
	
	var xmlHttp;
	try {
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		try {
			xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e) {
				alert('Your browser does not support AJAX!');
				return false;
			}
		}
	}

	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			document.getElementById('litebox').innerHTML = 'Loading . . .';
			document.getElementById('greybox').style.display='block';
			document.getElementById('litebox').style.display='block';
			
			document.getElementById('litebox').innerHTML=xmlHttp.responseText;
		}
	}
	
	xmlHttp.open('GET',"scripts/showpic.php?pic="+x,true);
	xmlHttp.send(null);
}
function swapPic(id,pic) {
	document.getElementById('pic'+id).src='productimages/'+pic;
}
