
/*******************************************
* FUNZIONI MACROMEDIA per show/hide layers *
********************************************/
function MM_findObj(n, d) { //v4.0
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3){
		if ((obj=MM_findObj(args[i]))!=null){
			v=args[i+2];
			if (obj.style) {obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v;}
			obj.visibility=v;
		}
	}
}

aimsDHTMLPresent=true;

// Prende in ingresso un url e restituisce un altro url in formato corretto per lo streaming
function createUrl(urlComplete) {
	var result = urlComplete.split("/");
	var file = '';
	for(i=0;i<result.length;i++) {
		if(i == (result.length-1)) file = result[i];
	}
	var index = urlComplete.indexOf(file);
	var url = urlComplete.substring(0,index-1);
	
	return url + '?file_name=' + file;
}

// Restituisce l'url per l'overview
function getOverviewUrl(streaming,completeUrl) {
	var url = '<img name="theImage" hspace="0" vspace="0" width="158" height="99" ';
	if(streaming == 'true') url += 'src=' + createUrl(completeUrl) + ' />';
	else url += 'src=' + completeUrl + ' />';
	return url;
}
		

function createLayer(name, inleft, intop, width, height, visible, content) {
	
	  var cheLayer;	  
	  
	  cheLayer = '<' + layerTag 
	  			+ ' id="' + name; 
	  
	  if(isNav4){
	  	cheLayer +=  '" left="' + inleft 
							+ '" top="' + intop 
							+ '" width="' + width 
							+ '" height="' + height 
							+ '" visibility="' + (visible ? 'visible' : 'hidden')
							+ '" bgcolor="' + layerBgColor
							+ '">';
	  } 
	  else{
	  	cheLayer +=   '" style="position:absolute;'
					+ 'overflow:hidden'
					+ ';left:' + inleft 
					+ 'px;top:' + intop 
					+ 'px;width:' + width 
					+ 'px;height:'+ height 
					+ 'px;z-index:1'
					+ ';visibility:' + (visible ?'visible':'hidden') 
					+ ';background:' + layerBgColor
					+ ';">';
	  }
	  
	  cheLayer += 	content + '</' + layerTag + '>';
	  //alert(cheLayer);
	  document.write(cheLayer);	  
	  
}

function getLayer(name) {

	var cheStyle = null;	
	if(isNav4){cheStyle = document.layers[name];}
	else if(isNav){cheStyle = document.getElementById(name).style;}
	else if(isIE){cheStyle = document.all[name].style;}	
	return cheStyle;
	
}
		
function isVisible(name) {
	  var cheLayer = getLayer(name);
	  if ((cheLayer.visibility == "show") || (cheLayer.visibility == "visible")){return true;}
	  else{return false;}
}

function moveLayer(name, x, y) {	
  	var cheLayer = getLayer(name);		
  	if (isNav4){
    	cheLayer.left = x;
   		cheLayer.top  = y;
	}
	else {
    	cheLayer.left = x + "px";
   		cheLayer.top  = y + "px";
  	}
}

function setLayerBackgroundColor(name, color) {
  	var cheLayer = getLayer(name);
 	if (isNav4){cheLayer.bgColor = color;}
	else{cheLayer.background = color;}
}

function hideLayer(name) {
  	var cheLayer = getLayer(name);		
  	if (isNav4){cheLayer.visibility = "hide";}
	else{cheLayer.visibility = "hidden";}
}

function showLayer(name) {
  	var cheLayer = getLayer(name);
  	if (isNav4){cheLayer.visibility = "show";}
	else{cheLayer.visibility = "visible";}
}

// ridisegna il layer in basse alle coordinate clipleft, cliptip, clipright, clipbottom
// Not working with Mozilla Milestone 12 (Nav5)
function clipLayer2(name, clipleft, cliptop, clipright, clipbottom) {		
	var cheLayer = getLayer(name);
	if (isNav4) {					
		cheLayer.clip.left   = clipleft;
		cheLayer.clip.top    = cliptop;
		cheLayer.clip.right  = clipright;
		cheLayer.clip.bottom = clipbottom;
	}
	else{
		cheLayer.top = parseInt(cheLayer.top.substring(0,cheLayer.top.indexOf("px"))) + cliptop;
		cheLayer.left = parseInt(cheLayer.left.substring(0,cheLayer.left.indexOf("px"))) + clipleft;
		cheLayer.width = clipright - clipleft;
		cheLayer.height = clipbottom - cliptop;
	}
	
}

function clipLayer(name, clipleft, cliptop, clipright, clipbottom) {
	var cheLayer = getLayer(name);
	if (isNav4) {
		cheLayer.clip.left   = clipleft;
		cheLayer.clip.top    = cliptop;					
		cheLayer.clip.right  = clipright;
		cheLayer.clip.bottom = clipbottom;
	}
	else{
		cheLayer.top = cliptop + "px";
		cheLayer.left = clipleft + "px";
		cheLayer.width = clipright - clipleft;
		cheLayer.height = clipbottom - cliptop;
	}
}

function boxIt(theLeft,theTop,theRight,theBottom) {
	
	clipLayer("zoomBoxTop",theLeft,theTop,theRight,theTop+ovBoxSize);
	clipLayer("zoomBoxLeft",theLeft,theTop,theLeft+ovBoxSize,theBottom);
	clipLayer("zoomBoxRight",theRight-ovBoxSize,theTop,theRight,theBottom);
	clipLayer("zoomBoxBottom",theLeft,theBottom-ovBoxSize,theRight,theBottom);
	
	showLayer("zoomBoxTop");
	showLayer("zoomBoxLeft");
	showLayer("zoomBoxRight");
	showLayer("zoomBoxBottom");
	
}

// verifica l'eistenza di un layer 
function hasLayer(name) {
	var result = false;
	if (isNav4) {
		if (document.layers[name]!=null) result=true;
	}  else if (isIE) {
		if (eval('document.all.' + name)!=null) result=true;
	} else if (isNav) {
		var theElements = document.getElementsByTagName("DIV");
		var theObj;
		var j = -1;
		for (i=0;i<theElements.length;i++) {
			if (theElements[i].id==name) result=true;
		}
    }
	return result;
}

