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_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a)&&x.oSrc;i++)
	x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a))!=null){document.MM_sr=x; if(!x.oSrc) x.oSrc=x.src;
	x.src=a;}
}
function MM_showHideLayers() { //v6.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; }
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

/* show/hide multiple objects */
//	UB_showHideObject('OBJ1_ID','on','OBJ2_ID','off')
function UB_showHideObject(){var i,args=UB_showHideObject.arguments;for(i=0;i<(args.length-1);i+=2){(args[i+1]=='off')?$('#'+args[i]).hide():$('#'+args[i]).show();}}

/* multiple object set/add/remove class */
//	UB_changeClass('OBJ1_ID','newClass1','OBJ2_ID','newClass2')
function UB_changeClass(){var i,args=UB_changeClass.arguments;for(i=0;i<(args.length-1);i+=2){$('#'+args[i]).attr('class',args[i+1]);}}
function UB_addClass(){var i,args=UB_addClass.arguments;for(i=0;i<(args.length-1);i+=2){$('#'+args[i]).addClass(args[i+1]);}}
function UB_removeClass(){var i,args=UB_removeClass.arguments;for(i=0;i<(args.length-1);i+=2){$('#'+args[i]).removeClass(args[i+1]);}}

/* generic popup */
function UB_genPop(myUrl,myWinName,myWidth,myHeight,myPars){var winLeft=(screen.availWidth-myWidth)/2;var winTop=(screen.availHeight-myHeight)/2;var winParameters=myPars+'';if(winParameters==''){winParameters=',toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no';};newWin=window.open(myUrl,myWinName,'width='+ myWidth +',height='+ myHeight +',left='+ winLeft +',top='+ winTop + winParameters);newWin.focus();}

/* cookie functions */
function createCookie(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires=';expires='+date.toGMTString();}else{var expires='';};document.cookie=name+'='+value+expires+'; path=/';}
function readCookie(name){var nameEQ=name+'=';var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);};return null;}
function eraseCookie(name){createCookie(name,"",-1);}

/* init function */
function UB_init(){for(var i=0;i<document.links.length;i++){a=document.links[i];if(a.href&&a.rel){if(a.rel.substring(0,2)=='UB|'){a.onclick=function(){UB_relPop(this);return false;}}}}}
function UB_onResize(){if($('#UB_popOverlayer')){UB_setScreenSize();$('#UB_overlayer').css({height:function(){return $(window).height();}});UB_ObjCenter($('#UB_popOverlayer'));}}

/* detect browser available dimensions */
var windowWidth,windowHeight;
function UB_setScreenSize(){if(self.innerHeight){windowWidth=self.innerWidth;windowHeight=self.innerHeight}else if(document.documentElement&&document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight}else if(document.body&&document.body.clientWidth){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight}}

/* center obj at screen */
function UB_ObjCenter(myObj){$(myObj).css({left:function(){return parseInt(($(window).width()-$(myObj).width())/2);},top:function(){if($(window).height()>$(myObj).height()){return parseInt(($(window).height()-$(myObj).height())/2)}else{return 0}}})}

/* overlayer fade functions */
function UB_fadein(myFadeIn,myWidthIn,myHeightIn,myPopContentIn){jQuery('#UB_overlayer').fadeTo(456,myFadeIn/10,function(){jQuery('#UB_popOverlayer').animate({width:myWidthIn,height:myHeightIn,top:(windowHeight-myHeightIn)/2,left:(windowWidth-myWidthIn)/2},123,function(){$("#popContent").html(myPopContentIn)})})}
function UB_fadeout(){$('#popContent').remove();$('#UB_popOverlayer').animate({width:0,height:0,top:windowHeight/2,left:windowWidth/2},456,function(){jQuery(this).remove();jQuery('#UB_overlayer').fadeOut(789,function(){jQuery(this).remove()})})}

/* close pop overlayer */
function UB_closePopOverlayer(){UB_fadeout()}

/*	simple parametric iframed lightbox */
/*	script v6.4P del 28/11/2011 by Borredon Umberto, NURUN Italia S.r.l. */
//	parametri funzione apertura lightbox - tutti obbligatori - nell'ordine:
//	UB_relPop(link,width,height,bgcolorOverlayer,opacityOverlayer,stripTitleClose,customClass,contentType);
//	rel="UB|width|height|bgcolorOverlayer|opacityOverlayer|stripTitleClose|customClass|contentType"
//	width				= larghezza finestra (espressa in pixel, ma senza unita' di misura es: 640);
//	height				= altezza finestra (espressa in pixel, ma senza unita' di misura es: 480);
//	bgcolorOverlayer	= colore di sfondo del div overlayer [stessa sintassi css, es: #FEB0C3; ammessa la forma compatta es: #000;]
//	opacityOverlayer	= opacita' del div overlayer [0-10] - 0=trasparente / 10=opaco;
//	stripTitleClose		= strip col pulsante di chiusura della pop [true|false];
//	customClass			= eventuale classe 'custom' per la personalizzazione della lightbox;
//	contentType			= tipologia di contenuto [D|I|F|M|P] - D=id del contenuto in pagina es:#insertedContent / I=iframe / F=flash / M=movie / P=picture
//	per chiudere la popup da dentro l'iframe (purche' la pagina richiamata si trovi nello stesso dominio della chiamante!) bisogna invocare la seguente funzione: parent.UB_closePopOverlayer();
//	e' anche possibile chiudere la lightbox cliccando dirattamente sull'overlayer esterno
var UB_overlayer,UB_popOverlayer;
function UB_relPop(myLink,myWidth,myHeight,myBgcolor,myFade,myHeader,myCustomClass,myContentType){if(myLink.rel){prmtrs=myLink.rel.split('|');myWidth=parseInt(prmtrs[1]);myHeight=parseInt(prmtrs[2]);myBgcolor=prmtrs[3];myFade=parseInt(prmtrs[4]);myHeader=(prmtrs[5]==='true')?true:false;myCustomClass=prmtrs[6];myContentType=prmtrs[7]};myTitle=(!!myLink.title)?myLink.title:'';myLink=(myLink.href)?$(myLink).attr('href'):myLink;if(myCustomClass==undefined||myCustomClass=='undefined')myCustomClass='';stripClose=(myHeader)?'<div class="popButChiudi"><h2>'+myTitle+'<\/h2><a href="#" title="CLOSE">X<\/a><\/div>':'';UB_setScreenSize();UB_overlayer=$('<div id="UB_overlayer" class="UB_overlayerClass" style="width:'+windowWidth+'px;height:'+windowHeight+'px;background:'+myBgcolor+'"><\/div>').click(function(){UB_closePopOverlayer()});myClassName=(myCustomClass)?'UB_popOverlayerClass '+myCustomClass:'UB_popOverlayerClass';UB_popOverlayer=$('<div id="UB_popOverlayer" class="'+myClassName+'"><\/div>').html(stripClose+'<div id="popContent" class="popContent" style="width:'+myWidth+'px;height:'+myHeight+'px;"><\/div>');var myPopContentMarkup;switch(myContentType){case 'D':myPopContentMarkup=$(myLink).html();break;case 'I':myPopContentMarkup='<iframe src="'+myLink+'" style="width:'+myWidth+'px;height:'+myHeight+'px;" class="UB_frame" name="UB_frame" id="UB_frame" frameborder="0" marginwidth="0" marginheight="0" scrolling="auto" allowtransparency="true"><\/iframe>';break;case 'F':myPopContentMarkup='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+myWidth+'" height="'+myHeight+'"><param name="menu" value="false" \/><param name="scale" value="noScale" \/><param name="wmode" value="transparent" \/><param name="allowScriptAccess" value="always" \/><param name="allowFullScreen" value="true" \/><param name="movie" value="'+myLink+'" \/><!--[if !IE]>--><object type="application\/x-shockwave-flash" data="'+myLink+'" width="'+myWidth+'" height="'+myHeight+'"><param name="menu" value="false" \/><param name="scale" value="noScale" \/><param name="wmode" value="transparent" \/><param name="allowScriptAccess" value="always" \/><param name="allowFullScreen" value="true" \/><param name="movie" value="'+myLink+'" \/><!--<![endif]--><p><br \/><br \/><a href="http:\/\/get.adobe.com\/flashplayer\/" title="GET ADOBE FLASH PLAYER" target="_blank" class="btn-getFP">GET ADOBE FLASH PLAYER<\/a><\/p><!--[if !IE]>--><\/object><!--<![endif]--><\/object>';break;case 'M':myPopContentMarkup=(iPad||iPhn||iPod)?'':'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+myWidth+'" height="'+myHeight+'"><param name="menu" value="false" \/><param name="scale" value="noScale" \/><param name="wmode" value="transparent" \/><param name="allowScriptAccess" value="always" \/><param name="allowFullScreen" value="true" \/><param name="play" value="true" \/><param name="movie" value="\/common\/swf\/player-video.swf?video='+myLink+'&autoPlay=true" \/><!--[if !IE]>--><object type="application\/x-shockwave-flash" data="\/common\/swf\/player-video.swf?video='+myLink+'&autoPlay=true" width="'+myWidth+'" height="'+myHeight+'"><param name="menu" value="false" \/><param name="scale" value="noScale" \/><param name="wmode" value="transparent" \/><param name="allowScriptAccess" value="always" \/><param name="allowFullScreen" value="true" \/><param name="play" value="true" \/><param name="movie" value="\/common\/swf\/player-video.swf?video='+myLink+'&autoPlay=true" \/><!--<![endif]--><p><br \/><br \/><a href="http:\/\/get.adobe.com\/flashplayer\/" title="GET ADOBE FLASH PLAYER" target="_blank" class="btn-getFP">GET ADOBE FLASH PLAYER<\/a><\/p><!--[if !IE]>--><\/object><!--<![endif]--><\/object>';break;case 'P':myPopContentMarkup='<img src="'+myLink+'" width="'+myWidth+'" height="'+myHeight+'" alt="'+myTitle+'" title="'+myTitle+'" \/>';break};if(myPopContentMarkup==''){top.location.href=myLink;return};$('body').append(UB_overlayer,UB_popOverlayer);UB_ObjCenter(UB_popOverlayer);var headerTotHeight;if(myHeader){headerHeight=$("#UB_popOverlayer .popButChiudi").height();headerPaddingTop=$("#UB_popOverlayer .popButChiudi").css('paddingTop');headerPaddingBottom=$("#UB_popOverlayer .popButChiudi").css('paddingBottom');headerTotHeight=parseInt(headerHeight)+parseInt(headerPaddingTop.replace('px',''))+parseInt(headerPaddingBottom.replace('px',''))}UB_fadein(myFade,myWidth,(myHeader)?myHeight+headerTotHeight:myHeight,myPopContentMarkup)}
$("#UB_popOverlayer .popButChiudi a").live('click',function(){UB_closePopOverlayer();return false});

/* implementazione player HD */
function handleClick_HD(identifier){
	alert(identifier);	
}

var activeObj='1';
function UB_swapObj(myObj){if(activeObj){$('#submenu_box_'+activeObj).slideUp('medium');UB_changeClass('submenu_titolo_'+activeObj,'');if(myObj==activeObj){activeObj='';return;}};$('#submenu_box_'+myObj).slideDown('fast');UB_changeClass('submenu_titolo_'+myObj,'active');activeObj=myObj;}

/* event functions */
window.onload=function(e){
	UB_init();
	/* read cookie style-switcher - da usare SOLO con UB-style-switcher.js */
//	var cookie=readCookie('style');var cookie2= readCookie('styleContrast');blContrast=(cookie2=='true')?true:false;title=cookie?cookie:getPreferredStyleSheet();(title=='null'||title==null)?setActiveStyleSheet('small-font'):setActiveStyleSheet(title);
	if($('body').hasClass('fadeIn'))$('body').fadeIn('slow');
}
window.onunload=function(e){
	/* write cookie style-switcher - da usare SOLO con UB-style-switcher.js */
//	title=getActiveStyleSheet();createCookie('style',title,1);createCookie('styleContrast',blContrast,1);
}
window.onresize=function(e){UB_onResize();}
