// scripts for product pages
lbInitHeight = 200;
lbInitWidth = 200;
lbHeight = lbInitHeight
lbWidth = lbInitWidth;
var img, lightBox, lbContents, fadeBox, bod , htm, isIE;
// for Internet Explorer (using conditional comments)
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
  if (this.readyState == "complete") {
    init(); // call the onload handler
  }
};
/*@end @*/
if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", init, false);
}
if (/WebKit/i.test(navigator.userAgent)) { // sniff
  var _timer = setInterval(function() {
    if (/loaded|complete/.test(document.readyState)) {
      clearInterval(_timer);
      init(); // call the onload handler
    }
  }, 10);
}

function init(){
	if(document.getElementById('lightBox'))
		lightBox = document.getElementById('lightBox');
	
	if(document.getElementById('lbContents'))
		lbContents = document.getElementById('lbContents');
	
	if(document.getElementById('product-image'))
		img = document.getElementById('product-image');
	
	fadeBox = document.getElementById('black_overlay');
	bod = document.getElementsByTagName('body')[0];
	htm = document.getElementsByTagName('html')[0];
	
	isIE = isIE();
}


function isIE()
{
      return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}
	  
function swapImage(thumb){
	/*img.src = "/images/loader-bar.gif";
	newImg = new Image();
	newImg.src = thumb.getAttribute("image");
	
	newImg.onload = function(){
		img.src = thumb.getAttribute("image");
		if(thumb.getAttribute("zoom"))
			img.setAttribute("zoom", thumb.getAttribute("zoom"))
		else
				img.setAttribute("zoom", "")
	}*/
	img.src = thumb.getAttribute("image");
	
		
	if(isIE){
		img.src = thumb.getAttribute("image");
	} else {
		img.src = "/images/loader-bar.gif";
		newImg = new Image();
		newImg.src = thumb.getAttribute("image");
		newImg.onload = function(){
			img.src = thumb.getAttribute("image");
			}
	}
	if(thumb.getAttribute("zoom"))
		img.setAttribute("zoom", thumb.getAttribute("zoom"))
	else
		img.setAttribute("zoom", "")
}

function zoomImage(){
	

	
	
	imgSrc = img.src;
	
	if(img.getAttribute("zoom"))
		imgSrc = img.getAttribute("zoom");
	
	zoomImg = new Image();
		zoomImg.src = imgSrc;
		
	if(isIE){
		lbContents.innerHTML ='<img src="'+imgSrc+'" alt="" />';
		lbWidth = zoomImg.width + 12;
		lbHeight = zoomImg.height + 30;
		showLightBox();
	} else {
		
		
		showLightBox();
		
		
		zoomImg.onload = function(){
			lbWidth = zoomImg.width + 12;
			lbHeight = zoomImg.height + 30;
			lbContents.innerHTML ='<img src="'+imgSrc+'" alt="" />';
			resizeLightBox();
		}
	}
}
function resizeLightBox(){

	scrollXY = getScrollXY();
	scrollX = scrollXY[0];
	scrollY = scrollXY[1];
	winHeight = document.documentElement.clientHeight;
	winWidth = document.documentElement.clientWidth;
	
	//Position the lightbox
	lbTop = ((winHeight - lbHeight) /2) + scrollY;
	lbTopLeft = ((winWidth-lbWidth) /2);
	lightBox.style.top = lbTop+"px";
	lightBox.style.left = lbTopLeft+"px";
	lightBox.style.width = lbWidth+"px";
	lightBox.style.height = lbHeight+"px";
}
function showLightBox(){


	
	lbClose = lightBox.getElementsByTagName('span')[0];
	lbClose.onclick = function(){ hideLightBox(); } ;

	//Prevent scrolling while lightbox is showing
	bod.style.overflow = "hidden";
	htm.style.overflow = "hidden"; 
	
	winHeight = document.documentElement.clientHeight;
	winWidth = document.documentElement.clientWidth;
	
	scrollXY = getScrollXY();
	scrollX = scrollXY[0];
	scrollY = scrollXY[1];
	
	//Position the Background fade
	fadeBox.style.top = scrollY+"px";	
	fadeBox.style.height = winHeight+"px";
	fadeBox.style.width = winWidth+"px";
	fadeBox.style.display = "block";
	fadeBox.onclick = function(){ hideLightBox(); } ;
	
	
	lightBox.style.display = "block";
	

	
	//Position the lightbox
	lbTop = ((winHeight - lbHeight) /2) + scrollY;
	lbTopLeft = ((winWidth-lbWidth) /2);
	lightBox.style.top = lbTop+"px";
	lightBox.style.left = lbTopLeft+"px";
	lightBox.style.width = lbWidth+"px";
	lightBox.style.height = lbHeight+"px";
	
}
function hideLightBox(){
	bod = document.getElementsByTagName('body')[0];
	htm = document.getElementsByTagName('html')[0];
	lightBox = document.getElementById('lightBox');
	lbContents = document.getElementById('lbContents');
	fadeBox = document.getElementById('black_overlay');
	
	lbContents.innerHTML = '<img src="/images/ajax-loader.gif" alt="loading" class="lbLoad" />';
	lightBox.style.display = "none";
	fadeBox.style.display = "none";
	bod.style.overflow = "auto";
	htm.style.overflow = "auto"; 
	fadeBox.style.height = lbInitHeight+"px";
	fadeBox.style.width = lbInitWidth+"px";
}


function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}



function showFlashPrima(){
	swfFile = 'toyboxv7.swf';
	newHTML = '<object width="550" height="440" data="/swf/'+swfFile+'" type="application/x-shockwave-flash"><param value="/swf/'+swfFile+'" name="movie"/></object>';	
	lbContents.innerHTML = newHTML;
	lbWidth = 562;
	lbHeight = 470;
	showLightBox();
}



