function getVideo(id, page, champ, methode, script, fullscreen){
	jQuery("#"+champ).fadeOut(200);
	setTimeout("load('"+champ+"', '31')", 50);
	jQuery("#"+champ).fadeIn(200);
	var special = script;
	if (methode != 'postComment')
		special = jQuery("#special").val();
	jQuery.ajax({
		type: "POST",
		dataType: "html",
		data:
		"id="+id+"&page="+page+"&methode="+methode+"&script="+script+"&fullscreen="+fullscreen+"&special="+special,
		url: "/zp/templates/fiche_video/JX_video.php",
		error:function(msg){
			alert( "Error !: " + msg );
		},
		success:function(data){
			//affiche le contenu du fichier dans le conteneur
			jQuery("#"+champ).empty();
			jQuery("#"+champ).fadeIn(200)
			jQuery("#"+champ).append(data);
			
			if (champ == 'postCommentaire'){
				setTimeout("getCommentaire("+page+")", 2000);
			}
			if (champ == 'video'){
				getBlocMemeTheme(); 
    			jQuery("#video-toolbar>li").hover(function(){ jQuery("div", this).css("display", "block")}, function(){jQuery("div", this).css("display", "none")});
				init_ibox();
			}
			if (champ == 'blocMemeTheme'){
				getBlocPlus();
			}
			if (champ == 'blocPlus'){
				if (jQuery("#timeToDown")){
					vitesse(jQuery("#timeToDown").html(), 'timeToDown');
				}
			}
		}
	});
}

function ScrollWin() {
	var Scrolling = 0;
      while(Scrolling != 700) {
	      this.scroll(1,Scrolling)
      	Scrolling++;
      }
}		

function getCommentaire(p){
	if (jQuery("#commentOn").val()){
		jQuery("#commentaire").slideUp();
		jQuery("#commentaire").empty();
		jQuery("#hiddenComment").toggleClass('show');
	}
	else{
		jQuery("#hiddenComment").toggleClass('show');
		getVideo(jQuery("#idV").val(), p, 'commentaire', 'getComment', '');
	}
	
}
function postComment(){
	getVideo(jQuery("#idV").val(), '1', 'postCommentaire', 'postComment', jQuery("#txtComment").val());
}
function getPlus(){
	if (jQuery("#plusOn").val()){
		jQuery("#plus").slideUp();
		jQuery("#plus").empty();
		jQuery("#hiddenPlus").toggleClass('show');
	}
	else{
		jQuery("#hiddenPlus").toggleClass('show');
		getVideo(jQuery("#idV").val(), '1', 'plus', 'getPlus', '');
	}
}
function getMemeTheme(){
	if (jQuery("#themeOn").val()){
		jQuery("#Mtheme").slideUp();
		jQuery("#Mtheme").empty();
		jQuery("#hiddenTheme").toggleClass('show');
	}else{
		jQuery("#hiddenTheme").toggleClass('show');
		var flash = new SWFObject("/flash/KTOTV_slideEmssions.swf?nbCol=4&nbThumb=4&path=/zp/templates/fiche_video/getXML.php?idV="+jQuery("#idV").val(), "mymovie", "400", "140", "8", "");
		flash.addParam("wmode", "transparent");
		flash.addParam("scale", "noScale");
		flash.write("Mtheme"); 

		jQuery("#Mtheme").append('<input type="hidden" id="themeOn" value="1">');
		jQuery("#Mtheme").slideDown();
	}
}
function getBlocMemeTheme(){
	getVideo(jQuery("#idV").val(), '1', 'blocMemeTheme', 'getBlocMemeTheme');
}
function getBlocPlus(){
	getVideo(jQuery("#idV").val(), '1', 'blocPlus', 'getBlocPlus');
}
var test_img; 
var test_src="http://www.ktotv.com/photo/images_default/test_adsl.jpg";   // Image à charger
var test_size=551034;     // Taille de l'image
var test_delai=8000; 
var test_nb=-1; 
var test_delai_max=20000; // 20 000 millisecondes
var timer1=0; 
var timer2=0;
var test_fin="";

function VerifCon(p, champ) {
	// lance la vérif de la connexion
	test_img=new Image();
	timer1=new Date();
	timer1=timer1.getTime();
	test_img.src=test_src+"?dummy="+timer1;
	test_nb=0;
	tempsCon(p, champ);
}
function tempsCon(p, champ) {
	if (test_nb*test_delai>=test_delai_max) { // Fin de la durée maxi
	} else {
		if (test_img.complete) {
			timer2=new Date(); 
			timer2=timer2.getTime();
			test_fin=(test_size/((timer2-timer1)/1000));

			var t = Math.round(p / test_fin);

			if (t > 60){
				jQuery("#"+champ).text(Math.round(t/60)+" min");
			}
			else{
				jQuery("#"+champ).text(t+" sec");
			}	

		} else {

			setTimeout("tempsCon("+p+", '"+champ+"')", 1)
		}
	}
}
function vitesse(p, champ){
	load(champ, '15');
	VerifCon(p, champ);
}


/* fonction du ibox.js reecrite pour reafficher la vod*/
hideIbox = function() {
	$("#mediaPlayer").removeClass('hidden_player');
	hideBG();
	var ibox = getElem('ibox_wrapper');
	ibox.style.display = "none";
	clearIboxContent();
	window.onscroll = null;
}


function getInfoClient(type, id){
	
	// recupere les infos navigateurs et player clients 
	if(id != ''){
		var idV = id;
	}
	else{
		var idV = jQuery("#idV").val();
	}
	
	if (type == 'stream'){
		getVideo(idV, 1, 'video', 'getHtmlInfVideo', jQuery("#videoList").val(), jQuery("#fullscreen").val());
	}
	else{
		parent.location='/getVod.php?file='+idV;	
	}
}

function getVod(){
	getInfoClient("vod", '');

}

function getVar (nomVariable)
{
	var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&"
	if (infos.indexOf("#")!=-1)
		infos = infos.substring(0,infos.indexOf("#"))+"&"
	var variable=0
	{
		nomVariable = nomVariable + "="
		var taille = nomVariable.length
		if (infos.indexOf(nomVariable)!=-1)
			variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&"))
	}
	return variable
}

var idV = getVar('idV');

$(document).ready(function() {
	jQuery("#video-toolbar>li").hover(function(){ jQuery("div", this).css("display", "block")}, function(){jQuery("div", this).css("display", "none")});
	if (jQuery("#timeToDown")){
		vitesse(jQuery("#timeToDown").html(), 'timeToDown');
	}
	var url = document.location.toString();
	var so = new SWFObject('/templates/ktotv/swf/player.swf', 'player_flash', '320', '264', '9');
	so.addParam('allowfullscreen', 'true');
	so.addParam('allowscriptaccess', 'always');
	so.addParam('flashvars', 'streamer=' + jQuery('#url_akamai_streaming_flash').val() + '&file=' + jQuery('#fichier_streaming').val() + '&type=rtmp&autostart=false&plugins=' + jQuery('#plugins').val() + '&dock=true&fbit.link=' + url + '&viral.onpause=false&viral.oncomplete=false&viral.callout=none&viral.functions=embed');
	so.addParam('wmode', 'transparent');
	so.useExpressInstall('/flash/expressinstall.swf');
	so.write('player');
});

