/* dropdown menu (richiede JQUERY & Superfish) ================================================== */

$(document).ready(function(){
	$("#nav ul").superfish({
		hoverClass	: "sfHover",
		delay		: 400,
		animation	: {height:"show"},
		speed		: "fast"
		}); 
});

/* descrizioni homepage ========================================================================= 

$(document).ready(function(){
	$("#menuHome li a.icoGraph").mouseover(function(){
		var linkText1 = $(this).text();
			$("#description").text(linkText1);
		});
	$("#menuHome li a.icoTxt").mouseover(function(){
		var linkText1 = $(this).text();
			$("#description").text(linkText1);
		});
	$("#menuHome li a.icoTwo").mouseover(function(){
		var linkText1 = $(this).text();
			$("#description").text(linkText1);
		});
	$("#menuHome li a.icoPerc").mouseover(function(){
		var linkText1 = $(this).text();
			$("#description").text(linkText1);
		});
	$("#menuHome li a").mouseout(function(){
		$("#description").text("");
		});
});*/

/* bgiframe per ie6 */

$(document).ready(function(){
	$('#nav ul').bgiframe();
});

/* popup accessibile by SF 2007 - arscolor.com ========================================= */

/* popup accessibile ======================================================= 
 *
 * pop up di dimensione 431x450: applicare al link la classe "popWindow";
 *
 * pop up di altezza e larghezza desiderate: applicare al link la classe "popParamWindow" e utilizzare nell'url
 * i parametri height=xyz&width=xyz
 * esempio: pagina.aspx?height=390&width=412
 */

// funzione per aprire la finestra specificando altezza e larghezza 
function popUp(destination,param){
var poppedUp = window.open(destination, "popWin", param);
//poppedUp.focus();
}

// esegue la funzione principale solo quando il DOM è completo
window.onload = prepareLinks;

// funzione principale che chiama la funzione popup
function prepareLinks(){
	var links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++){
		if (links[i].className == "popWindow"){
			links[i].onclick = function (){
				popUp(this.getAttribute("href"),"height=390, width=390, scrollbars=0");
				return false;}
		}
		
		if (links[i].className == "popParamWindow"){
			links[i].onclick = function (){
				var p = (this.getAttribute("href").substr(this.getAttribute("href").indexOf('height'))).split('&');
				var param = p[0]+', '+p[1]+', scrollbars=0';
				popUp(this.getAttribute("href"),param);
				return false;}
		}
	
	}
}

/* JSTarget function by Roger Johansson, www.456bereastreet.com ============================================================= */

var JSTarget = {
	init: function(att,val,warning) {
		if (document.getElementById && document.createElement && document.appendChild) {
			var strAtt = ((typeof att == 'undefined') || (att == null)) ? 'class' : att;
			var strVal = ((typeof val == 'undefined') || (val == null)) ? 'non-html' : val;
			var strWarning = ((typeof warning == 'undefined') || (warning == null)) ? ' (opens in a new window)' : warning;
			var oWarning;
			var arrLinks = document.getElementsByTagName('a');
			var oLink;
			var oRegExp = new RegExp("(^|\\s)" + strVal + "(\\s|$)");
			for (var i = 0; i < arrLinks.length; i++) {
				oLink = arrLinks[i];
				if ((strAtt == 'class') && (oRegExp.test(oLink.className)) || (oRegExp.test(oLink.getAttribute(strAtt)))) {
					oWarning = document.createElement("em");
					oWarning.appendChild(document.createTextNode(strWarning));
					oLink.appendChild(oWarning);
					oLink.onclick = JSTarget.openWin;
				}
			}
			oWarning = null;
		}
	},
	openWin: function(e) {
		var event = (!e) ? window.event : e;
		if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true;
		else {
		    var oWin = window.open(this.getAttribute('href'), '_blank');
			if (oWin) {
				if (oWin.focus) oWin.focus();
				return false;
			}
			oWin = null;
			return true;
		}
	},
	/*
	addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
	*/
	addEvent: function(obj, type, fn) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() {obj["e"+type+fn]( window.event );}
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	}
};
JSTarget.addEvent(window, 'load', function(){JSTarget.init("rel","external","");});


/*
PopImageExtra
*/

function popImageExtra(imageURL,imageTitle,AutoClose,oTimeClose,extraHTML){
	//really not important (the first two should be small for Opera's sake)
	//PositionX = 10;
	//PositionY = 10;
	defaultWidth  = 500;
	defaultHeight = 400;
	var imgWin = window.open('','_blank','scrollbars=no,resizable=1,width='+defaultWidth+',height='+defaultHeight);
	if( !imgWin ) { return true; } //popup blockers should not cause errors
	imgWin.document.write('<html><head><title>'+imageTitle+'<\/title><script type="text\/javascript">\n'+
		'function getRefToDivMod( divID, oDoc ) {\n'+
			'if( !oDoc ) { oDoc = document; }\n'+
			'if( document.layers ) {\n'+
			'if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {\n'+
			'for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {\n'+
			'y = getRefToDivNest(divID,oDoc.layers[x].document); }\n'+
			'return y; } }\n'+
			'if( document.getElementById ) { return oDoc.getElementById(divID); }\n'+
			'if( document.all ) { return oDoc.all[divID]; }\n'+
			'return document[divID];\n'+
		'}\n'+
		'function resizeWinTo() {\n'+
			'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }'+
			'if( !document.images[0].height || window.doneAlready ) { return; }\n'+ //in case images are disabled
			'var oH = getRefToDivMod( \'myID\' ); if( !oH ) { return false; }\n'+
			'var oW = oH.clip ? oH.clip.width : oH.offsetWidth;\n'+
			'var oH = oH.clip ? oH.clip.height : oH.offsetHeight; if( !oH ) { return false; }\n'+
			'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
			'window.doneAlready = true;\n'+ //for Safari and Opera
			'if(document.getElementsByTagName) {\n'+
				'for( var l = document.getElementsByTagName(\'a\'), x = 0; l[x]; x++ ) {\n'+
					'if(l[x].className==\'makeright\'&&!l[x].style.position){\n'+
						'l[x].style.position=\'relative\';\n'+
						'l[x].style.left=(document.images[0].width-(l[x].offsetWidth+l[x].offsetLeft))+\'px\';\n'+
			'}}}\n'+
			'var x = window; x.resizeTo( oW + 200, oH + 200 );\n'+
			'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n'+
			'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }\n'+
			'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
			'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
			'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
			'x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );\n'+
			'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
			'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
			(oTimeClose?('window.setTimeout(\'window.close()\','+oTimeClose+');\n'):'')+
		'}\n'+
		'<\/script>'+
		'<\/head><body onload="resizeWinTo();"'+(AutoClose?' onblur="self.close();"':'')+'>'+
		(document.layers?('<layer left="0" top="0" id="myID">'):('<div style="position:absolute;left:0px;top:0px;" id="myID">'))+
		'<img src="'+imageURL.replace(" ","%20")+'" alt="Loading image ..." title="" onload="resizeWinTo();">'+
		(extraHTML?extraHTML:'')+(document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
	imgWin.document.close();
	if( imgWin.focus ) { imgWin.focus(); }
	return false;
}