//--------------------------------- gallery 1.10.1
var galleryReq;
var slideshow_loaded=false;
var currentPID=0;
var currentPIDloaded=false;
function onGReqError(){
	alert("ERROR");
}
function loadSlideShow(){
	//try{
	galleryReq=new mAJAXRequest();
	//}catch(err){
		//document.getElementById("jsclassess").src="scripts/classes.js";
	//}
	//---------------------------------------------------------[create gallery container
	var mainBody=document.getElementsByTagName("body").item(0);
	var gContainerDIV=document.createElement("div");
	gContainerDIV.setAttribute("id","slideshow");
	gContainerDIV.style.display="none";
	//gContainerDIV.innerHTML='<div id="slideback"><iframe id="ifrgx" style="position:absolute;left:0;top:0;z-index:100;width:100%;height:100%;filter:progid:DXImageTransform.Microsoft.alpha(style=0,opacity=0);border:none;"></iframe></div><div id="slideholder"><div class="content group"><div class="padding"><div class="image_slide"><img id="image_slide" width="640" alt="" /></div><div class="optcontainer"><p class="cls"><a class="close" href="javascript:;" onclick="closeSlideshow()">Close Gallery</a></p><h1 id="productname_container"></h1><div class="detailed-button group"><p class="price"><span id="price_container">Call</span></p><form id="addtocartform" method="post"><!--<label>Qty</label><input type="text" name="quantity" value="1" />--><button type="submit" class="bact">Add to Cart</button></form><br class="clean" /></div><ul class="specifications" id="specification_container"></ul><p id="stockno_container"></p><p id="description_container"></p></div></div></div></div>';
	gContainerDIV.innerHTML='<div id="slideback"><iframe id="ifrgx" style="position:absolute;left:0;top:0;z-index:100;width:100%;height:100%;filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);border:none;"></iframe></div><div id="slideholder"><div class="content"><div class="padding"><div class="image_slide"><img id="image_slide" width="640" alt="" /></div><div class="optcontainer"><a class="close" href="javascript:;" onclick="closeSlideshow()">Close Gallery</a><div class="vars"><h1 id="productname_container"></h1><!-- | --><div id="estoredetails_container" style="display:none" class="detailed-button group"><p class="price"><span id="price_container">Call</span></p><p id="msrp_container"></p><form id="addtocartform" method="post"><p id="options_list" style="display:none"></p><label>Qty</label><input type="text" name="quantity" value="1" /><button type="submit" class="bact">Add to Cart</button></form><br class="clean" /></div><p id="freeshipping_notice"style="display:none">Free Shipping</p><p id="instocknotice" style="display:none"></p><ul class="specifications" id="specification_container"></ul></div><!-- | --><h2 id="stockno_container"></h2><p id="description_container"></p></div></div></div></div></div>';
	mainBody.appendChild(gContainerDIV);
	//-----------------------------------------
	galleryReq.setRequestLocation("/isapi_xml.php");
	galleryReq.setResponseType('xml');
	galleryReq.assignParser(galleryParser);
	galleryReq.assignErrorHandler(onGReqError);
	//-----------------------------------------
	slideshow_loaded=true;
}
function galleryParser(){
	if(typeof sIFR == "function"){
		sIFR.rollback(named({sSelector:"#slideholder h1"}))
		sIFR.rollback(named({sSelector:"#slideholder h2"}))
	}
	var resp=galleryReq.getResponse();
	document.getElementById("productname_container").innerHTML=resp.getElementsByTagName("PRODUCT_NAME")[0].childNodes[0].nodeValue;
	document.getElementById("description_container").innerHTML=resp.getElementsByTagName("PRODUCT_DESCRIPTION")[0].childNodes[0].nodeValue;
	document.getElementById("stockno_container").innerHTML=resp.getElementsByTagName("PRODUCT_STOCKNO")[0].childNodes[0].nodeValue;
	var isEstore=resp.getElementsByTagName("ESTORE")[0].childNodes[0].nodeValue;
	if(isEstore==1){
		document.getElementById("estoredetails_container").style.display="block";
		document.getElementById("addtocartform").action="/addToCart.php?pid="+currentPID;
		var price=resp.getElementsByTagName("PRICE")[0].childNodes[0].nodeValue;
		if(price=="$0.00") price="Call";
		document.getElementById("price_container").innerHTML=price;
		
		var msrp=resp.getElementsByTagName("MSRP")[0].childNodes[0].nodeValue;
		if(msrp!="$0.00") document.getElementById("msrp_container").innerHTML='MSRP: '+msrp;
		
		var isFreeShipping=resp.getElementsByTagName("FREE_SHIPPING")[0].childNodes[0].nodeValue;
		if(isFreeShipping==1) document.getElementById("freeshipping_notice").style.display="block";
		
		var pOpt=resp.getElementsByTagName("OPTIONS")[0].childNodes;//get options element
		if(pOpt.length>0){
			var options_list=document.getElementById("options_list");
			var optCategory=resp.getElementsByTagName("CATEGORY");//get all options categories
			options_list.innerHTML="";
			for(var i=0;i<optCategory.length;i++){
				var optCategory_name=optCategory[i].attributes.getNamedItem("category_name").nodeValue;
				var pOtions=optCategory[i].childNodes;
				var listOpts=document.createElement("LABEL");//create label with category name
				listOpts.innerHTML=optCategory_name+": ";
				options_list.appendChild(listOpts);
				
				listOpts=document.createElement("SELECT");//create drop down for options
				options_list.appendChild(listOpts);
				
				listOpts.name="options[]";
				
				for(var j=0;j<pOtions.length;j++){
					var oOption=document.createElement("OPTION");
					listOpts.options.add(oOption);
					oOption.text=pOtions[j].childNodes[0].nodeValue;
					oOption.value=pOtions[j].attributes.getNamedItem("value").nodeValue;
				}
			}
			options_list.style.display="block";
		}
		
		
		//resp.getElementsByTagName("INSTOCK")[0].childNodes[0].nodeValue;
		//resp.getElementsByTagName("FREE_SHIPPING")[0].childNodes[0].nodeValue;
		//resp.getElementsByTagName("options")[0].childNodes[0].nodeValue;
		//document.getElementById("specification_container").innerHTML=resp.getElementsByTagName("PRODUCT_SPECIFICATION")[0].childNodes[0].nodeValue;
		
	}
	var slideback=document.getElementById("slideback");
	slideback.style.width=document.documentElement.scrollWidth+"px";
	slideback.style.height=document.documentElement.scrollHeight+"px";
		
	document.getElementById("slideholder").style.top=document.documentElement.scrollTop+"px";
	document.getElementById("slideshow").style.display="block";
	//----------------------------------------------------------------------------------------
	currentImage=new Image();//<-clear old images
	currentImage.src=resp.getElementsByTagName("PRODUCT_IMG")[0].childNodes[0].nodeValue;
	document.getElementById("image_slide").src=currentImage.src;
	currentPIDloaded=true;
	if(typeof sIFR == "function"){
		sIFR.replaceElement(named({sSelector:"#slideholder h1,#slideholder h2", sFlashSrc:"http://www.ellejewelry.com/futura-h1.swf", sColor:"#000000", sWmode:"transparent"}));
		
	}
}
function getProduct(pid){
	if(!slideshow_loaded){
		loadSlideShow();
	}
	if(pid==currentPID){
		if(currentPIDloaded)//display same screen if already loaded, so if no images then we won't request it again
			document.getElementById("slideshow").style.display="block";
	}else{
		currentPIDloaded=false;
		currentPID=pid;
		document.getElementById("image_slide").src="";
		galleryReq.setData("module=product&pid="+pid);
		galleryReq.send();
	}
}
function closeSlideshow(){
	document.getElementById("slideshow").style.display="none";
}