// JavaScript Document

$(window).load(function () {

	//////////////////////////////////////////////////////////// 
	// MUSIC PLAYER
	if ($("#player_box").length) {
		$f("music_player", "/include/flowplayer/flowplayer-3.2.5.swf", {
				clip: {
					autoPlay: false,
					autoBuffering: true,
					url: '/musica_euromobil.mp3',
					onBeforeFinish: function() {
						return false; 
					}
	
				},
				plugins: {
					controls: null
				}
		}).controls("music_control");
		
		// aggiungo funzione personalizzata su tasto play
		$("#play_pause").live("click", function () {
			if ($(this).hasClass("play")) {$(this).text('play')} else {
				$(this).text('pause');
			}
		});
	}
	// Impostazione del testo "Play"
	$("#play_pause").text('PLAY');


	//////////////////////////////////////////////////////////// 
	// HOVER PULSANTI
	$("ul.pulsanti_home li a.immagine").append('<span class="hover"></span>');
	$("ul.pulsanti_home li").mouseenter(function () {
		$("ul.pulsanti_home li").not(this).addClass("dark");
	}).mouseleave(function () {
		$("ul.pulsanti_home li").not(this).removeClass("dark");
	});
	
	//////////////////////////////////////////////////////////// 
	// HOVER TOTAL HOME
	$(".total_home").mouseenter(function () {
		
		var bg = '<a id="bg_hover" target="_blank" href="http://www.totalhomedesign.it"  style="width: 100%; height: 100%;background: white; position: absolute; left: 0px; top: 0px; z-index: 100; display: block;"></a>';
		
		$(this).append(bg);
		$("#bg_hover").css({
			opacity: 0.2
		});
	}).mouseleave(function () {
		$("#bg_hover").remove();
	}).click(function() {
		// Tracciamento azione utente
		_gaq.push(['_trackEvent', 'Home Page', 'Banner', 'Total Home Design']);
		
		$("#bg_hover").remove();
	});
	
	//////////////////////////////////////////////////////////// 
	// SLIDE VETRINA
	$('#slide_vetrina .slider').cycle({
		fx: 'scrollLeft',
		speed: 1500,
		timeout: 4000
	});

	//////////////////////////////////////////////////////////// 
	// POPUP VETRINA
	$(".vetrina a.popup").click(function () {

		// Stop alla musica all'apertura del popup
		$f('music_player').pause();
		$("#play_pause").text('play');

		$.fancybox({
			padding: 10,
			href: $(this).attr("href"),
			scrolling: 'hidden',
			showCloseButton: false,
			overlayOpacity: 0.8,
			overlayColor: "#000000",
			titleFormat: formatTitle_video,
			titlePosition: 'inside'
		});
		
	
		return false;
	});

});

function formatTitle_video(title, currentArray, currentIndex, currentOpts) {
		var output = '<div id="contenuto_titolo_fb">';
		output += title;
		output += '	<div id="utility_fb">';
		//output += '		<a href="/utility/download.php?file='+currentArray[currentIndex].href+'" target="_blank"><img src="/immagini_layout/fb_salva.png" /></a>';
		//output += '		<a href="/utility/stampa.php?file='+currentArray[currentIndex].href+'" target="_blank"><img src="/immagini_layout/fb_print.png"" /></a>';
		output += '		<a href="javascript:;" onclick="$.fancybox.close();"><img src="/immagini_layout/fb_chiudi.png" /></a>';
		output += '	</div>';
		output += '</div>';
		return output;
}

function fancybox_video_popup (file, didascalia) {
	$.fancybox({
		padding: 10,
		content: '<div id="video_player" style="width: 650px; height: 365px;"></div>',
		scrolling: 'hidden',
		showCloseButton: false,
		overlayOpacity: 0.8,
		overlayColor: "#000000",
		customClass: "video_popup",
		//title: didascalia,
		titlePosition: 'inside',
		titleFormat: formatTitle_video,
		onComplete: function () {
			$f("video_player", "/nz/include/flowplayer/flowplayer.commercial-3.2.5.swf", {
				key: '#$e21679626322f760ad1',
				logo: {
						url: ''
				},
				clip: {
					autoPlay: true,
					autoBuffer: true,
					url: file,
					scaling: 'scale'
				},
				canvas: {
					backgroundGradient: 'none'
				},
				plugins: { 
					  controls: { 
						url: 'flowplayer.controls-3.2.3.swf', 
						scrubberBarHeightRatio: '0.1', //altezza barra tempo 
						backgroundColor: '#18171A', 
						backgroundGradient: 'none', 
						fontColor: '#ffffff',
						timeColor: '#ffffff' ,
						progressColor: '#',
						bufferColor: '#cccccc',
						buttonColor: '#ffffff',
						play:true, 
						volume:true, 
						mute:true, 
						time:true, 
						stop:false, 
						playlist:false, 
						fullscreen:false,
						//top: 0,
						left: 0,
						bottom: 0,
						height: 20,
						width: 650
						/*autoHide: {
						  enabled: true,
						  hideDelay: 1000,
						  fullscreenOnly: false
						}*/
					  }
				   }
			});
		}
	});	
}

