var d = document;
//var b; b = navigator.appName;
//if(b.indexOf("Netscape")>-1){b = "moz";
//else if(b.indexOf("Internet Explorer")>-1){b = "ie";}
var b; if(typeof window.innerWidth!="undefined"){b="moz";}else{b="ie";}
//if(b=="ie"){d.title=d.title+" [ie]";}

//Preload images
var img1 = new Image();	img1.src = "images/btn-add.gif";
var img2 = new Image();	img2.src = "images/btn-add2.gif";
var img3 = new Image(); img3.src = "images/btn-checkout.gif";
var img4 = new Image(); img4.src = "images/btn-checkout2.gif";

userWidth = window.innerWidth;
userHeight = window.innerHeight;
if(b=="moz"){
		h = window.innerHeight;// + d.body.scrollTop; // not ie compatible
		w = window.innerWidth; // not ie compatible
	}else{
		h = d.body.clientHeight; // not ie compatible
		w = d.body.clientWidth;
	}


//Background
d.write("<div id='div0' onClick='imgCancel();' style='opacity:0.7; filter:alpha(opacity=70); visibility:hidden; ");
d.write("background-image:url(\"images/anim-loading.gif\"); background-position:center center; background-repeat:no-repeat; ");
d.write("position:absolute; z-index:2; height:99%; width:99%; background-color:black;'>");
d.write("</div>");
//Image Frame
d.write("<div id='div1' class='imgwin' style='visibility:hidden; height:300; width:300; cursor:pointer;' onClick=\"imgCancel()\">");
d.write("<table width='100%' height='100%'><tr><td id='divbody' align='center' valign='middle'>");
d.write("");
d.write("</td></tr><tr><td align='center'><a href='javascript:imgCancel();'><b>Close</b></a></td></tr></table></div>");
function doImg(img){
	d.getElementById("div0").style.visibility = '';
	d.getElementById("div0").style.top = d.body.scrollTop -100; //Add a buffer to Top AND Height so BG is not visible OnScroll
	if(b=="moz"){
		d.getElementById("div0").style.height = window.innerHeight + 100; // not ie compatible
	}else{
		d.getElementById("div0").style.height = d.body.clientHeight + 100;
	}
	var str = "<img src='"+img+"' id='divimg' style='visibility:hidden; cursor:pointer;' border=0 class='img' ";
	str = str +	" onLoad=\"imgLoaded(this,d.getElementById('div1'))\" onClick=\"d.getElementById('div1').style.visibility='hidden';\">";
	d.getElementById("divbody").innerHTML = str;
}
function imgLoaded(img,div){
	h = img.height+20; w = img.width+20;
	div.style.height = h+20; div.style.width = w;
	if(b=="moz"){
		div.style.top = window.innerHeight/2 - h/2 + d.body.scrollTop; // not ie compatible
		div.style.left = window.innerWidth/2 - w/2; // not ie compatible
	}else{
		div.style.top = d.body.clientHeight/2 - h/2 + d.body.scrollTop; // not ie compatible
		div.style.left = d.body.clientWidth/2 - w/2;
	}
	div.style.visibility = "";
	img.style.visibility = "";
}
function imgCancel(){
	d.getElementById("div1").style.visibility = "hidden";
	d.getElementById("divbody").innerHTML = "";
	d.getElementById("div0").style.visibility = 'hidden';
}
function posImg(){
	d.getElementById("div0").style.top = d.body.scrollTop - 100;
	var div1 = d.getElementById("div1");
	if(d.getElementById("divimg")!=null){
		var h = d.getElementById("divimg").height;
		if(b=="moz"){
			div1.style.top = window.innerHeight/2 - h/2 + d.body.scrollTop;
		}else{
			div1.style.top = d.body.clientHeight/2 - h/2 + d.body.scrollTop;
		}
	}
}

function imgWin(img){

	doImg(img);
}

/*
d.write("<div id='tip' style=\"position:absolute; visibility:hidden;\">Hello.</div>");
function doTip(e){
	obj = d.getElementById("tip");
	if(e.type=="mouseover"){
		obj.style.visibility = "";
		obj.style.backgroundColor = "black";
		obj.style.top = e.clientY+20;
		obj.style.left = e.clientX+10;
		obj.style.padding = 8;
	}
	else if(e.type=="mouseout"){
		obj.style.visibility = "hidden";
	}
}
*/


pmwidth = 200;
pmleft = w-384;
pmtop = 278;
if(b!="moz"){
	pmwidth+=26; pmleft+=21; pmtop+=8;
}
d.write ("<div id='pricematch' style='visibility:hidden; position:absolute; border:1px solid #222; background:black; left:"+pmleft+"; top:"+pmtop+"; width:"+pmwidth+"; padding:12px;'>"
	+"See it for less somewhere else? We will try to match or beat any price. Just let us know where:"
	+"<form name='priceform' method='post' action='pricematch.php' target='pm'>"
	+"<br><br>your email:<input type='text' class='inp' name='email'><br><br>address of item:<br><input type='text' class='inp' name='url'><p align='right' id='pricebtn'>"
	+"<a href='javascript://Send' onClick=\"sendpricematch(this)\">Send</a></p></form>"
	+"<iframe name='pm' src='pricematch.php' style='position:absolute; visibility:hidden; margin-top:-24; height:28; width:80; border:none;'></iframe></div>");
function pricematch(){
	obj = d.getElementById("pricematch");
	if(obj.style.visibility==""){
		obj.style.visibility="hidden";
		}else{
		obj.style.visibility="";
		d.priceform.email.select();
	}
}
function sendpricematch(obj){
	f = d.priceform;
	if(f.email.value==''){
		f.email.focus();
	}else if(f.url.value==''){
		f.url.focus();
	}else{
	f.submit(); obj.style.visibility='hidden'; d.getElementById('pm').onLoad=obj.parentNode.innerHTML='<i>Sent</i>';
	}
}