var root = "../";

// Load images that will be immediately visible
ArrowRight = new Image(16,16); 	ArrowRight.src = root + "images/TransparentRight.gif";
ArrowDown = new Image(16,16); 	ArrowDown.src = root + "images/TransparentDown.gif"; 
RemoveBlack= new Image(71,17); RemoveBlack.src = root + "images/Remove.PNG";
RemoveGrey= new Image(71,17); RemoveGrey.src = root + "images/RemoveGrey.PNG"; 

function loadImages(){
	if (document.getElementById("Previewer")){
		var elements =  document.getElementsByTagName("img");
		var returnElements = [];
		var imageLoader = [];
		var current;
		var length = elements.length;
		for(var i=0; i<length; i++){
			current = elements[i];
			if("image90" == current.className){
				imageLoader[i] = new Image(200, 150);
				imageLoader[i].src = current.src.replace("-90.", "-200.");
			}
		}
		document.getElementById("Previewer").style.display="block";
	}
}

function Toggle(id){
	if (document.getElementById("Arrow_" + id).src.substring(document.getElementById("Arrow_" + id).src.length-8) == "Down.gif") {
		document.getElementById("Content_" + id).style.display="none";
		document.getElementById("Arrow_" + id).src= root + "images/TransparentRight.gif";
		if (id == "Contact") { document.getElementById("ContactLoveTo").innerHTML = "&nbsp;&mdash; we'd love to hear from you!";}
	} else {
		document.getElementById("Content_" + id).style.display="block";
		document.getElementById("Arrow_" + id).src= root + "images/TransparentDown.gif";
		if (id == "Contact") { document.getElementById("ContactLoveTo").innerHTML = ""; }
	}
}
 
function rejigBorders() {
	var imgs = document.getElementsByName("bordered");
	for (var i=0, j=imgs.length; i<j; i++) {
		imgs[i].width = imgs[i].firstChild.width*1+2;
		imgs[i].height = imgs[i].firstChild.height*1+2;
		console.debug(imgs[i].width);
	}
}

function glow(obj) {
	obj.style.backgroundColor="#C6EEBB";	
}
function unglow(obj) {
	obj.style.backgroundColor="";	
}
 
//Image switches 
function BigImage(image, name, id){
	if (document.getElementById("imagePreviewer")) {
		document.getElementById("imagePreviewer").src = root + "images/" + image.replace("-90.", "-200.");
		document.getElementById("imgPrevCaption").innerHTML = "<a href=/product-" + id + ".html>" + name + "</a>";
	}
	return true;
}

function changeOpac(opacity) {
    var object = document.getElementById("FloatingBasket").style;
	if (opacity==0) {
		object.display = "none";
	} else {
	    object.opacity = (opacity / 100);
	    object.MozOpacity = (opacity / 100);
	    object.KhtmlOpacity = (opacity / 100);
	    object.filter = "alpha(opacity=" + opacity + ")";
	}
}

function num2cash(n){
	if (Math.round(n) == Math.round(n*100)/100) {
		return Math.round(n*100)/100 + ".00";
	} else if (Math.round(n*10)/10 == Math.round(n*100)/100) {
		return Math.round(n*100)/100 + "0";
	} else if (Math.round(n*100)/100 == Math.round(n*100)/100) {
		return Math.round(n*100)/100;
	}
	return false;
}

function hoverOn(it) {
	if (it.src.substr(it.src.length -10) == "Remove.PNG") it.src = root + "images/RemoveHover.PNG";
}

function hoverOff(it){
	if (it.src.substr(it.src.length -10) == "eHover.PNG") it.src = root + "images/Remove.PNG";
}

var xmlhttp
function ajax(action) {
	xmlhttp = null;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = null;
	  }
	 }
	@end @*/
	if (window.XMLHttpRequest) {
		  xmlhttp=new XMLHttpRequest()
	}
	// code for IE
	else if (window.ActiveXObject) {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	if (xmlhttp!=null) 	{
		xmlhttp.onreadystatechange=state_Change;
		xmlhttp.open("GET","/3hp/ajax.php?action=" + action,true);
		xmlhttp.send(null);
  	} else alert("Your browser does not support XMLHTTP.\n\n Try using an up-to-date browser such as Firefox 2 or Internet Explorer 5+.\n\n If you're still stuck, please e-mail help@geological-supplies.com: we'll do everything we can to help!")
}

function state_Change() {
	if (xmlhttp.readyState==4) {return xmlhttp.responseText;}
}
