jQuery.noConflict();

var isShown = false;

jQuery(document).ready(function()
{
	var params = { allowScriptAccess: "always", wmode: "transparent" };
    var atts = { id: "ytPlayer" };
	var url = "http://www.youtube.com/e/yj91JK_CAEs?enablejsapi=1&version=3";
    
	if (cookie.getCookie("embPlayer"))
	{		
		showPicture();
	}
	else
	{
		url += "&autoplay=1";
		cookie.setCookie("embPlayer", "siudPlayer",1);
	}
	
	swfobject.embedSWF(url, "embytPlayer", "400", "230", "8", null, null, params, atts);
	
	var player = document.getElementById("ytPlayer");
	
	jQuery(".embYoutubePicture").click(function()
	{
		var player = document.getElementById("ytPlayer");
		hidePicture();
		
		if (jQuery.browser.msie)
		{
			onYouTubePlayerReady();
		}
	});
});

function onYouTubePlayerReady(playerid)
{
	var player = document.getElementById("ytPlayer");
	player.addEventListener("onStateChange", "onytplayerStateChange");
	
	if (!isShown && jQuery.browser.msie)
	{
		isShown = true;
		player.stopVideo();
	}
	else
	{
		player.playVideo();
	}
	
	if (!cookie.getCookie("embPlayer"))
	{
		player.playVideo();
	}
}

function onytplayerStateChange(val)
{
	var player = document.getElementById("ytPlayer");
	if (val==0)
	{
		player.seekTo(0);
		player.playVideo();
		player.pauseVideo();
		player.stopVideo();
		showPicture();
	}
}

function showPicture()
{	
	if (jQuery.browser.msie)
	{
		jQuery(".embYoutubePlayer").css({position:"absolute", top: "-900px"});
	}
	else
	{
		jQuery(".embYoutubePlayer").css("display","none");
	}
	jQuery(".embYoutubePicture").css("display","block");
}

function hidePicture()
{
	if (jQuery.browser.msie)
	{
		jQuery(".embYoutubePlayer").css({position:"static"});
	}
	else
	{
		jQuery(".embYoutubePlayer").css("display","block");
	}
	jQuery(".embYoutubePicture").css("display","none");
}
