	var GLOBAL_video_ID = '5dPW-h6xKBY';
	var GLOBAL_video_title = 'La centrale di cogenerazione di Imola';
	var GLOBAL_video_timer = null;
	var GLOBAL_video_close = 'chiudi il video';
	var GLOBAL_video_skip = 'vai alla notizia &raquo;';
	var GLOBAL_wid = 425;
	var GLOBAL_hei = 310;
	var GLOBAL_redirect_url = 'http://www.gruppohera.it/gruppo/attivita_servizi/business_energia/impianti/pagina14.html?utm_source=landing_video&utm_medium=banner&utm_campaign=coge_centrale_imola';
	var GLOBAL_redirect_enabled = true;
	ytplayer = null;
	function jqvp_redirect2page() {
		jQuery('body').css({cursor:'wait'});
		location.href = GLOBAL_redirect_url;
	}
	function jqvp_closePop() {
		jQuery('.jq_back,.jq_front').remove();
	}
	function onYouTubePlayerReady(playerId) {
		ytplayer = document.getElementById("myytplayer");
		ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
		loadNewVideo(GLOBAL_video_ID,0);
	}
	function onytplayerStateChange(newState) {
		//alert("Player's new state: " + newState);
		if (newState == 1) {			
			play();
			var duration = getDuration();
			if (duration>0) {
				GLOBAL_video_timer = setTimeout(function(){
					if (GLOBAL_redirect_enabled) {
						jqvp_redirect2page();
					}
					else {
						jqvp_closePop();
					}
				}, duration*1000);
			}
		}
	}
	function loadNewVideo(id, startSeconds) {
		if (ytplayer) {
			ytplayer.loadVideoById(id, parseInt(startSeconds));
		}
	}
	function play() {
		if (ytplayer) {
			ytplayer.playVideo();
		}
	}
	function getDuration() {
		if (ytplayer) {
			return ytplayer.getDuration();
		}
	}
	function getPlayerState() {
		if (ytplayer) {
			return ytplayer.getPlayerState();
		}
	}


	jQuery.noConflict();
	jQuery(document).ready(function(){
		if (jQuery('.jq_internal').length > 0) {
			GLOBAL_redirect_enabled = false;
			GLOBAL_video_skip = '';
		}
		jQuery('.jq_open_video').click(function(){
			if (jQuery('.jq_back').length==0) {	
				jQuery('#banneranimato').fadeOut(500);
				jQuery('body').append('<div class="jq_back" style="display:none;z-index:9999998;position:absolute;top:0px;left:0px;width:100%;height:100%;background:black;opacity:0.5;filter:alpha(opacity=50);"></div>');
				jQuery('body').append('<div class="jq_front" style="display:none;z-index:9999999;position:absolute;top:0px;left:0px;width:100%;height:100%;"><table width="100%" height="100%">'
					
					+'<tr><td align="center">'
					+'<table width="'+(GLOBAL_wid+10)+'" height="'+(GLOBAL_hei+34)+'" border="0" cellpadding="0" cellspacing="0">'
					+'<tr style="height:5px;">'
					+'<td style="width:5px;height:5px;overflow:hidden;" class="video_angolo1"></td>'
					+'<td style="height:5px; background:white;overflow:hidden;"></td>'
					+'<td style="width:5px;height:5px;overflow:hidden;" class="video_angolo2"></td></tr>'
					
					+'<tr><td style="width:5px; background:white;overflow:hidden;"></td>'
					+'<td class="jqwin" style="vertical-align:middle; background:white;" align="center"></td>'
					+'<td style="width:5px; background:white;overflow:hidden;"></td></tr>'
					
					+'<tr style="height:5px;">'
					+'<td style="width:5px;height:5px;overflow:hidden;" class="video_angolo3"></td>'
					+'<td style="height:5px; background:white;overflow:hidden;"></td>'
					+'<td style="width:5px;height:5px;overflow:hidden;" class="video_angolo4"></td></tr>'
					+'</table>'
					+'</td></tr>'
					
					+'</table></div>');

				jQuery('.jq_back').css({height:jQuery(document).height()});
				if ( ! GLOBAL_redirect_enabled) {
					jQuery('.jq_front').css({top:jQuery(window).scrollTop()+'px'});
					if (jQuery.browser.msie) {
						if (jQuery.browser.version == '6.0') {
							var dhei = Math.round((jQuery(document).height()-0)/2);
							var wscr = jQuery(window).scrollTop()-0;
							//alert(dhei+"\n"+wscr);
							jQuery('.jq_front').css({top:(340+wscr-dhei)+'px'});
						}
					}
				}
				var jqwin = jQuery('.jqwin');
				jqwin.html(	'<div style="width:'+GLOBAL_wid+'px; height:12px; background:white; text-align:right; padding:0;margin:0;border:0;"><img class="jqclose" src="/hr_adm/img/x.gif" style="padding:0;margin:0;border:0;width:48px;height:12px;float:right;display:block;" title="'+GLOBAL_video_close+'"/></div>'
							+'<div style="width:'+GLOBAL_wid+'px; height:'+GLOBAL_hei+'px; background:black;" id="ytapiplayer">'								
							//+'Sono richiesti Flash player 8+ e JavaScript abilitato per vedere il video.'
							+''
							+'</div>'
							+'<div style="width:'+GLOBAL_wid+'px; height:12px; background:white; text-align:right; line-height:15px; padding:0;margin:0;border:0;"><div style="padding-left:10px;">'
							+'<a href="'+GLOBAL_redirect_url+'" onclick="clearTimeout(GLOBAL_video_timer)" style="color:#454545;font-size:12px;text-decoration:none; font-variant:small-caps;">'
							//+GLOBAL_video_title
							+GLOBAL_video_skip
							+'</a>'
							+'</div></div>');
				jQuery('.jqclose').css({cursor:'pointer'}).click(function(){
					if (GLOBAL_redirect_enabled) {
						clearTimeout(GLOBAL_video_timer);
						jqvp_redirect2page();
					}
					else {
						jqvp_closePop();
					}
				});
/*				
				jQuery(window).bind('resize',function(){
					var divs = jQuery('.jq_back,.jq_front');
					divs.css({
						width:jQuery(document).width()+'px',
						height:jQuery(document).height()+'px'
					});
				});
*/
/*
				jQuery(window).bind('scroll',function(){
					var scrollTop = jQuery(document).scrollTop();
					var scrollLeft = jQuery(document).scrollLeft()
					jQuery('.jq_back,.jq_front').hide();
					jQuery('.jq_back,.jq_front').css({
						top:	scrollTop+'px',
						left:	scrollLeft+'px'
					});
					jQuery('.jq_back,.jq_front').show();
				});
*/
				jQuery('.jq_back').fadeIn({
					duration:	250,
					complete:	function(){
									var params = { allowScriptAccess: "always", bgcolor: '#FFFFFF' };
									var atts = { id: "myytplayer" };
									swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer", 
														"ytapiplayer", GLOBAL_wid, GLOBAL_hei, "8", null, null, params, atts);
									jQuery('.jq_front').fadeIn({
										duration:	250
									});
								}
				});
			}
			if (GLOBAL_redirect_enabled) {
				urchinTracker ('/video/banner_landing_page/coge_centrale_imola');				
			}
			else {
				urchinTracker ('/video/banner_news_page/coge_centrale_imola');
			}
			return false;					
		});
	});
