function hasVideo()
{
	return !!document.createElement('video').canPlayType;
}

function hasTouch()
{
	//return true;
	return navigator.userAgent.match(/(?:iPhone|iPad)/i);
	//si on est sur un p?riph?rique tactile
}

var isPlayerReady = false;
var playerVideo = null;

var flashvarsPlayerld =
{
	cfg : "http://static.infomaniak.ch/vod/config/87/653/653_vod.xml",
	enabledJsApi : 1
}

var paramsPlayerld =
{
	menu : "false",
	AllowScriptAccess : "always",
	wmode : "transparent",
	scale : "noscale",
	salign : "lt",
	bgcolor : "#ffffff",
	quality : "high",
	allowfullscreen : "true"
};

var attributesPlayerld =
{
	id : "objPlayer",
	name : "objPlayer"
};

var playerLoaded = function(objId)
{
	isPlayerReady = true;
}
var prepareMobilePlayer = function(video)
{
	isPlayerReady = true;
	$("#player").html('<img src="http://www.rougetv.ch/img/player/player_video.jpg" width="555" height="350">');
	$("#player").click(function()
	{
		window.open(video);
	});
}

/*
function firstPlayerInit(title, desc)
{
	var m_title = title;
	var m_desc	= desc;
	debugger;
	
	function firstPlayerInitLoop()
	{
		debugger;
		if (!isPlayerReady)
		{
			setTimeout(function()
			{
				firstPlayerInitLoop();
			}, 1500);
		}
		else
		{
			getVideoPlayer().setVideoInformations(m_title,m_desc);
		}
	}
	
	firstPlayerInitLoop(title, desc);
}*/


var playInInLinePlayer = function(video, titre, description, thumb, force)
{
	if (!hasTouch())
	{
		var duration = 0;
		if(!titre) titre = "Rouge FM";
		if(!description) description = "";
		if(!thumb) thumb = "";
		if(!video) video = "http://vod.infomaniak.com/redirect/rouge_fm_vod/video-2062/mp4-400/vid-0000035515.mp4"; //vid?o par d?faut (normalement jamais utilis?)
		if(!isPlayerReady)
		{
			loadingSWF(video, duration, titre, description, thumb);
			//firstPlayerInit(titre, description); //correction temporaire au bug du passage de titre par les flashvars
		}
		else
		{
			//debugger;
			getVideoPlayer().loadingNewVideos(video, duration, thumb, 1, 0, null, '555', '351', '1', titre, description);
		}
	}
	else
	{
		if (!isPlayerReady)
		{
			prepareMobilePlayer(video);
		}
		else
		{
			var windowopened = window.open(video);
			if (!windowopened) alert("les popup sont désactivées")
		}
	}
}

var loadingSWF = function(video, duration, titre, description, thumb)
{
	flashvarsPlayerld['video'] = video;
	flashvarsPlayerld['videoDuration'] = duration;
	flashvarsPlayerld['autostart'] = 1;
	flashvarsPlayerld['sTitle'] = encodeURIComponent(titre)
	flashvarsPlayerld['sDescription'] = encodeURIComponent(description);
	flashvarsPlayerld['sImageUrl'] = encodeURIComponent(thumb);
	swfobject.embedSWF("http://static.infomaniak.ch/livetv/player-v3.1.swf", "player", "555", "351", "10.0.0", "http://infomaniak.ch/shared/flashs/expressInstall.swf", flashvarsPlayerld, paramsPlayerld, attributesPlayerld);
}
var getVideoPlayer = function()
{
	return document.getElementById('objPlayer');
}
