$.fn.preview = function()
{
	var m_this = this;
	
	var cont = $("#imagePreview");
	if (!(cont && cont.length>0))
	{
		var ht = '<div id="imagePreview" style="position:absolute;z-index:1000; background-color:#D2D6E2; border:2px solid #B4BCCE; display:none;">' +
				'<div class="tt" style="padding:3px 0 3px 0; border-bottom: 2px solid #B4BCCE; font-weight:bold"></div><img src=""/></div>';
		$(document.body).append(ht);
	}
	
	$(document).click(function(){$("#imagePreview").fadeOut("normal")});
	
	m_this.click(function()
	{
		var h = m_this.attr("href");
		if (h && h!="")
		{
			$("#imagePreview img").bind("load", function()
			{
				var w = this.width;
				var h = this.h;
				$("#imagePreview").css({top:($(window).height() - 500) /2 + 'px', 
						             left:($(window).width() - 500) /2 + 'px'});
				$("#imagePreview").fadeIn("normal");
				$("#imagePreview .tt").html(m_this.attr("title"));
			})

			$("#imagePreview img").attr("src", h);
		}
		return false;
	})
}

$(document).ready(function(){
	/*Menu*/
	var url = document.location.href;
	$("#header a").each(function()
	{
		var href = $(this).attr("href").split("../").join("");
		var hrefPrefix = href.indexOf("/")!=-1 ? href.substring(0, href.lastIndexOf("/"))+"/" : href;
		
		if (url.indexOf(href)!=-1)
		{
			$(this).closest("li").find("ul").show();
			$(this).addClass("current");
		}
		else if (url.indexOf(hrefPrefix)!=-1)
		{
			$(this).closest("li").find("ul").show();
			//$(this).addClass("active");
		}
	})
	/*Menu ColDx*/
	$(".coldx li > a").each(function()
	{
		var href = $(this).attr("href").split("../").join("");
		var hrefPrefix = href.indexOf("/")!=-1 ? href.substring(0, href.lastIndexOf("/"))+"/" : href;
		
		if (url.indexOf(href)!=-1)
		{
			$(this).closest("li").find("ul").show();
			$(this).addClass("current");
		}
		
		else if (url.indexOf(hrefPrefix)!=-1)
		{
			$(this).closest("li").find("ul").show();
			$(this).addClass("active");
		}
	})
	
	/*Box scroll*/
	if($("#list").length>0){
		$("#list").find("div.item").each(function(){if ($(this).html().split(" ").join("").split("\n").join("").split("\r").join("").split("\t").join("")=="") $(this).remove()});
		$("#list").cycle({
		    fx: "scrollUp",
		    timeout: 5000,
			height: 269,
		    delay:  -2000
		});
	}
	
	$("a[rel='preview']").each(function(){$(this).preview()});
	
	$("a[rel='videoPlayer']").each(function()
	{
		var prefix = document.location.href.indexOf("timeo.biz")!=-1 ? "/fastwebtv/" : "/";
		var href = prefix + $(this).attr("href").split("../").join("");
		var el = $(this).after("<div id=\"videoPlayer\" style=\"width:460px; height:290px; margin-bottom:10px\"></div>");
		$(this).hide();
		$f("videoPlayer", prefix + "res/swf/flowplayer-3.1.5.swf", { 
			    plugins:  { 
			        controls: { 
			           
			            // tooltips configuration 
			            tooltips: { 
			                 
			                // enable english tooltips on all buttons 
			                buttons: true,                  
			                // customized texts for buttons 
			                play: 'Play', 
			                pause: 'Pausa',
			                //fullscreen: 'Fullscreen',
							mute: 'Disattiva',
							unmute: 'Attiva'
			            }, 
						
						// controlbar specific settings
						all:false, 
			            scrubber:true, 
			            play:true, 
			            mute:true,
						time:true,
			             
			            // background color for all tooltips 
			            tooltipColor: '#3F5181',			 
			            // text color 
			            tooltipTextColor: '#F5BB14',
						// buffer color
						bufferColor: '#3F5181',
						//progress color
						progressColor: '#F5BB14',						
						//background color toolbar
						backgroundColor: '#3F5181',
						sliderColor: '#F5BB14',
						//button color
						buttonColor: '#F5BB14', 
			            buttonOverColor: '#F5BB14',
						//time color
						timeColor: '#F5BB14',
						durationColor: '#F5BB14',						
						timeBgColor: '#3F5181'
			        } 
			    },  
     
			   // pause on first frame of the video 
			   clip: { 
			   	   url: href, 
			       autoPlay: true, 
			       autoBuffering: true 
			   },
			
				// fiercy background color with a little gradient and curving 
				canvas: { 
			       backgroundColor: '#3F5181', 
			       backgroundGradient: [0.3, 0]
			   }
			});
	})
})