$(function(){
	
	// slide con video approfondimenti
	$("#label_approfondimenti").click(function () {
		$("#approfondimenti").slideToggle("slow", function(){
			if($("#approfondimenti").is(":visible")){
				$("#label_approfondimenti a").addClass("active");
			} else {
				$("#label_approfondimenti a").removeClass("active");
			}
		});
	});
	
	// sostituisco il video che si puņ vedere
	$(".play_video").click(function () {
		var link_img = $(this).attr("rel");
		var tg_id = $("#tg_id").attr("rel");
		//questo metodo carica il nuovo video (comprensivo di player)
		//youtube(link_img, 'video_youtube', 364, 273);
		
		if (tg_id && link_img == tg_id) {
			ytplayer.loadVideoById(link_img,pos_tg);
			sem = 1;
			$('#video_tg').hide();
		} else {
			if (sem == 1) {
				pos_tg = ytplayer.getCurrentTime();
				sem = 0;
			}
			$('#video_tg').show();
			ytplayer.loadVideoById(link_img);
		}
	});
	
});

var pos_tg;
var sem = 1;
function youtube(idvideo, contenitore, width, height) {
	var params = {
		allowScriptAccess: "always",
		allowFullScreen: "true",
		wmode: "transparent"
	};
	var attributes = {
		id: 'player_youtube',
		name: "YOUTUBE"
	};
	swfobject.embedSWF("http://www.youtube.com/e/" + idvideo + "?enablejsapi=1&playerapiid=ytplayer&fmt=22&showinfo=0&fs=1", contenitore, width, height, "9.0.0", false, false, params, attributes);
}

function onYouTubePlayerReady(playerId) {
	ytplayer = document.getElementById("player_youtube");
}
