var ind =0;

//mi occorre la grandezza dello schermo per spostare il footer
function getwinHeight(){
		var winHeight = window.innerHeight
		|| document.documentElement && document.documentElement.clientHeight
		|| document.body.clientHeight;
		return winHeight;
}	

//blocca il footer quando si avvicina troppo
function scaleComplete(obj){
		/*var imgWidth =	"imgWidth:=" + obj["imgWidth"] + "px ";
		var imgHeight=	"imgHeight:=" + obj["imgHeight"] + "px ";
		var holderWidth="holderWidth:=" +	obj["holderWidth"] + "px ";
		var holderHeight="holderHeight:=" +	obj["holderHeight"] + "px ";
		var imgMargin="imgMargin:=" +	obj["imgMargin"] + "px ";
		var holderMargin="holderMargin:=" +		obj["holderMargin"] + "px ";*/
		//window.status=imgWidth+imgHeight+holderWidth+holderHeight+imgMargin+holderMargin+"Inner"+getwinHeight()+"px";
		//window.status="Inner:= "+getwinHeight()+"px";
		var _main = JQ(".main-container");
		var _footer = JQ(".footer");
		var mBottom = window.event ? 60 : 30;
		if(getwinHeight() < 650 ){
			_main.css({"marginBottom" : mBottom });
			//_main.css({"height":480});
			_footer.css({"position" : "relative"});
			_footer.css({"clear" : "both"});
		}else{
			_main.css({"marginBottom":0 });
			//_main.css({"height":"auto"});
			_footer.css({"position":"absolute"});
			_footer.css({"bottom":0});
		}
}

function swapImage(src,id,zoomsrc){
	document.getElementById('sub_SmallImg_div_'+ ind).className="sub_SmallImg_div";
	var image_Large = document.getElementById('mainImage');
	image_Large.src=src;
	if(!id){
	id='0';
	}
	ind=parseFloat(id);
	//per lo zoom
	var zoomImage_Img = document.getElementById("zoomImage_Img");
	if(zoomImage_Img){
		zoomImage_Img.src=zoomsrc; 
	}
	document.getElementById('sub_SmallImg_div_'+id).className="sub_SmallImg_div_enable";
}

function swapLeft(){
	var curr_ind=ind;
	//perchè parte da -1
	curr_ind=curr_ind-1;
	//
	if(document.getElementById('img_'+curr_ind)){
		document.getElementById('sub_SmallImg_div_'+ (curr_ind+1)).className="sub_SmallImg_div";
		var swaptitle = document.getElementById('img_'+curr_ind).getAttribute("swaptitle");
		var swapzoomImage = document.getElementById('img_'+curr_ind).getAttribute("swapzoomImage");
		swapImage(swaptitle,curr_ind,swapzoomImage);
	}
}

function swapRight(){
	var curr_ind=ind;
	//perchè parte da -1
	curr_ind=curr_ind+1;
	//
	if(document.getElementById('img_'+curr_ind)){
		document.getElementById('sub_SmallImg_div_'+ (curr_ind-1)).className="sub_SmallImg_div";
		var swaptitle = document.getElementById('img_'+curr_ind).getAttribute("swaptitle");
		var swapzoomImage = document.getElementById('img_'+curr_ind).getAttribute("swapzoomImage");
		swapImage(swaptitle,curr_ind,swapzoomImage);
	}
}

function GoToProdURL(location){
this.location.href ="./ProductDetail.jsp?prod="+location;
}

function GoToSizeChart(){
var goUrl =this.location.pathname;
goUrl = goUrl.toLowerCase().replace('productdetail','customer_service/ringsSize');
showWebMessageBox(508,614,'',goUrl,true);
}

function GoToRelatedProducts(prodId,testata){
var goUrl =this.location.pathname;
goUrl = goUrl.replace('productDetail','RelatedProducts');
goUrl = goUrl + '?prod='+prodId;
showWebMessageBox(360,240,'RELATED PRODUCTS | '+ testata ,goUrl,true);
}

function findStore(){
this.location.href ="./storeLocator.jsp";
}

function openPrintPage(prodId){
	var goUrl =this.location.pathname;
	goUrl = goUrl.toLowerCase().replace('productdetail','productPrint');
	goUrl = goUrl + '?prod='+prodId+'&ind='+(parseFloat(ind)-1);
	//window.status=goUrl;
	showWebMessageBox(630,350,PRINT,goUrl,true);
}

function openPrintBrdPage(prodId){
	var goUrl =this.location.pathname;
	goUrl = goUrl.toLowerCase().replace('productbrddetail','productPrintBrd');
	goUrl = goUrl + '?prod='+prodId+'&ind='+(parseFloat(ind)-1);
	showWebMessageBox(630,350,PRINT,goUrl,true);
}
  
function openSendEmail(prodId){
	var goUrl =this.location.pathname;
	goUrl = goUrl.toLowerCase().replace('productdetail','customer_service/sendtofriend');
	goUrl = goUrl + '?prod='+prodId+'&ind='+ind;
	//window.status=goUrl;
	showWebMessageBox(800,600,'',goUrl,true);
}

function showTechDet(){
	var spanTec = document.getElementById('span_tech');
	var spanDesc = document.getElementById('span_desc'); 
	var techDet = document.getElementById('techDet'); 
	var descDet = document.getElementById('descDet'); 
	spanTec.style.display='block';
    spanDesc.style.display='none';
    
    techDet.className = "selected";
    descDet.className = "inactive";
    //techDet.style.color= '#16110a';
    //descDet.style.color= '#F1F0ED';
}

function showDescDet(){
	var spanTec = document.getElementById('span_tech');
	var spanDesc = document.getElementById('span_desc'); 
	var techDet = document.getElementById('techDet'); 
	var descDet = document.getElementById('descDet'); 
	if(spanTec) {
		spanTec.style.display='none';
		techDet.className = "inactive";
	}
	
    spanDesc.style.display='block';    
    descDet.className = "selected";
    /*
    techDet.style.color= '#666666';
    descDet.style.color= '#16110a';
    */
}

function ddMenu(){
  var h = document.getElementById('ddheader');
  var c = document.getElementById('ddcontent');

  if(c.style.display == 'none' || c.style.display == ''){
      c.style.display = 'block';
      c.style.height = 'auto';
    }
  else{
      c.style.display = 'none';
      c.style.height = 'auto';
 	}

 }
 
 function loadParure(){
	var RELATEDPRODUCTS = document.getElementById("RELATEDPRODUCTS");
	var PARURE = document.getElementById("PARURE");
	PARURE.className="lightboxCaption_select";
	RELATEDPRODUCTS.className="lightboxCaption_default";
	PARURE.onclick=function() {return false;}
	RELATEDPRODUCTS.onclick =function() {loadRelatedProducts();}
	var lightboxFrame = document.getElementById("lightboxFrame");
	var src = lightboxFrame.src;
	src = src.replace("&mode=rel","&mode=par");
	lightboxFrame.src=src;
}

 function loadRelatedProducts(){
	var RELATEDPRODUCTS = document.getElementById("RELATEDPRODUCTS");
	var PARURE = document.getElementById("PARURE");
	PARURE.className="lightboxCaption_default";
	RELATEDPRODUCTS.className="lightboxCaption_select";
	PARURE.onclick=function() {loadParure();}
	RELATEDPRODUCTS.onclick =function() {return false;}
	var lightboxFrame = document.getElementById("lightboxFrame");
	var lightboxFrame = document.getElementById("lightboxFrame");
	var src = lightboxFrame.src;
	src = src.replace("&mode=par","&mode=rel");
	lightboxFrame.src=src;
	//RELATEDPRODUCTS.innerHTML =RELATED_PROD;
	//PARURE.innertHTML =S_PARURE;
}

//load dynamic title for related products
//if ind==1 all ( related and parure )
//if ind==2 only related 
//if ind==3 only parure
function setTitleRelatedProducts(obj,ind)
{
	var nonFermarti = false;
	if(obj.getAttribute('titolo')) nonFermarti = true;
	
	
	if(!nonFermarti){
		var text_title="";
		if(ind==1){
			text_title ="<a id=\"RELATEDPRODUCTS\" class=\"lightboxCaption_select\" onclick=\"return false;\" href=\"#\">";
			text_title = text_title + RELATED_PROD + "</a> | <a id=\"PARURE\" class=\"lightboxCaption_default\" onclick=\"loadParure();\" href=\"#\">";
			text_title = text_title +  S_PARURE  + "</a>";
		}else if (ind==2){
			text_title= "<span class=\"lightboxCaption_select\">" + RELATED_PROD + "</span>";
		}else if(ind==3){
			text_title= "<span class=\"lightboxCaption_select\">" + S_PARURE + "</span>";
		}
		obj.setAttribute('titolo',text_title);
	}
}