  window.EAS_DUMMY_AD = function(cu, url)	{
	  if (!url && !cu) return;
	  var el = window.top.document.createElement('iframe');
	  el.style.position = 'absolute';
	  el.style.bottom = '0px'; el.style.left = '0px';
	  el.style.width = '1px'; el.style.height = '1px';
	  el.style.border = "0px";
	  if (typeof el.allowTransparency != "undefined") el.allowTransparency='yes';
	  if (typeof el.frameBorder != "undefined") el.frameBorder='0';
	  if (typeof el.scrolling != "undefined") el.scrolling = 'no';
	  el.className = 'emediate_dummy video';
	  if (!url) url = 'http://eas8.emediate.eu/eas?cu='+cu+';cre=mu;from=video';
	  el.src = url.replace("<","").replace(">","");
	  el.onload = function() { window.top.document.body.removeChild(this); }
	  window.top.document.body.appendChild(el);
	}

function _ArturoVideo() {
  this.FULLSCREEN_EXPANDED = false;
  this.PERMALINK = null;

  this.loadVAST = function(vp, prerollUrl, postrollUrl) {
	var buster = ";"+Math.random();
	vp = $(vp).eq(0);
	if (prerollUrl) {
	  prerollUrl = prerollUrl.replace('http://eas8.emediate.eu/', '/arturo/vast/');
	  if (window.location.hostname && (window.location.hostname.indexOf('dev2.') != -1 || window.location.hostname.indexOf('dev.') != -1)) {
		prerollUrl += ";kw1=adpreview";
	  }
	  vp.attr("data-preroll-url", prerollUrl);
	  $.ajax({
		  type: "GET",
		  dataType: "xml",
		  //crossDomain: true,
		  url: prerollUrl,
		  error: function(jqXHR, textStatus, errorThrown) {
			  //alert("errore caricamento VAST preroll: "+errorThrown);
		  },
		  success: function(xml, textStatus, jqXHR){
			//vp.attr("data-preroll", jqXHR.responseText);
			vp.get(0).VASTPreroll = xml;
			var v = vp.find("video").get(0);
			if (v && v.autoplay) { v.pause(); v.play(); }
		  }
	  });
	}
	if (postrollUrl) {
	  postrollUrl = postrollUrl.replace('http://eas8.emediate.eu/', '/arturo/vast/');
	  if (window.location.hostname && (window.location.hostname.indexOf('dev2.') != -1 || window.location.hostname.indexOf('dev.') != -1)) {
		prerollUrl += ";kw1=adpreview";
	  }
	  vp.attr("data-postroll-url", postrollUrl);
	  $.ajax({
		  type: "GET",
		  dataType: "xml",
		  //crossDomain: true,
		  url: postrollUrl,
		  error: function(jqXHR, textStatus, errorThrown) {
			  //alert("errore caricamento VAST preroll: "+errorThrown);
		  },
		  success: function(xml, textStatus, jqXHR){
			vp.get(0).VASTPostroll = xml;
			//vp.attr("data-postroll", xml);
		  }
	  });
	}
  }

  this.VASTDone = function(vt, dontResetSource) {
	var v = $(vt);
	var vp = v.closest(".video_player");
	var running = v.attr("data-adv-running");
	if (!running) return;
	var iefix = vp.find(".IE9Preroll").get(0);
	if (iefix) {
	  iefix.autoplay = false;
	  iefix.muted = true;
	  iefix.pause();
	  iefix.src='';
	  $(iefix).remove();
	  v.css("display","block");
	}
	var done = v.attr("data-adv-done");
	done = (done) ? done+" "+running : running;
	v.attr("data-adv-done", done);
	vt.controls = true;
	vt.muted = false;
	v.removeAttr("data-adv-running");
	vp.find("a.VASTclick").css("display", "none");
	if (!dontResetSource) {
	  vt.src = '';
	  v.removeAttr("src");
	  vt.load();
	  vt.autoplay = true;
	}
	vp.find(".status_msg").css("display","none").html("");
	return true;
  }

  this.VASTPreroll = function(vt, play) {
	if (!vt) return;
	var vp = $(vt).closest(".video_player");
	var v = $(vt);
	var done = v.attr("data-adv-done") || "";
	if (!vp.get(0).VASTPreroll || v.attr("data-adv-running") || (done && done.indexOf("preroll") != -1)) return false;
	//var vast = $(vp.attr("data-preroll"));
	var vast = $(vp.get(0).VASTPreroll);

	var vfile = vast.find("MediaFile").eq(0).text();
	if (vfile.indexOf(".mp4") != -1) {
	  if (!vt.canPlayType('video/mp4; codecs="avc1.4D401F, mp4a.40.2').replace(/no/, '')) {
		vfile = vfile.replace(".mp4",".webm");
	  }
	}
	if (vfile.indexOf(".webm") != -1) {
	  if (!vt.canPlayType('video/webm; codecs="vp8, vorbis').replace(/no/, '')) {
		v.attr("data-adv-done", done + " preroll")
		return false;
	  }
	}
	if (!vfile) return false;
	vt.VASTLoading = true;
	vt.pause();
	vt.src = '';
	vt.autoplay = true;
	vt.controls = false;
	vt.muted = false;
	vt.preload = 'auto';
	v.attr({'data-adv-running': "preroll", 'src': vfile });
	vt.src = vfile;
	vt.load();
	var log_url = vast.find("Impression").eq(0).text();
	if (log_url) window.EAS_DUMMY_AD(null, log_url);
	var pixelCounter = vast.find("CustomClick").text() || vast.find("AdParameters").text();
	if (pixelCounter) window.EAS_DUMMY_AD(null, pixelCounter);
	var click_url = vast.find("ClickThrough").eq(0).text();
	if (click_url) vp.find(".VASTclick").css({"display": "block", "width": v.width(), "height": v.height(), 'z-index': 10000 }).attr("href", click_url);
	var duration = vast.find("Duration").eq(0);
	vp.find(".status_msg").css("display","block").html("&nbsp;Messaggio promozionale: il video partir&agrave; al termine dello spot...");

	// IE9 fix
	if ($.browser.msie) {
	  vt.muted = true;
	  vt.autoplay = false;
	  vt.src = '';
	  vt.pause();
	  v.removeAttr('src');
	  var el = document.createElement('video');
	  el.preload = 'auto';
	  el.src = vfile;
	  el.className = "IE9Preroll";
	  el.width = v.width();
	  el.height = v.height();
	  v.css("display","none");
	  v.before(el);
	  el.addEventListener('ended', function() { window.VideoPlayer.VASTDone(vt); });
	  el.addEventListener('waiting', function() { setTimeout(this.play, 500); });
	  el.play();
	  if (click_url) {
		el.addEventListener('click', function(e) { window.open(click_url); });
		el.style.cursor = "pointer";
	  }

	} else if (play) {
	  vt.play();
	}
	vp.find("div.title, .btn_play").fadeOut('fast');
	// marca la impression
	var impUrl = vast.find("Impression").eq(0).text().replace("http://eas8.emediate.eu/", "/arturo/vast/");
	if (impUrl) {
	  window.jQuery.get(impUrl.replace("::cre=log", ""));
	  window.jQuery.get(impUrl);
	}
	vt.VASTLoading = false;
	return vfile;
  }

  this.VASTPostroll = function(vt) {
	var vp = $(vt).closest(".video_player");
	var v = $(vt);
	var done = v.attr("data-adv-done") || "";
	if (!vp.get(0).VASTPostroll || v.attr("data-postroll-running") || (done && done.indexOf("preroll") != -1)) return false;
	//var vast = $(vp.attr("data-preroll"));
	var vast = $(vp.get(0).VASTPostroll);

	var vfile = vast.find("MediaFile").eq(0).html().replace('<!--[CDATA[','').replace(']]-->','');;
	if (vfile.indexOf(".mp4") != -1) {
	  if (!vt.canPlayType('video/mp4; codecs="avc1.4D401F, mp4a.40.2').replace(/no/, '')) {
		vfile = vfile.replace(".mp4",".webm");
	  }
	}
	if (vfile.indexOf(".webm") != -1) {
	  if (!vt.canPlayType('video/webm; codecs="vp8, vorbis').replace(/no/, '')) {
		v.attr("data-adv-done", done + " postroll")
		return false;
	  }
	}
	if (!vfile) return false;
	vt.pause();
	v.attr({'data-adv-running': "postroll", 'src': vfile });
	vt.src = vfile;
	vt.controls = false;
	vt.preload = 'auto';
	vt.load()
	var log_url = vast.find("Impression").eq(0).text();
	if (log_url) window.EAS_DUMMY_AD(null, log_url);
	var pixelCounter = vast.find("CustomClick").text() || vast.find("AdParameters").text();
	if (pixelCounter) window.EAS_DUMMY_AD(null, pixelCounter);
	var click_url = vast.find("ClickThrough").eq(0).text();
	if (click_url) vp.find("a.VASTclick").css("display","block").attr("href",click_url);
	vt.play();
	vp.find(".status_msg").css("display","block").html("&nbsp;Messaggio promozionale");
	vp.find("div.title, .btn_play").fadeOut('fast');
	// marca la impression
	var impUrl = vast.find("Impression").eq(0).text().replace("http://eas8.emediate.eu/", "/arturo/vast/");
	if (impUrl) {
	  window.jQuery.get(impUrl.replace("::cre=log", ""));
	  window.jQuery.get(impUrl);
	}
	vt.VASTLoading = false;

	return vfile;
  }

  this.initNielsen = function(videoPlayer) {
	var _nolggGlobalParams = { clientid: "edmaster-it", vcid: "b01", cisuffix: "", sfcode: "it", prod: "sc" };
	var uid = 0;
	var canUseSWF = false;
	if (window.gg) {
	  videoPlayer.NielsenVideo = new gg();
	  videoPlayer.NielsenVideo.ggInitialize(_nolggGlobalParams, uid, canUseSWF);
	  return;
	}
	var js = window.document.createElement('script');
	js.src = "http://secure-it.imrworldwide.com/novms/js/2/ggcmb370.js";
	js.async = true;
	js.onload = js.onreadystatechange = function(_, isAbort) {
		if (!js.readyState || /loaded|complete/.test(js.readyState)) {
			// Handle memory leak in IE
			js.onload = js.onreadystatechange = null;
			// Remove the script
			if (js.parentNode) { js.parentNode.removeChild(js); }
			js = undefined;
			if (isAbort) { return; }
			// init di nielsen
			videoPlayer.NielsenVideo = new gg();
			videoPlayer.NielsenVideo.ggInitialize(_nolggGlobalParams, uid, canUseSWF);
		}
	};
	var s = document.getElementsByTagName('script')[0];
	s.parentNode.insertBefore(js, s);
  }

  this.flashFallback = function(el, prerollUrl, postrollUrl) {
	if (!el) return;
	var n = navigator.userAgent.toLowerCase();
	if (n.indexOf("iphone") != -1 || n.indexOf("ipad") != -1 || n.indexOf("ipod") != -1 || n.indexOf("android") != -1) {
	  return;
	}
	el = $(el);
	el.css("display", "block");
	var screenW = el.width();
	var screenH = el.height() - 25;
	var sdsrc = el.attr("data-sdsrc");
	var hdsrc = el.attr("data-hdsrc");
	var videosrc = (screenW > 720 && hdsrc) ?  hdsrc : sdsrc;
	var vp = el.closest(".video_player");
	var permalink = vp.attr("data-permalink");
	vp.find("video").remove();
	vp.find(".fullscreen, .menu.formats").css("display","none");
	var opts = {
		play: null,
		//playlist: [{"url": videosrc }],
		buffering: true,
		onFullscreen: function() {
		  if (!hdsrc || hdsrc == videosrc) return true;
		  videosrc = hdsrc;
		  this.play(hdsrc);
		  return true;
		},
		onMouseOver: function() {
		  window.jQuery(".video_player div.title").fadeIn('fast');
		},
		onMouseOut: function() {
			window.jQuery(".video_player div.title").fadeOut('fast');
		},
		clip: {
			url: videosrc,
			//provider: "httpd",
			scaling: "orig",
			fadeInSpeed: 0,
			fadeOutSpeed: 0,
			autoPlay: true,
			accelerated: true,
			useHwScaling: true,
			autoBuffering: true,
			onStart: function(clip) {
				if (this.NielsenVideo) { this.NielsenVideo.ggPM(15, videoUrl, "content", "<uurl>"+permalink+"</uurl><lenght>"+vp.attr("data-duration")+"</length><title>"+vp.attr("data-title")+"</title><category>"+vp.attr("data-type")+"</category><subcategory>"+vp.attr("data-keyword")+"</subcategory><imgurl>"+vp.attr("data-poster")+"</imgurl>", 1); }
				_gaq.push(["_trackEvent", "Videos", "Play", videoUrl]);
				window.jQuery(".video_player div.title").fadeOut('fast');
			},
			onResume: function(clip) {
				var videoUrl = this.getClip().completeUrl;
				if (this.NielsenVideo) { this.NielsenVideo.ggPM(5); }
				_gaq.push(["_trackEvent", "Videos", "Resume", this.getClip().completeUrl ]);
				window.jQuery(".video_player div.title").fadeOut('fast');
			},
			onPause: function(clip) {
			  var videoUrl = this.getClip().completeUrl;
			  if (this.NielsenVideo) { this.NielsenVideo.ggPM(6); }
			  _gaq.push(["_trackEvent", "Videos", "Pause", this.getClip().completeUrl ]);
			  window.jQuery(".video_player div.title").fadeIn('fast');
			},
			onStop: function(clip) {
				var videoUrl = this.getClip().completeUrl;
				_gaq.push(["_trackEvent", "Videos", "Stop", videoUrl ]);
				if (this.NielsenVideo) { this.NielsenVideo.ggPM(7); }
				window.jQuery(".video_player div.title").fadeIn('fast');
			},
			onFinish: function(clip) {
			  var videoUrl = this.getClip().completeUrl;
			  _gaq.push(["_trackEvent", "Videos", "Finish", videoUrl ]);
			  if (this.NielsenVideo) { this.NielsenVideo.ggPM(7); this.NielsenVideo.ggPM(4); }
			  window.jQuery(".video_player div.title").fadeIn('fast');
			  if (window.top.VideoPlaylist) window.top.VideoPlaylist.playNext();
			}
		},
		plugins: {
		  //httpd: {
		  //	url: '/arturo/static/flowplayer.pseudostreaming.swf'
		  //},
		  controls: {
			  "timeColor":"#ffffff",
			  "borderRadius":"0px",
			  "slowForward":true,
			  "bufferGradient":"none",
			  "backgroundColor":"rgba(0, 0, 0, 0)",
			  "volumeSliderGradient":"none",
			  "slowBackward":false,
			  "timeBorderRadius":20,
			  "progressGradient":"none",
			  "time":true,
			  "height":25,
			  "volumeColor":"#4599ff",
			  "fastBackward":false,
			  "opacity":1,
			  "timeFontSize":12,
			  "volumeSliderColor":"#ffffff",
			  "bufferColor":"#a3a3a3",
			  "border":"0px",
			  "buttonColor":"#ffffff",
			  "mute":true,
			  "backgroundGradient":"none",
			  "width":"100pct",
			  "sliderBorder":"1px solid rgba(128, 128, 128, 0.7)",
			  "display":"block",
			  "buttonOverColor":"#ffffff",
			  "fullscreen":true,
			  "timeBgColor":"rgba(0, 0, 0, 0)",
			  "scrubberBarHeightRatio":0.2,
			  "bottom":3,
			  "stop":false,
			  "zIndex":1,
			  "sliderColor":"#000000",
			  "scrubberHeightRatio":0.6,
			  "tooltipTextColor":"#ffffff",
			  "sliderGradient":"none",
			  "timeBgHeightRatio":0.8,
			  "volumeSliderHeightRatio":0.6,
			  "name":"controls",
			  "timeSeparator":" ",
			  "volumeBarHeightRatio":0.2,
			  "left":"50pct",
			  "tooltipColor":"rgba(0, 0, 0, 0)",
			  "playlist":false,
			  "durationColor":"#b8d9ff",
			  "play":true,
			  "fastForward":true,
			  "timeBorder":"0px solid rgba(0, 0, 0, 0.3)",
			  "progressColor":"#4599ff",
			  "scrubber":true,
			  "volume":true,
			  "volumeBorder":"1px solid rgba(128, 128, 128, 0.7)",
			  //"autoHide":{"enabled":false, "hideDelay":350, "mouseOutDelay":350, "hideStyle":"fade", "hideDuration":400, "fullscreenOnly": false},
			  tooltips: {
					buttons: true,
					play: 'Play',
					pause: 'Pausa',
					mute: 'Togli audio',
					unmute: 'Riattiva audio',
					next: 'Prossimo filmato',
					previous: 'Filmato precedente',
					fullscreen: 'Guarda a tutto schermo',
					fullscreenExit: 'Esci dalla visualizzazione a tutto schermo'
			  }
		  }
		},
		canvas: {
		  backgroundColor: '#000000',
		  backgroundGradient: 'none',
		  borderRadius: 3
		},
		screen: {
		  top:0, left: 0, width: screenW, height: screenH
		}
	}
	if (prerollUrl || postrollUrl) {
	  var buster = ";"+Math.random();
	  opts["plugins"]["openAdStreamer"] = {
			"url": "/arturo/static/flowplayer.ova.swf",
			"autoPlay": true,
			"debug": {
               "debugger": "firebug",
               "levels": "fatal"
			},
            "overlays": {
                "regions": [
                    {
                        "id": "my-ad-notice",
                        "verticalAlign": "bottom",
                        "horizontalAlign": "right",
                        "backgroundColor": "transparent",
                        "width": "100pct",
                        "height": 40,
                        "style": ".smalltext { font-size:11; }"
                    }
                ]
            },
			"ads": {
               "pauseOnClickThrough": false,
			   "disableControls": true,
			   "controls": {
                     "enableScrubber": false,
					 "enableFullscreen": false,
                     "enableVolume": true,
                     "enableMute": true
               },
               "schedule": [ ],
			   "notice": { "show": true, "region": "my-ad-notice", "message": "<p class=\"smalltext\" align=\"right\">Pubblicità - fra _seconds_ secondi vedrai il filmato</p>" },
                "clickSign": {
                   "enabled": false,
				   "verticalAlign": "center", "horizontalAlign": "center",
                   "width": 150, "height": 32, "backgroundColor": "#000000",
                   "opacity": 0.6, "borderRadius": 15,
                   "style": ".smalltext { font-size:12; }",
                   "html": "<p class=\"smalltext\" align=\"center\">Clicca per saperne di più</p>",
                   "scaleRate": 0.75
                }
           }
	  }
	  if (prerollUrl) {
		opts["plugins"]["openAdStreamer"]["ads"]["schedule"].push({'position': 'pre-roll', 'server': {'type':'Direct', 'tag': prerollUrl+buster }})
	  }
	  if (postrollUrl) {
		opts["plugins"]["openAdStreamer"]["ads"]["schedule"].push({'position': 'post-roll', 'server': {'type':'Direct', 'tag': postrollUrl+buster}})
	  }
	} else {
	  // OVA e httpd pseudostreaming sono incompatibili fra loro
	  // Attiva pseudostreaming, con seek via http content-range
	  opts["plugins"]["httpd"] = { url: '/arturo/static/flowplayer.pseudostreaming.swf' };
	  opts["clip"]["provider"] = "httpd";
	}

	var flow = el.flowplayer({'src': "/arturo/static/flowplayer.swf", 'version': [10, 0], 'wmode': 'transparent' }, opts);
	//window.VideoPlayer.initNielsen(flow);
	return el.flowplayer(0);

  }

  this.adjustIframe = function() {
	var ifr = window.frameElement;
	if (!ifr) return;
	ifr.width = $(document.body).width();
	ifr.height = $(document.body).height();
  }

  this.selectMedia = function(vp, targetWidth, targetHeight) {
	var size = {'width': 0, 'height': 0 };
	var source = null;
	var v = vp.find("video");
	if (v.length) {
	  // html5
	  var vt = v.get(0);
	  vt.pause();
	  var sourceList = v.find("source");
	  for (var i = 0; i < sourceList.length; i++) {
		var s = sourceList.eq(i);
		var w = parseInt(s.attr("width"));
		if (!w || !vt.canPlayType(s.attr("type")).replace(/no/, '')) continue;
		if (targetWidth == 'max' && w > size["width"]) {
		  source = s;
		  size["width"] = w;
		} else if (w == targetWidth) {
		  source = s;
		  break;
		}
	  };
	  if (source) {
		size["width"] = parseInt(source.attr("width"));
		size["height"] = parseInt(source.attr("height"));
		if (v.currentSrc != source.attr("src")) {
		  window.VideoPlayer.VASTDone(v, true);
		  vt.src = source.attr("src");
		  v.attr("src", source.attr("src"));
		  vt.load();
		}
	  }

	} else {
	  // flowplayer
	  var fallback = vp.find(".video_fallback");
	  var flow = fallback.flowplayer(0);
	  var source = null;
	  if (targetWidth > 640 || targetWidth == 'max') {
		source = fallback.attr("data-hdsrc");
		if (source) {
		  size["width"] = parseInt(fallback.attr("data-hdwidth"));
		  size["height"] = parseInt(fallback.attr("data-hdheight"));
		}
	  }
	  if (!source) {
		source = fallback.attr("data-sdsrc");
		size["width"] = parseInt(fallback.attr("data-sdwidth"));
		size["height"] = parseInt(fallback.attr("data-sdheight"));
	  }
	  if (source) {
		flow.play(source);
	  }
	}
	return size;
  }


  this.loadVideoFormat = function(e) {
	if (e) {
	  e.stopPropagation();
	  e.preventDefault();
	}
	var btn = $(this);
	//if (btn.hasClass("active")) return;
	var t = btn.attr("rel").split("x");
	var targetWidth = parseInt(t[0]);
	var targetHeight = parseInt(t[1]);
	var vp = btn.closest(".video_player").eq(0);
	var v = vp.find("video");
	if (!v.length) v = vp.find(".video_fallback");
	else {
	  var vt = v.get(0);
	  // non cambiare video o ricare durante i preroll/postroll
	  if (vt.VASTLoading || vt.hasAttribute("data-adv-running")) { return; }
	}
	vp.find(".formats a.active").removeClass("active");
	btn.addClass("active");
	var size = window.VideoPlayer.selectMedia(vp, targetWidth, targetHeight)
	if (size["width"] > (v.width()+100) || size["height"] > (v.height()+100)) {
	  window.VideoPlayer.enterFullscreen(vp, size["width"], size["height"])
	} else {
	  window.VideoPlayer.exitFullscreen();
	  // fai partire il video
	  var vt = v.get(0);
	  if (vt && vt.play) {
		vt.controls = 'true';
		vt.autoplay = 'true';
		//vt.load();
		//vt.play();
	  } else { v.flowplayer(0).play(); }
	}
  }

  this.isFullscreen = function() {
	var res = (window.top.document.getElementById('VideoPlayerOverlay')) ? true : false;
	return res;
  }


  this.toggleFullscreen = function(btn) {
	if (window.top.document.getElementById('VideoPlayerOverlay')) {
	  window.top.VideoPlayer.exitFullscreen();
	  if (btn) { $(btn).removeClass("active"); }
	  return false;
	}
	var vp = (btn) ? $(btn).closest(".video_player") : $(".video_player");
	if (btn) {
	  var size = window.VideoPlayer.selectMedia(vp, 'max');
	  vp.find(".formats a.active").removeClass("active");
	  vp.find(".formats a").removeClass("active");
	  vp.find(".formats a[rel="+size["width"]+"x"+size["height"]+"]").addClass("active");
	}
	window.VideoPlayer.enterFullscreen(vp, size["width"], size["height"]);
  }

  this.enterFullscreen = function(vp, targetWidth, targetHeight) {
	var v = vp.find("video");
	var vt = v.get(0);
	//if (vt && vt.webkitSupportsFullscreen) { vt.webkitEnterFullscreen(); return; }
	//var vt = vp.get(0);
	var flow = null;
	var jq = window.top.jQuery;
	var root = (window.frameElement) ? window.top.jQuery(window.frameElement) : vp;

	var interfaceH = (vp.height() - vp.find(".cnt_media").height())+5;
	var ratio = targetWidth / targetHeight;
	var winW = $(window.top).width();
	var winH = $(window.top).height();
	if (targetWidth >= winW) {
	  targetWidth = winW;
	  targetHeight = Math.round(targetWidth/ratio);
	}
	if (this.FULLSCREEN_EXPANDED) {
	  targetWidth = winW;
	  targetHeight = Math.round(targetWidth/ratio);
	}
	if ((targetHeight + interfaceH) >= winH) {
	  targetHeight = winH - interfaceH;
	  targetWidth = Math.round(targetHeight * ratio);
	}
	var marginX = Math.round((winW - targetWidth) / 2);
	var marginY = Math.round((winH - (targetHeight+interfaceH)) / 3);

	// espandi
	root.parent().css({'display': 'block', 'position': 'relative', 'width': root.width(), 'min-height': root.height() });
	root.css({'position': 'fixed', 'z-index': 10501 });
	v.css({'width': '100%', 'height': '100%' });
	vp.find(".cnt_menu").css({'position': 'absolute', 'bottom': '0px', 'width': '100%'});
	jq(window.top.document.body).append('<div id="VideoPlayerOverlay" onclick="window.top.VideoPlayerExitFullscreen();" style="width: 100%; height: 100%; position: fixed; top: 0; left: 0; background-color: #000000; z-index: 10500"></div>');
	jq("iframe.emediate").css("display","none");
	root.animate({ 'width': targetWidth, 'height': targetHeight+interfaceH, 'left': marginX, 'top': marginY }, 'fast', function() {
		var v = vp.find("video");
		if (v.length) {
		  v.css({'width': targetWidth, 'height': targetHeight });
		  var vt = v.get(0);
		  vt.autoplay = 'true';
		  vt.controls = 'true';
		  vt.play();
		  v.siblings("div.btn_play").css({'height': targetHeight });
		} else {
		  var fallback = vp.find(".video_fallback")
		  var oldFlow = fallback.css({'width': targetWidth, 'height': targetHeight }).flowplayer(0);
		  if (oldFlow) {
			oldFlow.stop();
			oldFlow.unload();
		  }
		  setTimeout(function() {
			var flow = window.VideoPlayer.flashFallback(vp.find(".video_fallback").get(0));
			vp.find(".video_fallback img").click();
			flow.load();
			flow.play();
		  }, 50);
		}
		vp.css({'width': targetWidth, 'height': ''});
		vp.find(".cnt_menu").css({'position': 'static', 'bottom': '', 'width': '100%'});
		if (window.top.VideoPlaylist) window.top.VideoPlaylist.playlistResize();
		vp.find("a.fullscreen").addClass("active");
		window.VideoPlayer.adjustIframe();
	});

	jq(window.top.document).keydown(function(e) {
	  if (e.keyCode == 27) { window.top.VideoPlayer.exitFullscreen(); }   // esc
	});
  }

  this.exitFullscreen = function() {
	if (!window.top.document.getElementById('VideoPlayerOverlay')) {
	  return;
	}

	var shrinkPlayer = function(vp) {
  	  var el = (vp) ? $(vp) : $(this);
	  var autoclose = el.attr("data-autoclose");
	  var targetWidth = parseInt(el.attr("data-width"));
	  var targetHeight = parseInt(el.attr("data-height"));
	  el.css({'position': 'relative', 'z-index': 1, 'width': targetWidth, 'height': '', 'left': '', 'top': '' });
	  if (window.frameElement) {
		el.css("width",targetWidth);
		el.parents("body, html").css("width",targetWidth);
	  }
	  var v = el.find("video");
	  el.find("a.fullscreen").removeClass("active");
	  if (v.length) {
		v.css({'width': '', 'height': '' });
		v.siblings("div.btn_play").css({'height': targetHeight });
		var vt = v.get(0);
		if (vt.webkitDisplayingFullscreen) { vt.webkitExitFullscreen(); }
		vt.width = targetWidth;
		vt.height = targetHeight;
		if (!vt.paused) { vt.play(); }
	  } else {
		var fallback = vp.find(".video_fallback")
		var oldFlow = fallback.css({'width': targetWidth, 'height': targetHeight+25 }).flowplayer(0);
		if (!oldFlow) return;
		var isPlaying = oldFlow.isPlaying();
		oldFlow.stop();
		setTimeout(function() {
		  oldFlow.unload();
		  var flow = window.VideoPlayer.flashFallback(vp.find(".video_fallback").get(0));
		  flow.load();
		  vp.find(".video_fallback img").click();
		  if (isPlaying) { flow.play(); }
		  else { flow.pause(); }
		}, 50);
	  }
	  return {'width': targetWidth, 'height': targetHeight }
	}

	window.top.jQuery(".video_player").each(shrinkPlayer);

	window.top.jQuery(".video_player_embedded").each(function() {
	  var el = $(this);
	  el.css({'position': 'relative', 'z-index': 1, 'width': '', 'height': '', 'left': '', 'top': '' });
	  var iframeWindow = (this.contentWindow) ? this.contentWindow : this.contentDocument.defaultView;
	  shrinkPlayer(iframeWindow.jQuery(".video_player"));
	  iframeWindow.VideoPlayer.adjustIframe();
	});

	if (window.top.VideoPlaylist) window.top.VideoPlaylist.playlistResize();
	window.top.jQuery("#VideoPlayerOverlay").remove();
	window.top.jQuery("iframe.emediate").css("display","block");
	return false;
  }
  window.top.VideoPlayerExitFullscreen = this.exitFullscreen;

  this.playVideo = function(pk, e) {
	if (e && e.stopPropagation) {
	  e.stopPropagation();
	  e.preventDefault();
	}
	var url = (pk) ? "/a/video/"+pk+"/embedded/?autoplay" : $(this).attr("href");
	if (!url) { alert("manca il video!"); return; }
	var vp = window.top.jQuery("iframe.video_player_embedded");
	if (vp.length) {
	  var ifr = vp.get(0);
	  var jq = (ifr.contentWindow) ? ifr.contentWindow.jQuery : ifr.contentDocument.defaultView.jQuery;
	  var v = jq("video");
	  if (v.length) {
		v.get(0).pause();
	  } else {
		jq(".video_fallback").flowplayer(0).stop();
	  }
	  jq("div.video_loading").css("display","block");
	  ifr.src = url;
	  return;
	}
	var vp = $(".video_player").eq(0);
	alert("non implementato");
  }
  window.top.VideoPlayerPlayVideo = this.playVideo;

  this.initVideo = function(el, prerollUrl, postrollUrl) {
	var canPlay = false;
	if (el && el.canPlayType) {
	  var sourceList = $(el).find("source");
	  for (i = 0; i < sourceList.length; i++) {
		var s = sourceList.get(i);
		if (el.canPlayType(s.type.replace(/no/, ''))) {
		  canPlay = true;
		  break;
		}
	  }
	}
	var vp = $(el).closest(".video_player");
	var permalink = vp.attr("data-permalink");
	if (prerollUrl) vp.attr("data-preroll-url", prerollUrl);
	if (postrollUrl) vp.attr("data-postroll-url", postrollUrl);
	vp.find("div.formats a").click(this.loadVideoFormat);
	vp.find(".fullscreen").click(function(e) {
	  e.stopPropagation(); e.preventDefault();
	  window.VideoPlayer.toggleFullscreen(this);
	});

	// il browser non è in grado di far girare il video
	if (!canPlay) {
	  //window.VideoPlayer.initNielsen(vp);
	  window.VideoPlayer.flashFallback(vp.find(".video_fallback"), prerollUrl, postrollUrl);
	  return;
	}
	// Vai col player html5
	///window.VideoPlayer.initNielsen(el);
	if (prerollUrl || prerollUrl) {
	  window.VideoPlayer.loadVAST(vp, prerollUrl, postrollUrl);
	}
	$(el).click(function(e) {
	  // ignora i click nella parte bassa del video - sono sull'interfaccia
	  var y = e.offsetY || e.layerY || e.clientY;
	  if (($(this).height() - y) < 40) return true;
	  //if (navigator.userAgent.toLowerCase().indexOf('firefox') != -1 && e.clientX < 25 && y < 30) { return true; }
	  if (this.paused) { this.play(); }
	  else { this.pause(); }
	});

	// configura gli eventi vari, anche per il loggin su analytics
	function fadeOut(e, el) {
	  if (el && el.paused) { return; }
	  if (!el) var el = this;
	  $(el).closest(".video_player").find("div.title").fadeOut('fast');
	}
	function fadeIn(e, el) {
	  if (!el) var el = this;
	  $(el).closest(".video_player").find("div.title").fadeIn('fast');
	}
	$(el).closest(".cnt_media").hover(fadeIn, fadeOut);

	var btnPlay = $(el).siblings("div.btn_play");
	btnPlay.css({'height': el.height });
	var nav = navigator.userAgent.toLowerCase();
	if (!el.autoplay) btnPlay.css("display", "block");
	btnPlay.click(function(e) {
	  if (el.paused) { el.play(); } else { el.pause(); }
	  e.stopPropagation(); e.preventDefault();
	});
	var msgBuffering = $(el).siblings("div.msg_buffering").get(0);

	// Eventi
	el.addEventListener('play', function() {
	  var hasAdv = window.VideoPlayer.VASTPreroll(this, true);
	  if (hasAdv) {
		fadeOut(null, this);
		//$(this).closest(".video_player").find("div.title").fadeOut('fast');
		return;
	  }
	  if (!this.hasAttribute("data-adv-running")) {
		_gaq.push(["_trackEvent", "Videos", "Play", this.currentSrc ]);
		if (this.NielsenVideo) {
		  if (!this.NielsenVideoLoaded || this.NielsenVideoLoaded != this.currentSrc) {
			var vp = $(this).closest(".video_player");
			this.NielsenVideo.ggPM(15, this.currentSrc, "content", "<uurl>"+permalink+"</uurl><lenght>"+vp.attr("data-duration")+"</length><title>"+vp.attr("data-title")+"</title><category>"+vp.attr("data-type")+"</category><subcategory>"+vp.attr("data-keyword")+"</subcategory><imgurl>"+vp.attr("data-poster")+"</imgurl>", 1);
			this.NielsenVideoLoaded = this.currentSrc;
		  } else {
			this.NielsenVideo.ggPM(5, this.currentTime);
		  }
		}
	  }
	  if (msgBuffering) { msgBuffering.style.display = "none"; }
	  btnPlay.fadeOut('fast', function() { btnPlay.css("display","none"); });
	  setTimeout(function() { btnPlay.css("display","none"); }, 200);
	  fadeOut(null, this);
	}, false);

	el.addEventListener('pause', function() {
	  if (this.VASTLoading) return;
	  if (this.hasAttribute("data-adv-running")) {
		  this.play();
		  return;
	  }
	  _gaq.push(["_trackEvent", "Videos", "Pause", this.currentSrc ]);
	  if (!this.seeking) {
		if (this.NielsenVideo) { this.NielsenVideo.ggPM(6, this.currentTime); }
		btnPlay.fadeIn('fast');
		fadeIn(null, this);
	  }
	}, false);
/*
	el.addEventListener('waiting', function() {
	  this.autoplay = true;
	  //setTimeout(this.play, 2000);
	}, false);
*/

	el.addEventListener('readystatechange', function() {
	  if (this.VASTLoading) return;
	  if (this.readyState == 4 && this.autoplay) { this.play(); }
	  if (this.readyState < 4 && msgBuffering) { msgBuffering.style.display = "block"; }
	  return;
	}, false);

	el.addEventListener('seeking', function() {
	  this.seekingStartPosition = this.currentTime;
	}, false);

	el.addEventListener('seeked', function() {
	  if (this.NielsenVideo) { this.NielsenVideo.ggPM(8, this.seekingStartPosition || 0.0, this.currentTime); }
	}, false);

	el.addEventListener('volumechange', function() {
	}, false);

	el.addEventListener('error', function() {
	  // adv in corso
	  if (this.VASTLoading) return;
	  if (this.hasAttribute("data-adv-running")) {
		if (this.error.code == 4) return;
		//alert('VAST HTMLVideo error: '+this.error.code);
		window.VideoPlayer.VASTDone(this);
		return;
	  }
	  //alert('HTMLVideo error: '+this.error);
	  //_gaq.push(["_trackEvent", "Videos", "Finish", this.currentSrc ]);
	  fadeIn(null, this);
	  btnPlay.fadeIn('fast');
	}, false);


	el.addEventListener('ended', function() {
	  if (this.hasAttribute("data-adv-running")) {
		window.VideoPlayer.VASTDone(this);
		fadeIn(null, this);
		return;
	  } else {
	  	  var hasAdv = window.VideoPlayer.VASTPostroll(this);
		  if (this.NielsenVideo) { this.NielsenVideo.ggPM(7, this.currentTime); }
		  _gaq.push(["_trackEvent", "Videos", "Finish", this.currentSrc ]);
		  if (hasAdv) { return; }
	  }
	  //var vp = $(this).closest(".video_player")
	  //var autoclose = vp.attr("data-autoclose");
	  if (window.top.VideoPlayer.isFullscreen() || !window.top.VideoPlaylist || !window.top.VideoPlaylist.playNext()) {
		window.top.VideoPlayer.exitFullscreen();
		this.currentTime = 0.0;
		this.autoplay = false;
		if (!this.loop) {
		  this.pause();
  		  this.src = '';
		  window.jQuery(this).removeAttr("src");
		  fadeIn(null, this);
		}
	  }
	  if (this.loop) { this.pause(); this.currentTime = 0.0;  this.play(); }
	}, false);

  }

  this.init = function(prerollUrl, postrollUrl) {
	// fallback per ffox 3.5
	var v = document.createElement('video');
	if (!v || !v.canPlayType) {
	  // manca il supporto html5
	  $(".video_fallback").each(function() { window.VideoPlayer.initVideo(this, prerollUrl, postrollUrl); });
	  return;
	} else {
	  $("video").each(function() { window.VideoPlayer.initVideo(this, prerollUrl, postrollUrl); });
	}
	window.top.VideoPlayer = this;
  }

}


/* PlayList */

function _ArturoVideoPlaylist() {

  this.init = function() {
	$(".video_playlist li").click(function(e) {
	  e.stopPropagation();
	  e.preventDefault();
	  window.VideoPlaylist.play(this);
	});
	$(".video_playlist li a").click(function(e) {
	  e.stopPropagation(); e.preventDefault();
	  $(this).closest("li").eq(0).click();
	});
	this.playlistResize();
	return this;
  }

  this.playlistResize = function(p) {
	var plList = $(".video_playlist");
	for (i = 0; i < plList.length; i++) {
	  var pl = plList.eq(i);
	  var li = pl.find("li");
	  var w = (li.eq(0).width()+15) * li.length;
	  pl.find("ul").css({'width': w });
	}
  }

  this.playlistAdd = function(target, event) {

  }

  this.play = function(idx, player) {
	var pl = $(".video_playlist").eq(0);
	if (!pl) return;
	pl.find(".active").removeClass("active");
	var t = (idx && idx.tagName) ? $(idx) : pl.find("li").eq(idx);
	t.addClass("active");
	var pk = t.attr("data-videoid");
	if (!player) var player = window.VideoPlayer
	player.playVideo(pk);
  }

  this.playNext = function() {
	return false;
	var li = $(".video_playlist li");
	if (!li) return false;
	var idx = 0;
	for (i = 0; i < li.length; i++) {
	  var el = li.eq(i);
	  if (el.hasClass("active") && (i+1) < li.length) {
		idx = i + 1;
	  }
	}
	window.VideoPlaylist.play(li.get(idx));
	return true;
  }

}

