var overDivObj = null;
var overDivLoaded = 0;

function rotateImageWLink(ImgLnk,element,timeout){
	document.getElementById(element["image"]).src=ImgLnk[0]["image"];
  	document.getElementById(element["link"]).href=ImgLnk[0]["link"];
	function changeImageWLink(){
		if (row > (ImgLnk.length-1)){
    		row=0;
   		}
		document.getElementById(element["image"]).src=ImgLnk[row]["image"];
  		document.getElementById(element["link"]).href=ImgLnk[row]["link"];    
    	row++;
	}
	var row=0;
    setInterval(changeImageWLink,timeout);
}




function displayHidden(id){
	
	current = (document.getElementById(id).style.display == 'block') ? 'none' : 'block';
	document.getElementById(id).style.display = current;
	return false;

}
var winW = 0, winH = 0;
function overlibStart()
	{
	overDivObj = document.getElementById('overDiv');
	overDivLoaded = 0;
	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
	  winW = window.innerWidth;
	  winH = window.innerHeight;
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	  winW = document.documentElement.offsetWidth;
	  winH = document.documentElement.offsetHeight;
	 }
	}
	return false;
	
	}

function getCoords(e, objW, objH)
{
	var posx = 0;
	var posy = 0;
	var relx = 0;
	var rely = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		relx = e.pageX - document.documentElement.scrollLeft;
		rely = e.pageY - document.documentElement.scrollTop;
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.documentElement.scrollLeft;
		posy = e.clientY + document.documentElement.scrollTop;
		relx = e.clientX;
		rely = e.clientY;
	}
	//dbg = document.getElementById('debugBox');
	//if(dbg)
	//	{
	//	dbg.innerHTML = 'posizioni Relative X:'+relx+' Y:'+rely+'<br />';
	//	dbg.innerHTML += 'posizioni Assolute X:'+posx+' Y:'+posy+'<br />';
	//	}
	if((relx + objW) >=  winW)
			posx = posx - objW;
	if((rely + objH) >=  winH)
			posy = posy - objH;

	return new Array(posx,posy);
}
function overlib(event,message)
	{
    if(overDivObj)
		{
		var divId = null;
		var IE = (document.all?true:false);
		var width = document.documentElement.clientWidth;
		var height = document.documentElement.clientHeight;
		var alignBottom = false;
		var alignRight = false;
	

		
		if(!event)
	                event = window.event;
	    if(event.target)
	            divId = event.target.id;
	    else
	            divId = event.srcElement.id;
            
		overDivCont = document.getElementById(divId+'_overDiv');
		var coords = getCoords(event, overDivCont.width, 250);
		if(overDivCont.className != '')
			{
			overDivObj.style.width = overDivCont.style.width;
			overDivObj.className = overDivCont.className;
			}
		overDivObj.innerHTML = overDivCont.innerHTML;
	//	alert(coords[1]+" "+overDivCont.height);
		overDivObj.style.left = (coords[0] + 3)+"px";
		overDivObj.style.top = (coords[1] + 3)+"px";
		overDivObj.style.display = 'block';
		
			if(arguments.length>1){
				divMessage=document.createElement('div');
				divMessage.className='photoDida';
				divMessage.innerHTML = message;
				divMessage.style.width='300px';
				divMessage.style.fontSize='9px';
				overDivObj.appendChild(divMessage);
			}
		}
	return false;
	}

function nd()
	{
	overDivObj = document.getElementById('overDiv');
	overDivObj.style.display= 'none';
	overDivObj.style.left = null;
	overDivObj.style.right = null;
	overDivObj.style.top = null;
	overDivObj.style.bottom = null;
	overDivLoaded = 0;
	}
function rotateGallery()
	{
	var galBox = document.getElementById('galleryRotation');
	//
	if(galBox)
		{
		galBox.childNodes[galleryCounter].style.display = 'none';
		if(galleryCounter == (galBox.childNodes.length - 1))
			galleryCounter = 0;
		else
			galleryCounter++;
		galBox.childNodes[galleryCounter].style.display = 'block';
		setTimeout(rotateGallery,3000);
		}
	}
function rotateGalleryNew(idGallery,where,NrElements,rand){
        var req;

        function rotate(){
		if (window.XMLHttpRequest){
  			req=new XMLHttpRequest()
  		}else if (window.ActiveXObject){
			  req=new ActiveXObject("Microsoft.XMLHTTP")
  		}

	        req.onreadystatechange = function() {setUrl();};
        	req.open('GET', 'rpcInline.php?action=getRandGallRPC&id='+idGallery+'&where='+where+'&nrElems='+NrElements+'&randGall='+rand,true);
		req.send('');
        }
        function setUrl(){
		var url;
		if (req.readyState == 4) { 
			if (req.status == 200) { 
			   url = req.responseText;
			   var galbox = document.getElementById('gallery');
			   if(galbox)
                           	galbox.src=url;
			}
		}
        }

	rotate();
}

function rotateShop()
	{
	shopBox = document.getElementById('shopRotation');

	//
	if(shopBox)
		{
		shopBox.childNodes[shopCounter].style.display = 'none';
			if(shopCounter == (shopBox.childNodes.length - 1))
				shopCounter = 0;
			else
				shopCounter++;
		shopBox.childNodes[shopCounter].style.display = 'block';
		setTimeout(rotateShop,3000);
		}
	}
function popup_window(action,objId)
	{
	window.open('popupBz.php?action='+action+'&id='+objId,'popup','width=10,height=10,toolbar=no,status=no,scrollbars=no,location=no');
	return false;	
	}
	
function putInCart(objId,qty)
	{
	rpcObj = document.getElementById('sysrpc');
	rpcObj.src = "rpc.php?action=addProduct&articleId="+objId+"&qty="+qty;
	return false;
	}
function emptyCart()
	{
	rpcObj = document.getElementById('sysrpc');
	rpcObj.src = "rpc.php?action=emptyCart";
	return false;
	}
function incProductRPC(objId)
	{
	rpcObj = document.getElementById('sysrpc');
	rpcObj.src = "rpc.php?action=addProduct&articleId="+objId+"&qty=1";
	return false;
	}
function decProductRPC(objId)
	{
	rpcObj = document.getElementById('sysrpc');
	rpcObj.src = "rpc.php?action=removeProduct&articleId="+objId+"&qty=1";
	return false;
	}
function delProductRPC(objId)
	{
	rpcObj = document.getElementById('sysrpc');
	rpcObj.src = "rpc.php?action=removeProduct&articleId="+objId;
	return false;
	}
function incProduct(objId)
	{
	return false;
	}
function decProduct(objId)
	{
	return false;
	}
function delProduct(objId)
	{

	return false;
	}
