var player = null;
var video_id = null;
var video = null;
var currentPLitem =null;
var host = '';

jQuery(document).ready(function(){
	host = jQuery("#host").val();

});

function createPlayer(f_path,w,h,thumb){
	var file="http://"+ host + f_path;
	var so = new SWFObject('/imgfiles/home/img/player-4.2.90.swf', 'plyr', w, h, 'false');
	so.addParam('allowscriptaccess', 'always');
	so.addParam('allowfullscreen', 'true');
	so.addParam('wmode', 'transparent');
	so.addVariable('file',file);

	//solo para cuando es un solo archivo:
	if(thumb) { 
		so.addVariable("image",thumb)
	}

	so.addVariable('autostart', 'false');
	so.write('player');
}

function playerReady(thePlayer)
{
	player = window.document[thePlayer.id];
	//un cop s'ha carregat el video, cridem a aquestes funcions, axií ens assegurem que l'objecte player 
	//i totes les seves variables ja estan inicialitzades
	addListener();
	currentvideo();
}


function addListener() {

	 if (player) { 
		player.addControllerListener("ITEM", "itemListener");
		player.addControllerListener("PLAYLIST", "playlistLoaded");
	} else {
		setTimeout("addListener()",100);
	}
}

//es crida quan es comença a reproduir un video
/*function itemListener(obj) {
	ésta función es diferente en cada página
}*/

function play(id_video){
		for(var i=0; i<player.getPlaylist().length; i++){
			idvideo = player.getPlaylist()[i].author;
			if(idvideo==id_video){
				player.sendEvent('STOP');
				player.sendEvent('ITEM',i);
				currentPLitem = i;
				break;
			}
		}

}

function get_index(id_video){
		for(var i=0; i<player.getPlaylist().length; i++){
			idvideo = player.getPlaylist()[i].author;
			if(idvideo==id_video){
				return i;
				break;
			}
		}
} 

