var prodimg,largeimg,MoveBoxHeight,MoveBoxWidth,XScale,YScale,zoomState;
var imageX,imageYbottomX,bottomY,largeImgSrc,normalImgSrc,normalHover,largeimgValid,smallimgValid,initialized;
var menuOn,loadimg,loadingmsg;
var browser_version= parseInt(navigator.appVersion);
var browser_type=navigator.appName;

//This function is called from each deal
function ZoomLoadernew(id, largeimgurl)
{prodimg=document.getElementById("NormalImage_" + id);
largeimg=document.getElementById("LargeImage_" + id);
loadingmsg=document.getElementById("loadimg_" + id);
largeimg.src=largeimgurl;

moveBox=document.getElementById("MoveBox_" + id);
zoomBox=document.getElementById("ZoomBox_" + id);
sizeWindow=document.getElementById("SizeWindow_" + id);
hoverText=document.getElementById("textBox_" + id);

//Statically assign the height and width to variables (issues when extracting from CSS?).
moveBoxHeight=40;
moveBoxWidth=60;

//Initialize the image paths.
largeImgSrc=largeimg.src;
normalImgSrc=prodimg.src;
//Calculate the scaling factor.
XScale=largeimg.width /prodimg.width;
YScale=largeimg.height /prodimg.height;


//Store the X, Y coordinates of the small image.
imageX=findPosX(prodimg);
imageY=findPosY(prodimg);

//Calculate the lower right X, Y coordinates of the small image.
bottomX=imageX + prodimg.width;
bottomY=imageY + prodimg.height;

// Initialize our flags.
zoomState=false;
normalHover=false;
initialized=true;
menuOn=false;
}

//This function checks the coordinates of the mouse, and sets the zoomState
//flag if it is within the small image, and clears the flag if it is outside it.
function CheckMouse(currX, currY)
{//We're within the image boundaries.
if(currX >= imageX && currX <= bottomX && currY >= imageY && currY <= bottomY && !menuOn && XScale > 1 && YScale > 1)
 zoomState=true;
else
 zoomState=false;
}

//ZoomInBox: Gets called when the mouse is moved
function ZoomInBox(e)
{
// e gives access to the event in all browsers.
if(!e) {var e=window.event;}

// Grab the position of the mouse.
var mouseX=getMouseX(e);
var mouseY=getMouseY(e);

// Recalculate the scaling factor.
if(initialized)
{ XScale=largeimg.width / prodimg.width;
  //XScale=XScale + 1;
  YScale=largeimg.height / prodimg.height;
  //YScale=YScale + 1;
}

//Set the location of the "Out of Stock" dialog box.
if(initialized)
{ hoverText.style.left=imageX + ((bottomX - imageX) / 2) - 50;
  hoverText.style.top=imageY + ((bottomY - imageY) / 2) - 20;
}

// Check if the mouse is inside the image.
CheckMouse(mouseX, mouseY);

// If the large image has changed, make sure that the path is updated.
if(initialized)
{if(largeImgSrc != largeimg.src) {largeimg.src=largeImgSrc;}
}

// If the small image has changed, make sure that the path is updated.
if(initialized)
{if(normalImgSrc != prodimg.src && !normalHover) {prodimg.src=normalImgSrc;}
}

// To reduce overhead, check if we even need to do any processing.
if(zoomState===true)
{	loadingmsg.innerHTML="<CENTER><H4><FONT COLOR=#D8D8D8>P r o c e s s i n g &nbsp;&nbsp;I M A G E. . .</FONT> </H4></CENTER>";

	// Make sure that our scaling factor is a valid number.
	if(isNaN(XScale))
	{XScale=largeimg.width / prodimg.width;}
	if(isNaN(YScale))
	{YScale=largeimg.height / prodimg.height;}

	// Determine if the cursor box is near the edge of the image.
	// Calculate the X, Y coordinates of the cursor box (upper, and
	// lower).
	var cursorBoxUpX=mouseX - moveBoxWidth / 2;
	var cursorBoxUpY=mouseY - moveBoxHeight / 2;
	var cursorBoxBottomX=mouseX + moveBoxWidth / 2;
	var cursorBoxBottomY=mouseY + moveBoxHeight / 2;
	var relativeY;
	var relativeX;

	// Check the calculated coordinates to those of the image.
	// We need to check the X and Y separately, so they can change
	// independent of each other.
	// Check X.
	if(cursorBoxUpX >= imageX && cursorBoxUpX <= bottomX && cursorBoxBottomX >= imageX && cursorBoxBottomX <= bottomX)
	{	moveBox.style.left=mouseX - moveBoxWidth / 2;

		// Assign the relative coordinates, for translation
		// to the large image.
		relativeX=cursorBoxUpX - imageX;
	}
	else if(cursorBoxUpX < imageX)
	{ moveBox.style.left=imageX;relativeX=1;}
	else if(cursorBoxBottomX > bottomX)
	{ moveBox.style.left=bottomX - moveBoxWidth;relativeX=bottomX - imageX - moveBoxWidth;}

	// Check Y.
	if(cursorBoxUpY >= imageY && cursorBoxUpY <= bottomY && cursorBoxBottomY >= imageY && cursorBoxBottomY <= bottomY)
	{	moveBox.style.top=mouseY - moveBoxHeight / 2;

		// Assign the relative coordinates, for translation
		// to the large image.
		relativeY=cursorBoxUpY - imageY;
	}
	else if(cursorBoxUpY < imageY)
	{ moveBox.style.top=imageY;relativeY=1;
	}
	else if(cursorBoxBottomY > bottomY)
	{ moveBox.style.top=bottomY - moveBoxHeight;relativeY=bottomY - imageY - moveBoxHeight;}

	// Adjust the size of the zoom box, based on our scaling factor,
	// and the size of the cursor box.
	 //zoomBox.style.height=moveBoxHeight * YScale;
	 //zoomBox.style.width=moveBoxWidth * XScale;
	 zoomBox.style.height=250;
	 zoomBox.style.width=300;

	// Adjust the location of the zoom box, based on the small image.
	var zoomBoxTop=imageY + prodimg.height - (prodimg.height * 0.9);
	var zoomBoxLeft=imageX + prodimg.width + 43;
	zoomBox.style.top=zoomBoxTop;
	zoomBox.style.left=zoomBoxLeft;

	// The coordinates for the large image are calculated based on
	// the offset of the cursor box within the small image.
	var largeimgTop=relativeY * YScale *-1;
	var largeimgLeft=relativeX * XScale *-1;

	// These tests are here so that IE and Gecko browsers behave the
	// same when NaN is encountered.
	if(largeimgTop) {largeimg.style.top=largeimgTop;}
	if(largeimgLeft) {largeimg.style.left=largeimgLeft;}

	// Make the zoom box layers visible, and render the zoom box
	// itself.
	largeimg.style.visibility="visible";
	moveBox.style.visibility="visible";
	zoomBox.style.visibility="visible";

}

// Hide the zoom box layers.
if(zoomState===false)
{	if(initialized)
	{largeimg.style.visibility="hidden";
	 moveBox.style.visibility="hidden";
	 zoomBox.style.visibility="hidden";
	}
}
}

//These two functions find the X, Y coordinates of the supplied object, in our
//case it is the coordinates of the small image. Written by James Robinson.
function findPosX(obj)
{var curleft=0;
 if(obj.offsetParent)
 {while (obj.offsetParent)
  {curleft += obj.offsetLeft; obj=obj.offsetParent;
   }
 }
else if(obj.x) {curleft += obj.x;}
return curleft;
}

function findPosY(obj)
{var curtop=0;
 if(obj.offsetParent)
 {while (obj.offsetParent)
  { curtop += obj.offsetTop;obj=obj.offsetParent;
   }
 }
 else if(obj.y) {curtop += obj.y;}
 return curtop;
}

//These two functions ensure compatibility with various browsers.
function getMouseX(evt)
{if(evt.pageX) return evt.pageX;
else if(evt.clientX) return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
else {return null;}
}

function getMouseY(evt)
{if(evt.pageY) return evt.pageY;
 else if(evt.clientY) return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
 else {return null;}
}

//This function updates the large image, when a thumbnail is clicked.
function updateLargeImgSrc(new_src)
{largeImgSrc=new_src;}

//This function updates the small image, when a thumbnail is clicked.
function updateNormalImgSrc(new_src)
{normalImgSrc=new_src;}

//Our homemade image-swapping function.
function swapNormalImg(dest)
{normalHover=true;prodimg.src=dest;}

//This function resets the small image when the mouse is no longer hovering over a thumbnail.
function resetMainImg()
{prodimg.src=normalImgSrc;}

//This function hides the text behins image Image is proccessing.
function runClock(id)
{document.getElementById(id).style.visibility="hidden";}

//Begin ** Functions for TabContent
function commonToggle(mainTabDivId, mainContentDivId, currTabDivId, currContentDivId,opt)
{ 	browser_type=navigator.appName;
	if(opt==1) var_scr_width = screen.width/2.1;
	if(opt==2) var_scr_width = screen.width*96/100;
	if(opt!=3) document.getElementById(mainContentDivId).style.width=var_scr_width;
	var ulobj=document.getElementById(mainTabDivId)
	var ulist=ulobj.getElementsByTagName("li")
	for(var x=0;x<ulist.length;x++)
	{var ulistlink	= ulist[x].getAttribute("id")
	 if(ulistlink==currTabDivId) document.getElementById(ulistlink).className="selected";
	 else document.getElementById(ulistlink).className="";
	}

	var divobj=document.getElementById(mainContentDivId)
	var divlist=divobj.getElementsByTagName("div")
	for(var x=0;x<divlist.length;x++)
	{ if(browser_type=="Netscape" || browser_type=="Opera")
	  { if(divlist[x].getAttribute("id") != null)
	    {var divlistid=divlist[x].getAttribute("id")
	     if(divlistid==currContentDivId) document.getElementById(divlistid).className="selected";
	     else document.getElementById(divlistid).className="tabcontent";
	     }
	   }
	   else if(browser_type=="Microsoft Internet Explorer")
	   {if(divlist[x].getAttribute('id').charAt(0) != '')
	    {var divlistid=divlist[x].getAttribute("id")
	     if(divlistid==currContentDivId) document.getElementById(divlistid).className="selected";
	     else document.getElementById(divlistid).className="tabcontent";
	     }
	    }
	}
}

function tabToggle(mainTabDivId, mainContentDivId, currTabDivId, currContentDivId)
{commonToggle(mainTabDivId, mainContentDivId, currTabDivId, currContentDivId,1);
}

function tabNoticeToggle(mainTabDivId, mainContentDivId, currTabDivId, currContentDivId)
{commonToggle(mainTabDivId, mainContentDivId, currTabDivId, currContentDivId,2);
}

function tabToggle_fullwidth(find, mainTabDivId, mainContentDivId, currTabDivId, currContentDivId)
{commonToggle(mainTabDivId, mainContentDivId, currTabDivId, currContentDivId,3);
}
//END ** Functions for TabContent

//Begin ** Functions for Ajaxtooltip for Coupons
/*(C) www.dhtmlgoodies.com, March 2006. This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website. Terms of use: You are free to use this script as long as the copyright message is kept intact. However, you may not redistribute, sell or repost it without our permission. Thank you! www.dhtmlgoodies.com Alf Magne Kalleland*/

var x_offset_tooltip=5;
var y_offset_tooltip=0;

var ajax_tooltipObj=false;
var ajax_tooltipObj_iframe=false;

var ajax_tooltip_MSIE=false;
var inTime,outTime;

if(navigator.userAgent.indexOf('MSIE')>=0)ajax_tooltip_MSIE=true;

var  closeFlag=false,openFlag=false,externalFile,inputObj;
function demomouseover()
{closeFlag=true;}

function dynamic_ajax_showTooltip(externalFilex,inputObjx,wd,ht)
{
 if(wd > 0 && ht > 0)
 { var datex=new Date();
   inTime=datex.getTime();
   openFlag=true;
   inputObj=inputObjx;
   externalFile=externalFilex;
   setTimeout("openWindowFun("+wd+","+ht+")", 1000);
 }
 else{ajax_showTooltip(externalFilex,inputObjx);}
}

function ajax_showTooltip(externalFilex,inputObjx)
{ //alert(externalFilex);
  //alert(inputObjx);
  var datex=new Date();
  inTime=datex.getTime();
  openFlag=true;
  inputObj=inputObjx;
  externalFile=externalFilex;
  setTimeout("openWindowFun(0,0)",1000);
}
function outImageEvent()
{ var datex=new Date();
  outTime=datex.getTime();
  if(((outTime-inTime)/1000)<1)
  {openFlag=false;}
}

function ajax_positionTooltip(inputObj,wd,ht)
{ var leftPos=(ajaxTooltip_getLeftPos(inputObj));
  var topPos=ajaxTooltip_getTopPos(inputObj)+20;
  if (wd>0 && ht>0)
   {var tooltipWidth=230;}
  else
   {var tooltipWidth=document.getElementById('ajax_tooltip_content').offsetWidth +  document.getElementById('ajax_tooltip_arrow').offsetWidth;}
    ajax_tooltipObj.style.left=leftPos + 'px';
    ajax_tooltipObj.style.top=topPos + 'px';
}

var enableCache=true;
var jsCache=new Array();
var dynamicContent_ajaxObjects=new Array();

function ajax_showContent(divId,ajaxIndex,url)
{ document.getElementById(divId).innerHTML=dynamicContent_ajaxObjects[ajaxIndex].response;
  if(enableCache){jsCache[url]=	dynamicContent_ajaxObjects[ajaxIndex].response;}
  dynamicContent_ajaxObjects[ajaxIndex]=false;
}

function ajax_loadContent(divId,url)
{ if(enableCache && jsCache[url]){document.getElementById(divId).innerHTML=jsCache[url];return;}
  var ajaxIndex=dynamicContent_ajaxObjects.length;
  document.getElementById(divId).innerHTML='Loading content - please wait';
  dynamicContent_ajaxObjects[ajaxIndex]=new sack();
  dynamicContent_ajaxObjects[ajaxIndex].requestFile=url;
  dynamicContent_ajaxObjects[ajaxIndex].onCompletion=function(){ajax_showContent(divId,ajaxIndex,url); };
  dynamicContent_ajaxObjects[ajaxIndex].runAJAX();
}

function openWindowFun(wd,ht)
{ if(openFlag==false) {return false;}
  if(!ajax_tooltipObj)
  { ajax_tooltipObj=document.createElement('DIV');
    ajax_tooltipObj.onmouseout =delayFunction;
    ajax_tooltipObj.onmouseover=demomouseover;
    ajax_tooltipObj.style.position='absolute';
    ajax_tooltipObj.id='ajax_tooltipObj';
    document.body.appendChild(ajax_tooltipObj);
    var leftDiv=document.createElement('DIV');
    leftDiv.className='ajax_tooltip_arrow';
    leftDiv.id='ajax_tooltip_arrow';
    ajax_tooltipObj.appendChild(leftDiv);
    var contentDiv=document.createElement('DIV');
    contentDiv.className='ajax_tooltip_content';
    ajax_tooltipObj.appendChild(contentDiv);
    contentDiv.id='ajax_tooltip_content';
    if(ajax_tooltip_MSIE)
    { ajax_tooltipObj_iframe=document.createElement('<IFRAME frameborder="0">');
      ajax_tooltipObj_iframe.style.position='absolute';
      ajax_tooltipObj_iframe.border='0';
      ajax_tooltipObj_iframe.frameborder=0;
      ajax_tooltipObj_iframe.style.backgroundColor='#FFF';
      ajax_tooltipObj_iframe.src='about:blank';
      contentDiv.appendChild(ajax_tooltipObj_iframe);
      ajax_tooltipObj_iframe.style.left='0px';
      ajax_tooltipObj_iframe.style.top='0px';
    }
  }
  // Find position of tooltip
  ajax_tooltipObj.style.display='block';
  ajax_loadContent('ajax_tooltip_content',externalFile);
  if(ajax_tooltip_MSIE)
  { ajax_tooltipObj_iframe.style.width=ajax_tooltipObj.clientWidth + 'px';
    ajax_tooltipObj_iframe.style.height=ajax_tooltipObj.clientHeight + 'px';
  }
  if (wd>0 && ht>0){ajax_positionTooltip(inputObj, wd,ht);}
  else {ajax_positionTooltip(inputObj, 0,0);}
}

function delayFunction()
{closeFlag=false;setTimeout("closeWindowFun()", 2000);}

function closeWindowFun(){if(!closeFlag) {ajax_tooltipObj.style.display='none';}}

function ajax_hideTooltip()
{ajax_tooltipObj.style.display='none';}

function ajaxTooltip_getTopPos(inputObj)
{ var returnValue=inputObj.offsetTop;
  while((inputObj=inputObj.offsetParent)!=null)
  {if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;}
  return returnValue;
}

function ajaxTooltip_getLeftPos(inputObj)
{ var returnValue=inputObj.offsetLeft;
  while((inputObj=inputObj.offsetParent)!=null)
  {if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;}
  return returnValue;
}

/* Simple AJAX Code-Kit (SACK)©2005 Gregory Wild-Smithwww.twilightuniverse.com. Software licenced under a modified X11 licence, see documentation or authors website for more details */

function sack(file)
{
	this.AjaxFailedAlert="Your browser does not support the enhanced functionality of this website, and therefore you will have an experience that differs from the intended one.\n";
	this.requestFile=file;
	this.method="POST";
	this.URLString="";
	this.encodeURIString=true;
	this.execute=false;
	this.onLoading=function(){};
	this.onLoaded=function(){};
	this.onInteractive=function(){};
	this.onCompletion=function(){};

	this.createAJAX=function()
	{try{this.xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}
	 catch (e)
	 {try{this.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}catch (err){this.xmlhttp=null;}}
	 if(!this.xmlhttp && typeof XMLHttpRequest != "undefined")
	 {this.xmlhttp=new XMLHttpRequest();}
	 if(!this.xmlhttp){this.failed=true;}
	};

	this.setVar=function(name, value)
	{ if (this.URLString.length < 3){this.URLString=name + "=" + value;}
	  else{this.URLString += "&" + name + "=" + value;}
	}

	this.encVar=function(name,value)
	{var varString=encodeURIComponent(name) + "=" + encodeURIComponent(value);
	 return varString;
	}

	this.encodeURLString=function(string)
	{varArray=string.split('&');
	 for (i=0;i < varArray.length; i++)
	 { urlVars=varArray[i].split('=');
	   if (urlVars[0].indexOf('amp;') != -1)
	   {urlVars[0]=urlVars[0].substring(4);}
	   varArray[i]=this.encVar(urlVars[0],urlVars[1]);
	 }
	 return varArray.join('&');
	}

	this.runResponse=function(){eval(this.response);}

	this.runAJAX=function(urlstring)
	{this.responseStatus=new Array(2);
	 if(this.failed && this.AjaxFailedAlert)
	  {alert(this.AjaxFailedAlert);}
	 else
	 {if (urlstring)
	  { if (this.URLString.length)
	   {this.URLString=this.URLString + "&" + urlstring;}
	     else{this.URLString=urlstring;}
	  }
	  if (this.encodeURIString)
	  { var timeval=new Date().getTime();
	    this.URLString=this.encodeURLString(this.URLString);
	    this.setVar("rndval", timeval);
	  }
	  if (this.element){this.elementObj=document.getElementById(this.element); }
	  if (this.xmlhttp)
	  { var self=this;
	    if (this.method=="GET")
	    { var totalurlstring=this.requestFile + "?" + this.URLString;
	      this.xmlhttp.open(this.method, totalurlstring, true);
	    }
	    else{this.xmlhttp.open(this.method, this.requestFile, true);}
	    if (this.method=="POST")
	    {try{this.xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded')} catch (e){}}
	    this.xmlhttp.send(this.URLString);
	    this.xmlhttp.onreadystatechange=function()
	    {switch (self.xmlhttp.readyState)
	      {case 1:self.onLoading();break;
	       case 2:self.onLoaded();break;
	       case 3:self.onInteractive();break;
	       case 4:self.response=self.xmlhttp.responseText;
		self.responseXML=self.xmlhttp.responseXML;
		self.responseStatus[0]=self.xmlhttp.status;
		self.responseStatus[1]=self.xmlhttp.statusText;
		self.onCompletion();
		if(self.execute){self.runResponse();}
		if(self.elementObj)
		{ var elemNodeName=self.elementObj.nodeName;
		  elemNodeName.toLowerCase();
		  if(elemNodeName=="input" || elemNodeName=="select" || elemNodeName=="option" || elemNodeName=="textarea")
		  { self.elementObj.value=self.response;}
		  else{ self.elementObj.innerHTML=self.response;}
		}
		self.URLString="";
		break;
	      }
	    }
	  }
	 }
	}
this.createAJAX();
}
//END ** Functions for Ajaxtooltip for Coupons