$(document).ready(function() {

	//Gestion liens
	$(".clickVod").click(function(event) {
		document.location.href=$(this).attr("rel")
	});
	
	launchStream();
	
	var v = 0;
	function launchStream()
	{
		$.post("ajax/home.deal.php",{},function(data)
		{
			if(data.erreur=="Ok")
			{
				$("#streamButs").empty();
				$("#streamButs").append(data.buttonHTML);
				eval(data.buttonJS);
				var x = $("#activeStream").val();
				$(".changeStream").removeClass("btn-clicked");
				$(".changeStream").addClass("btn");
				$("#goLive"+x).addClass("btn-clicked");
				$("#goLive"+x).removeClass("btn");
				v=setTimeout(launchStream, 60000);
			}
			else
			{
				//alert(data.erreur);
			}
		}
		, "json");
	}

	loadStream(1);
	function loadStream(id)
	{
		$.post("ajax/stream.deal.php",{ action:'loadstream', id:id},function(data)
		{
			if(data.erreur=="Ok")
			{
				$("#streamPlayer").html(data.url);
				if(data.info != "" && data.title != "")
				{
					$("#showStreamDefault").hide();
					$("#showStreamGame").html("<img src='images/icons/jeux/"+ data.img + "' border='0' />");
					$("#showStreamTitle").text(data.title);
					$("#showStreamInfo").html(data.info);
					$("#showStreamTitle").show();
					$("#showStreamInfo").show();
					$("#showStreamGame").show();
				}
				else
				{
					$("#showStreamDefault").show();
					$("#showStreamTitle").hide();
					$("#showStreamInfo").hide();
					$("#showStreamGame").hide();	
				}
			}
			else
			{
				//alert(data.erreur);
			}
		}
		, "json");
	}
	
	function lookinInfo()
	{
		$.post("ajax/stream.deal.php",{ action:'loadstream', id:$("#activeStream").val()},function(data)
		{
			if(data.erreur=="Ok")
			{
				if(data.info != "" && data.title != "")
				{
					$("#showStreamDefault").hide();
					$("#showStreamGame").html("<img src='images/icons/jeux/"+ data.img + "' border='0' />");
					$("#showStreamTitle").text(data.title);
					$("#showStreamInfo").html(data.info);
					$("#showStreamTitle").show();
					$("#showStreamInfo").show();
					$("#showStreamGame").show();
				}
				else
				{
					$("#showStreamDefault").show();
					$("#showStreamTitle").hide();
					$("#showStreamInfo").hide();
					$("#showStreamGame").hide();	
				}
			}
			else
			{
				//alert(data.erreur);
			}
		}
		, "json");
	}
	
	//move admin box for chat away
	var left = $(window).width();
	left = left - 1200;
	left = left/2;
	left = left + 1250;
	$("#commu").css("margin-left", left);
	
	
	function bindChatHover() 
	{
		$("#chat > p").hover(function() {
			$(this).children(".msgTime").show();
		},
		function() {
			$(this).children(".msgTime").hide();
		});
	}
});
