// JavaScript Document

hexZoom.WindowID 	= "imagezoom"
hexZoom.BackID 		= "imagezoombkg"
hexZoom.MainImageID = "imagezoommain"
hexZoom.ThumbsID	= "imagezoomthumbs"
//hexZoom.ThumbSrc	= "/media/Items/images/zooms/"
//hexZoom.ImageSrc	= "/media/Items/images/zooms/"
hexZoom.LoaderImg	= "/images/ajax-loader.gif"

function init_mainjs () {
	hex.browser.png.ApplyIEFilter()
	if (!hex.browser.supportPngAlpha()) {
		hex.LoadStyleSheet("/styles/iefix.css","iefix",iefixloaded)
	}
	if (document.cookie.acceptcontent != "1") {
	//	inpageInfo(0)
	}
}
function iefixloaded() {
}
//window.onload = init_mainjs
hex.onLoad.Add(init_mainjs)

function cCur (intNum) {
		var strCur = intNum.toString().replace(/\£|\,/g,'');
		if (intNum = "") { strCur = 0}
		if (isNaN(strCur)) {
			strCur = "0";
		}
		var strPounds = parseInt(strCur).toString()
		var strPence = (Math.floor((Math.abs(strCur) - strPounds)*100)).toString()
		if (strPence < 10) {strPence = "0" +strPence}
		if (isNaN(strPounds)) { strPounds = "0"}
		if (isNaN(strPence)) { strPence = "00"}
		for (var i = 0; i < Math.floor((strPounds.length-(1+i))/3); i++) {
			strPounds = strPounds.substring(0,strPounds.length-(4*i+3))+','+ 	strPounds.substring(strPounds.length-(4*i+3));
		}
		
		return "£" + strPounds + "." + strPence
	}

function inpageInfo(intType) {
hex.BlackOut.Animate = false
	
	var blnIE = (window.innerHeight > 0) ? false : true
	var intWinHeight = (blnIE) ? document.documentElement.clientHeight : window.innerHeight
	var intWinWidth	= (blnIE) ? document.documentElement.clientWidth : window.innerWidth
	var intScrollTop = (document.documentElement) ?  document.documentElement.scrollTop : document.body.scrollTop
	hex.$("inpagepopup").style.display = "block"
	hex.$("inpagepopup").style.zIndex = parseInt(hex.BlackOut.Depth) + 1
	hex.$("inpagepopup").style.left = (hexZoom.winWidth()/2) - (hexZoom.$width("inpagepopup")/2) + "px"
	hex.$("inpagepopup").style.top = (intWinHeight/2) - (hexZoom.$height("inpagepopup")/2) + ((document.documentElement) ?  document.documentElement.scrollTop : document.body.scrollTop) + "px"
	hex.$("inpagepopup").style.height = "415px"
	hex.$("inpagepopup").style.width = "555px"
	var intY = ((intWinHeight - intScrollTop) / 2) - (415/2) + intScrollTop
	//alert(hexZoom.$height("inpagepopup"))
	if (intY < 0) {
		intY = 0
	}
	hex.$("inpagepopup").style.top = intY +"px"
	hex.$("inpagepopup_terms").style.display = "none"
	hex.$("inpagepopup_exrate").style.display = "none"
	hex.$("inpagepopup_terms").style.display = "none"
	hex.$("inpagepopup_guide").style.display = "none"
	hex.$("inpagepopup_unsubscribe").style.display = "none"
	hex.$("inpagepopup_guide2").style.display = "none"
	hex.$("inpagepopup_guide3").style.display = "none"

	hex.$("inpagepopup_closeimage").style.display = "block"
	hex.$("inpagepopup_closebtn").style.display = "block"
	
	switch (intType) {
		case 0:
			hex.BlackOut.Show()
			hex.$("inpagepopup_warning").style.display = "block"
			hex.$("inpagepopup_closeimage").style.display = "none"
			hex.$("inpagepopup_closebtn").style.display = "none"
		break;
		case 1:
			hex.BlackOut.Show()
			hex.$("inpagepopup_terms").style.display = "block"
		break;
		case 2:
			hex.BlackOut.Show()
			hex.$("inpagepopup").style.top = hex.Common.findPos(hex.$("currencyconverter"))[1] +"px"
			hex.$("inpagepopup").style.left = (hex.Common.findPos(hex.$("currencyconverter"))[0] + 220) +"px"
			//currencyconverter
			hex.$("inpagepopup_exrate").style.display = "block"
		break;
		case 3:
			hex.BlackOut.Show()
			hex.$("inpagepopup_unsubscribe").style.display = "block"
		break;
		case 4:
			hex.$("inpagepopup_guide").style.display = "block"
			hex.$("inpagepopup").style.height = "425px"
			hex.$("inpagepopup").style.width = "300px"
			var intY = ((intWinHeight - intScrollTop) / 2) - (610/2) + intScrollTop
			if (intY < 0) {
				intY = 0
			}
			hex.$("inpagepopup").style.top = hex.Common.findPos(hex.$("itemoptions"))[1] +"px"
			hex.$("inpagepopup").style.left = hex.Common.findPos(hex.$("itemoptions"))[0] -320 +"px"
		break;
		case 5:
			hex.$("inpagepopup_guide2").style.display = "block"
			hex.$("inpagepopup").style.height = "410px"
			hex.$("inpagepopup").style.width = "200px"
			var intY = ((intWinHeight - intScrollTop) / 2) - (610/2) + intScrollTop
			if (intY < 0) {
				intY = 0
			}
			hex.$("inpagepopup").style.top = hex.Common.findPos(hex.$("itemoptions"))[1] +"px"
			hex.$("inpagepopup").style.left = hex.Common.findPos(hex.$("itemoptions"))[0] -250 +"px"
		break;
		case 6:
			hex.BlackOut.Show()
			hex.$("inpagepopup_subscribe").style.display = "block"
			hex.$("inpagepopup").style.height = "100px"
			hex.$("inpagepopup").style.width = "300px"
			hex.$("inpagepopup").style.top = hex.Common.findPos(hex.$("mailling"))[1] +"px"
			hex.$("inpagepopup").style.left = (hexZoom.winWidth()/2) - (hexZoom.$width("inpagepopup")/2) + "px"
		break;
		case 7:
			hex.$("inpagepopup_guide3").style.display = "block"
			hex.$("inpagepopup").style.height = "410px"
			hex.$("inpagepopup").style.width = "250px"
			var intY = ((intWinHeight - intScrollTop) / 2) - (610/2) + intScrollTop
			if (intY < 0) {
				intY = 0
			}
			hex.$("inpagepopup").style.top = hex.Common.findPos(hex.$("itemoptions"))[1] +"px"
			hex.$("inpagepopup").style.left = hex.Common.findPos(hex.$("itemoptions"))[0] -300 +"px"
		break;
	}

	
	return false
}
function hideInpageInfo() {
	hex.BlackOut.Animate = false
	hex.BlackOut.Hide()
	hex.$("inpagepopup").style.display = "none"
	hex.$("inpagepopup_terms").style.display = "none"
	hex.$("inpagepopup_exrate").style.display = "none"
	return false
}


function ScreenCentre(strDim) {
	var blnIE = (window.innerWidth > 0) ? false : true
	var intX = (blnIE) ? document.documentElement.clientWidth : window.innerWidth
	intX = intX/2 + ((document.documentElement) ?  document.documentElement.scrollLeft : document.body.scrollLeft)
	var intY = (blnIE) ? document.documentElement.clientHeight : window.innerHeight
	intY = intY/2 + ((document.documentElement) ?  document.documentElement.scrollTop : document.body.scrollTop)
	return (strDim != null) ? ((strDim == "X") ? intX : ((strDim == "Y") ? intY : null)) : new Array(intX,intY)
}
var $ = document.getElementById
var intScrollTop = 0
var intScrollLeft = 0
var objWin = null
/*function showImageZoom(strImageToShow,intID) {
	var strWinName = "imagezoom"
	var arrCookie = document.cookie.split(';');
	for(var i=0;i < arrCookie.length;i++) {
		var strCookie = arrCookie[i];
		if (strCookie == "winopen=1") { 
			var objWin = window.open("",strWinName)
			objWin.close()
			break;
		}
	}
	var objWin = window.open("imagezoom.asp?image=" + strImageToShow,strWinName,'dependent=no,titlebar=no,location=yes,status=yes,scrollbars=yes,resizable=yes,width=800,height=650');
	return false;
}*/
var objImageZoomVars	= {
	Prefix	: ""
}
function showImageZoom(strImageToShow,intID) {
	$("imagezoom_image").style.display = "none"
	$("imagezoom_loader").style.display = "block"
	$("imageblackout").style.display = "block"
		
	
	var blnIE = (window.innerHeight > 0) ? false : true
	
	var intWinWidth = (blnIE) ? document.documentElement.clientWidth : window.innerWidth
	var intBodyWidth = (blnIE) ? document.body.scrollWidth : document.body.scrollWidth
	var intWinHeight = (blnIE) ? document.documentElement.clientHeight : window.innerHeight
	var intBodyHeight = (blnIE) ? document.documentElement.scrollHeight : document.body.scrollHeight
	$("imageblackout").style.width = ((intBodyWidth > intWinWidth)?intBodyWidth : intWinWidth) + "px"
	$("imageblackout").style.height = ((intBodyHeight > intWinHeight)?intBodyHeight : intWinHeight) + "px"
	intScrollTop = document.documentElement.scrollTop
	intScrollLeft = document.documentElement.scrollLeft
	scroll(0,0)
	
	//var arrUrl = window.location.toString()
	
	
	//window.location = arrUrl.split("#")[0] + "#img1"
	
	/*var intMaxHeight = (blnIE) ? document.documentElement.clientHeight : window.innerHeight
	var intMaxWidth = (blnIE) ? document.documentElement.clientWidth : window.innerWidth
	
	if (isNaN(intMaxHeight)) {intMaxHeight = -1}else{intMaxHeight -= 100}
	if (isNaN(intMaxWidth)) {intMaxWidth = -1}else{intMaxWidth -= 100}
	if (intMaxHeight == -1 && intMaxWidth == -1) {
		intMaxWidth = 640
		intMaxHeight = 480
	}*/
	//if (hex.BlackOut) {
	//hex.BlackOut.Animate = false
	///hex.BlackOut.Show()
	//}
	//$("imagezoom_contents").style.zindex = hex.BlackOut.Depth + 1
	$("imagezoom_contents").style.width = "100px"

	$("imagezoom_contents").style.height = "100px"
	$("imagezoom").style.width = "110px"
	$("imagezoom").style.height = "110px"
	var arrCentre = ScreenCentre()	
	hex.$("imagezoom").style.left = (arrCentre[0] - 55) + "px"
	hex.$("imagezoom").style.top = (arrCentre[1] - 55) + "px"
	//hex.$("imagezoom").style.left = 0+ "px"
	//hex.$("imagezoom").style.top = 0 + "px"
	
	var objTempImage 	= document.createElement("img")
	objTempImage.src 	= objImageZoomVars.Prefix + "uploads/items/originals/" + strImageToShow
	objTempImage.id		= "imagezoom_mainimage"
	$("imagezoom_image").innerHTML = ""
	$("imagezoom_image").appendChild(objTempImage)
	$("imagezoom").style.display = "block"
	
	if (objTempImage.readyState) {
		objTempImage.onreadystatechange = function () {
			if (this.readyState.toString() == "loaded" || this.readyState.toString() == "complete") {
				zoomImageLoaded()
			}
		}
		if (objTempImage.readyState.toString() == "loaded" || objTempImage.readyState.toString() == "complete") {
			zoomImageLoaded()
		}
	}else{
		objTempImage.onload = function () {
			zoomImageLoaded()
		}
		if (objTempImage.complete) {
			zoomImageLoaded()
		}
	}
	return false
}
function zoomImageLoaded() {
	$("imagezoom_image").style.display = "block"
	$("imagezoom_loader").style.display = "none"
	var intHeight = $("imagezoom_mainimage").height
	var intWidth = $("imagezoom_mainimage").width
	$("imagezoom").style.width = (intWidth) + "px"
	$("imagezoom").style.height = (intHeight+50) + "px"
	//hex.BlackOut.Show()
	
	hex.$("imagezoom").style.left = 0+ "px"
	hex.$("imagezoom").style.top = 0 + "px"
	
	var blnIE = (window.innerHeight > 0) ? false : true
	var intWinWidth = ((blnIE) ? document.documentElement.clientWidth : window.innerWidth)
	var intWinHeight = ((blnIE) ? document.documentElement.clientHeight : window.innerHeight)
	
	if (intWidth < intWinWidth) {
		var intLeft = (ScreenCentre()[0] - (intWidth/2))
		var intTop	= (ScreenCentre()[1] - (intHeight/2) -30)
		hex.$("imagezoom").style.left = ((intLeft < 0) ? 0 : intLeft) + "px"
		hex.$("imagezoom").style.top = ((intTop < 0) ? 0 : intTop)+ "px"
	}
	if (intHeight > intWinHeight-60) {
		hex.$("imagezoom").style.top = 0
	}

	$("imagezoom_header").childNodes[0].style.width = ((intWinWidth <  intWidth) ? intWinWidth : intWidth) + "px"
	$("imagezoom_footer").childNodes[0].style.width = ((intWinWidth <  intWidth) ? intWinWidth : intWidth) + "px"
	

	$("imagezoom_contents").style.width = intWidth + "px"
	$("imagezoom_contents").style.height = intHeight + "px"
	//$("imageblackout").style.width = document.body.scrollWidth + "px"
	//$("imageblackout").style.Height = document.body.scrollHeight + "px"
	//hex.Effects.doResize($("imagezoom"),"auto","auto",intWidth+5,intHeight+5,10,50,true)
	//hex.Effects.doResize($("imagezoom_contents"),"auto","auto",intWidth,intHeight,10,50,true,null,"centre","centre")
	//hex.Effects.doResize($("imagezoom_image"),"auto","auto",intWidth,intHeight,10,50,true)
}
function closeZoom() {
	$("imageblackout").style.display = "none"
	//if (hex.BlackOut) {
	//hex.BlackOut.Animate = false
	//hex.BlackOut.Hide()
	//}
	///hex.Effects.doResize($("imagezoom"),"auto","auto",0,0,10,50,true,null,null,null,true)
	//hex.Effects.doResize($("imagezoom_contents"),"auto","auto",0,0,10,50,true,null,"centre","centre")
	//$("imagezoom").style.display = "none"
	$("imagezoom").style.display = "none"
	$("imagezoom_header").childNodes[0].style.width = ""
	$("imagezoom_footer").childNodes[0].style.width = ""
	scroll(intScrollLeft,intScrollTop)
	return false
}

function subscribe() {
	var strVars = "name=" + hex.$("mail_name").value + "&email=" + hex.$("mail_email").value
	hex.Connect.Send(objImageZoomVars.Prefix + "newsletter/subscribe.asp",strVars,subscribed)
	return false;
}
function subscribed(objXml) {
	if (objXml.responseText == "Subscribed") {
		hex.$("mailing_msg").innerHTML = "Thank you for joining our mailling list."
		hex.$("mail_name").value = ""
		hex.$("mail_email").value = ""
	}else{
		hex.$("mailing_msg").innerHTML = objXml.responseText
	}
	inpageInfo(6)
}
/*

			<label for="mail_name">Name:</label>
			<input id="mail_name" name="mail_name" type="text"  style="width: 160px;" />
			<label for="mail_email">Email Address:</label>
			<input id="mail_email
*/