// v1.7
function Right(str, n){
	if (n <= 0)
	   return "";
	else if (n > String(str).length)
	   return str;
	else {
	   var iLen = String(str).length;
	   return String(str).substring(iLen, iLen - n);
	}
}  
 
function eventRollHover(id){
	var sfEls = $(id).getElementsByTagName("IMG");
	for (var i=0; i<sfEls.length; i++) {		
		sfEls[i].onmouseover=function() {
			if (this.className == 'rollhover'){
				if (id == 'menu') changeImg(this,'over');
				if (id == 'clienti') {					
					//obj = this;
					obj = this.id;
					change(this.id,"over");
					/*$('details').set('text', ''); //RESET 
					//NOW NO AJAX TOO SLOW
					clientetoload = parseInt(this.parentNode.id.replace("cliente",""));
					var req = new Request.HTML({
						method: 'get',
						url: 'cliente.cfm?cid='+clientetoload,
						evalScripts : true,
						onSuccess: function(html) {	
							$('details').set('text', '');
							$('details').adopt(html);
						},
						onComplete: function(html) {
							$('box_overlayer').style.display='block';
						}
					}).send();*/
					moltiplicatori = Right(this.parentNode.className, 3);
					moltiplicatorex = parseInt(Right(this.parentNode.className, 1));
					moltiplicatorey = parseInt(moltiplicatori.substring(0,1));
					//$('box_overlayer').style.display='block'; //OLD
					totop = parseInt(this.parentNode.scrollHeight)-30+((moltiplicatorey-1)*120);
					if (moltiplicatorex < 4) {							
						toleft = parseInt(this.parentNode.scrollWidth)*moltiplicatorex-79;	
						$('angolo'+this.id).style.left='14px';
						$('angolo'+this.id).src='images/struttura/angolo2.gif';
						$('angolo'+this.id).style.display='block';
					}else{
						toleft = parseInt(this.parentNode.scrollWidth)*moltiplicatorex-319;
						$('angolo'+this.id).style.left='178px';
						$('angolo'+this.id).src='images/struttura/angolo.gif';
						$('angolo'+this.id).style.display='block';
					}
					$('box_overlayer'+this.id).style.top=totop+'px';
					$('box_overlayer'+this.id).style.left=toleft+'px';
					
					$('angolo'+this.id).style.display='block';
					$('box_overlayer'+this.id).style.display='block';
				}
			}
		}
		sfEls[i].onmouseout=function() {
			if (this.className == 'rollhover'){
				if (id == 'menu') changeImg(this,'out');
				if (id == 'clienti') {
					change(this.id,"out");
					$('box_overlayer'+this.id).style.display='none';
				}
			}
		}
	}
}

function change(id,action){
	if (action == "over") {
		$(id).src=$(id+"_a").src;
	}else{
		$(id).src=$(id+"_b").src;
	}
}
	
function changeImg(obj,action){
	if (action == "over") {
		if (Right(obj.src,6)!="_a.gif") obj.src=obj.src.replace(".gif","_a.gif");	
	}else{
		if (Right(obj.src,6)=="_a.gif") obj.src=obj.src.replace("_a.gif",".gif");  
	}
} 

function eventRollHoverOverlayer(id){
	$(id).onmouseover=function() {
		this.style.display='block';
		//changeImg(obj,'over');
		change(obj,"over");
	}
	$(id).onmouseout=function() {
		this.style.display='none';
		//changeImg(obj,'out');
		change(obj,"out");
	}
}

function eventRollHoverOverlayerNew(id){
	var sfEls = $(id).getElementsByTagName("DIV");
	for (var i=0; i<sfEls.length; i++) {		
		sfEls[i].onmouseover=function() {
			if (this.className == 'box_overlayer'){
				this.style.display='block';
				change(this.id.substring(13),"over");
			}
		}
		sfEls[i].onmouseout=function() {
			if (this.className == 'box_overlayer'){
				this.style.display='none';
				change(this.id.substring(13),"out");
			}
		}
	}
}

window.addEvent('domready', function() {	
	eventRollHover('menu');
});

function viewtipologia(id){
	if (id == '1') URL = 'comunicazione.cfm';
	if (id == '2') URL = 'eventi.cfm';
	if ((id == '1') || (id == '2')) {
	var req = new Request.HTML({
		method: 'get',
		url: URL,
		evalScripts : true,
		onSuccess: function(html) {
			$('viewtipologia').set('text', '');
			$('viewtipologia').adopt(html);
		},
		onComplete: function(html) {
			$('pertipologia').style.display='none';
			$('viewtipologia').style.display='block';
		}
	}).send();
	}else{
		$('pertipologia').style.display='block';
		$('viewtipologia').style.display='none';
	}
}

function video(URL){
	/*
	//JW Media Player settings and options
	playerpath= 'NonverBlaster.swf';	// player.swf Path to the mediaplayer.swf or flvplayer.swf file
	backcolor=  '000000';		// Base color for the controller, color name / hex value (0x000000)
	frontcolor= '999999';		// Text and button color for the controller, color name / hex value (0x000000)
	lightcolor= '000000';		// Rollover color for the controller, color name / hex value (0x000000)
	screencolor= '000000';		// Rollover color for the controller, color name / hex value (0x000000)
	controlbar= 'over';			// bottom, over, none (this setting is ignored when playing audio files)
	autoplay= 'true';
	bgcolor= '#000000';
	scriptaccess= 'true';
	fullscreen= 'true';
	
	preload = new Swiff(''+playerpath+'?file='+URL+'&backcolor='+backcolor+'&frontcolor='+frontcolor+'&lightcolor='+lightcolor+'&screencolor='+screencolor+'&autostart='+autoplay+'&controlbar='+controlbar, {
		id: 'photogallery',
		width: '630',
		height: '270',
		params: {wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
		});
	}
	*/
	var obj = new Swiff('player.swf?file=../'+URL, {
		id: 'photogallery',
		width: 500,
		height: 400,
		params: {
			wmode: 'opaque',
			bgcolor: '#ff3300'
		}
	});

}

function getCookie(c_name){
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++){
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name) {
			return unescape(y);
		}
	}
}

function setCookie(c_name,value,exdays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}
