/**
 * @author krizz
 */


var vod = {};

vod.msg = {
	iplaTrue: "Kliknij, aby obejrzeć całość w ipla >>",
	iplaFalse: "Oglądasz zwiastun. Aby zobaczyć całość pobierz i zainstaluj ipla >>"
};
vod.msgTextIpla = '';
/* vod.isInstalledIpla = (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) ? false : iplaCheck(); */
vod.isInstalledIpla = 'false';
if(typeof iplaCheck == "function"){
	if(iplaCheck()){ vod.isInstalledIpla = 'true'; }else{ vod.isInstalledIpla ='false';}
	
}else{
	vod.isInstalledIpla = 'false';
}

vod.isHomepage = false;
vod.showPlayerOnLoad = false;
vod.isDisplayed = false;

vod.setMsgTextIpla = function(){
	if (vod.isInstalledIpla) vod.msgTextIpla = vod.msg.iplaTrue;
	else vod.msgTextIpla = vod.msg.iplaFalse;
}

vod.setMsgTextIpla();

vod.getFlashMovieObject = function (movieName){


	if (window.document[movieName]) {

		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1){

		if (document.embeds && document.embeds[movieName]) {
			return document.embeds[movieName];
		}
	}
	else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	{

    	return document.getElementById(movieName);
  	}
}
vod.params = {
	quality: "high",
	scale: "showall",
	wmode: "transparent",
	devicefont: "false",
	bgcolor: "#000000",
	menu: "false",
	allowFullScreen: "true",
	allowScriptAccess: "sameDomain"
};
vod.attributes = {};
vod.flashvars = {
	isInstalledIpla: vod.isInstalledIpla, /*  */
	getIplaPath: encodeURIComponent('http://www.ipla.pl/Ipla__Pobierz_Ipla,2221/index.html'), /*encodeURIComponent(iplaPageUrl) */
	textIpla: vod.msgTextIpla,
	isHomepage: vod.isHomepage
};
vod.swfHandler = {};
vod.displayPlayerWindow = function() {


	vod.isDisplayed = true;
	
	swfobject.embedSWF("/templates/toptrendy/swf/mainPlayerMultimedia.swf", vod.playerId+"swf", "557", "315", "9.0.0", false, vod.flashvars, vod.params, vod.attributes);
	

	vod.swfHandler = vod.getFlashMovieObject(vod.playerId+'swf');

}
vod.showPlayer = function(id){
	if (id == undefined || id == null) id = 0;
	a = vod.movies[id];
	for(var i in a)	vod.flashvars[i] = encodeURIComponent(a[i]);
	
	if(vod.flashvars['flv'] == '' && vod.isInstalledIpla == 'false' ){
			vod.flashvars['isInstalledIpla'] = true;
			vod.flashvars['pathToIpla'] = encodeURIComponent('http://www.ipla.pl/Ipla__Pobierz_Ipla,2221/index.html');
		}
	
	
	if (vod.showPlayerOnLoad || vod.forceDisplay){
		vod.displayPlayerWindow();
	}	
}
vod.setMovie = function(id){	


	if (!vod.isDisplayed) {
		vod.forceDisplay = true;
//		vod.flashvars.autoPlay = "true";
		vod.showPlayer(id);
		
	}
	else{
		vod.swfHandler.setMovie(
			vod.movies[id].flv,
			vod.movies[id].title,
			vod.movies[id].pathToIpla,
			vod.movies[id].date,
			vod.movies[id].vote,
			vod.movies[id].description,
			vod.movies[id].aspect, // aspect:String ('16:9', '4:3')
			'',		//vod.movies[id].tag,
			'false', //isFullMovie:String
			vod.movies[id].isFlvForIsInstalled
		);
	}
}
vod.setImage = function(id){

	if (!vod.isDisplayed) {
		vod.forceDisplay = true;
		vod.flashvars.autoPlay = "false";
		vod.showPlayer(id);
	}
	else{
		if (vod.movies[id].flv == '' && vod.isInstalledIpla == 'false') {
			flag = 'true';
			vod.movies[id].pathToIpla = 'http://www.ipla.pl/Ipla__Pobierz_Ipla,2221/index.html';
		}else{
			//flag = vod.isInstalledIpla;
			if(vod.isInstalledIpla == 'true'){flag = 'true';}else{flag = 'false';vod.movies[id].pathToIpla = 'http://www.ipla.pl/Ipla__Pobierz_Ipla,2221/index.html'; }
			
		}
		//true false
		
		// ładuje zdjęcie
		vod.swfHandler.setImage(
			vod.movies[id].flv,
			vod.movies[id].bigImg,
			vod.movies[id].title,
			vod.movies[id].pathToIpla,
			vod.movies[id].date,
			vod.movies[id].vote,
			vod.movies[id].description,
			vod.movies[id].aspect,		// aspect:String ('16:9', '4:3')
			'',		//vod.movies[id].tag,
			'false',	//isFullMovie:String
			flag //parametr czy flv
		);
	}
	
}



vod.fireFlash = function(id){

		$("#"+vod.playerId+" .scroll").attr('id', id);
		location.hash = id;

		if(vod.movies[id].flv != ''){	
		
			vod.setImage(id);
			
		}else{
				
			vod.setImage(id);
		}
}

/* TYMCZASOWE */
vod.showPlayerOnLoad = true;
 if(typeof vod === "undefined") vod = {};
vod.movies = [];
$(document).ready(function(){
 	vod.playerId = 'videoPlayer';
	if(location.hash !=''){
		var hashMv = location.hash;
		hashMv = hashMv.replace('#','');
		if(vod.movies[hashMv]){
			vod.fireFlash(hashMv);	
		}else{
			var cc = 0;
			for (i in vod.movies) {if (cc == 0) {vod.fireFlash(i);cc = 1;}}		
		}
	
	}else{
		var cc = 0;
		for(i in vod.movies){
			if(cc == 0){
			vod.fireFlash(i);
			cc = 1;
			}
		}
	}
	
$('#multimedia-polecane .multimedia-item a').click(function(){
	vodId = $(this).attr('title').replace('t_','');
	vod.fireFlash(vodId);
	return false;	
}); 		
$('#multimedia-list .multimedia-item a').click(function(){
	vodId = $(this).attr('title').replace('t_','');
	vod.fireFlash(vodId);
	return false;	
}); 
});
















