var d=document;
var ua = navigator.userAgent; if(ua.indexOf("MSIE 7")>0){o="ie7"}else if(ua.indexOf("Firefox")>0){o="ff"}else if(ua.indexOf("MSIE")>0){o="ie"}else {o="other"}
var b; if(typeof window.innerWidth!="undefined"){b="moz";}else{b="ie";}
var w = window.innerWidth || d.body.clientWidth;	var h=window.innerHeight || d.body.clientHeight;
//Preload images
img1 = new Image(); img1.src = "images/btn-purchase.png";
img2 = new Image(); img2.src = "images/btn-purchase2.png";
img3 = new Image();	img3.src = "images/facebook2.png";
d.oncomplete=new function(){
	img4 = new Image();	img4.src = "images/btn-checkout.png";
	img5 = new Image();	img5.src = "images/btn-checkout2.png";
	img8 = new Image();	img8.src = "images/btn-continue2.png";
	img6=new Image();img6.src = "images/parch-bottom2.png";
	img7=new Image();img7.src = "images/parch-topmid2.png";}
//Background
d.write("<div id='blk' onClick='imgCancel();' style='position:absolute; height:0; width:0; top:0; left:0; opacity:0.7; filter:alpha(opacity=70); visibility:hidden;"
	+"background-image:url(\"images/anim-loading.gif\"); background-position:center center; background-repeat:no-repeat; "
	+"position:absolute; z-index:2; height:99%; width:99%; background-color:black;'>"
	+"</div>");
//Image Frame
d.write("<div id='imgdiv' style='position:absolute; visibility:hidden; height:300; width:300; cursor:pointer; z-index:88;' onClick=\"imgCancel()\">"
	+"<table width='100%' height='100%'><tr><td id='divbody' align='center' valign='middle'>"
	+"</td></tr><tr><td align='center'><a href='javascript:imgCancel();'><b>Close</b></a></td></tr></table></div>");

function doFade(){
	d0 = d.getElementById("blk");
	if(d0.style.visibility=='hidden'){
		d0.style.height=h+100;
		d0.style.backgroundImage="url(\"images/anim-loading.gif\")";
		if(o=="ie7"){
			d0.filters[0].opacity=20;d0.style.visibility = '';setTimeout("d0.filters[0].opacity=40;",100);setTimeout("d0.filters[0].opacity=70;",200);
		}else if(o=="ie"){
		}else{
			d0.style.opacity=0.2;d0.style.visibility='';setTimeout("d0.style.opacity=0.4;",100);setTimeout("d0.style.opacity=0.7;",200);
		}
	}else if(d0.style.visibility==''){
		d0.style.backgroundImage='';
		if(o=="ie7"){
			setTimeout("d0.filters[0].opacity=40;",100);setTimeout("d0.filters[0].opacity=20;",200);setTimeout("d0.filters[0].opacity=20;;d0.style.visibility='hidden';",300);
		}else if(o=="ie"){
		}else{
			setTimeout("d0.style.opacity=0.4;",100);setTimeout("d0.style.opacity=0.2;",200);setTimeout("d0.style.opacity=0.2;d0.style.visibility='hidden';",300);}
	}
}


function viewbig(img){
	d.getElementById("blk").style.top = d.body.scrollTop -100; //Add a buffer to Top AND Height so BG is not visible OnScroll
	d.getElementById("blk").style.height = h + 100;
	doFade();
	var str = "<img src='"+img+"' id='divimg' style='visibility:hidden; cursor:pointer;' border=0 class='img' ";
	str = str +	" onLoad=\"imgLoaded(this,d.getElementById('imgdiv'))\" onClick=\"d.getElementById('imgdiv').style.visibility='hidden';\">";
	d.getElementById("divbody").innerHTML = str;
}
function imgLoaded(img,div){
	imgh = img.height+20; imgw = img.width+20;
	div.style.height = imgh+20; div.style.width = imgw;
	div.style.top = h/2 - imgh/2 + d.body.scrollTop;
	div.style.left = w/2 - imgw/2;
	div.style.visibility = "";
	img.style.visibility = "";
}
function imgCancel(){
	doFade();
	d.getElementById("imgdiv").style.visibility = "hidden";
	d.getElementById("divbody").innerHTML = "";
}


function posImg(){ //if browser is scrolled, img window will move with it
	d.getElementById("blk").style.top = d.body.scrollTop - 100;
	var imgdiv = d.getElementById("imgdiv");
	if(d.getElementById("divimg")!=null){
		var imgh = d.getElementById("divimg").height;
		imgdiv.style.top = h/2 - imgh/2 + d.body.scrollTop;
	}
}
function doResize(){ //if the browser is resized ?
	if(b=="moz"){var w = window.innerWidth; var h=window.innerHeight;}else{var w = d.body.clientWidth; var h = d.body.clientHeight;}
	var blk = d.getElementById("blk").style;blk.width=w-20;blk.height=816;
	var div1 = d.getElementById("div1").style;div1.left=w/2-div1.width.replace("px","")/2 +120;
}

function ello(){
	var myarr = new Array(
		"'ello.",
		"We gots <a href='?cat=New'>fresh jewels</a>."
		);
	var r = Math.round(Math.random() * (myarr.length-1));
	d.getElementById("ello").innerHTML = myarr[r];
} //var mytimer = setInterval("ello()", 6000);

function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}
function getCookie(c_name){
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{
		c_start=c_start + c_name.length+1;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		}
	  }
	return "";
}
//alert(d.cookie);
function region(){//£GBP 0.690894017	€EUR
	x = getCookie("region"); //alert(x);
	if(x=="us"||x==""){active="$USD";}
	else if(x=="uk"){active="£GBP";}
	else{active="$USD";}
	//var q = location.search.substring(1).replace("region=","");
	d.write("<div id='region'>Prices: <span id='activeregion'>"+active+"</span><div>"
	+"<span onClick=\"doregion('uk');\"><img src='images/flag2-gb.png' align='absmiddle'> £GBP</span>"
	+"<span onClick=\"doregion('us');\"><img src='images/flag2-us.png' align='absmiddle'> $USD</span>"
	+"<span onClick=\"doregion('eu');\"><img src='images/flag2-eu.png' align='absmiddle'> €EUR</span>"
	+"</div></div><style id='pricestyle'>.pricegbp{display:none;} .priceusd{display:none;} .priceeur{display:none;}</style>");
	doregion(x);
}
function doregion(x){
	myarr = new Array(".priceusd",".pricegbp",".priceeur");
	if(x==""||x=="us"){hideme=".pricegbp,.priceeur"; label="$USD";}
	if(x=="uk"){hideme=".priceusd,.priceeur"; label="£GBP";}
	if(x=="eu"){hideme=".priceusd,.pricegbp"; label="€EUR";}
	//set cookie to x
	setCookie("region",x,888);
	if(b=="moz"){
		d.getElementById("pricestyle").innerHTML = hideme+" {display:none;}";
	}else{//ie :P
		for(i in d.styleSheets){
			if(d.styleSheets[i].id=="pricestyle"){
				for(j in d.styleSheets[i].rules){
					var obj=d.styleSheets[i].rules[j];
					
					//for each .style, see if .style is within jshideme, if!=-1 hide it.
					//alert(obj.selectorText+" " +hideme.indexOf(obj.selectorText));
					
					//if(obj.selectorText==hideme){//worked for single
					if(hideme.indexOf(obj.selectorText)!=-1){
						obj.style.display="none";
						}else{
						if(obj.selectorText!=undefined){obj.style.display="";}
					}
				}
			}
		}
	}
	d.getElementById("activeregion").innerHTML = label;
}
function ep(obj){
	if(typeof(obj)=="string"){obj=d.getElementById(obj);}
	if(obj!=null){
	var usd = obj.innerHTML.replace("$","");
	var gbp = (usd*0.690894017).toFixed(2);
	var eur = (usd*0.814010).toFixed(2);
	if(obj.id=="shipfree"){gbp=Math.ceil(gbp); eur=Math.ceil(eur);}
	var newprice = "<span class='priceusd'>$"+usd+"</span>"
		+"<span class='pricegbp'>£"+gbp+"</span>"
		+"<span class='priceeur'>€"+eur+"</span>";
	obj.innerHTML = newprice;
	}
}
function epall(){ //Envelope all Prices with ids beginning with ep
	/*var str="";
	for(i in d.all){
		x=d.all[i].id;
		str+=x.substr("ep")+"<br>";
	} d.write(str);*/
}
function autosetregion(){
	ip = '<!--#echo var="REMOTE_ADDR"-->';
	//show loading animation
	//doalert("Grabbing product...");
	var xmlhttp;
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else if (window.ActiveXObject){// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}else{alert("Your browser does not support XMLHTTP!");}
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4){
			var val = xmlhttp.responseText;
			alert(val);
			//doalert("Grabbed product."); alertTimer();
		}
	}
	xmlhttp.open("GET","http://api.hostip.info/get_html.php?ip="+ip,true); xmlhttp.send(null);
}