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: "opaque",
	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/player-sg.swf", vod.playerId+"swf", "471", "265", "9.0.0", false, vod.flashvars, vod.params, vod.attributes);
	//player-sg.swf

	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){

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

/* TYMCZASOWE */
vod.showPlayerOnLoad = true;
 if(typeof vod === "undefined") vod = {};
vod.movies = [];

/*
vod.movies['vod7e572f16bcdcd5b7fbd75b1be630fad7'] = {
 id:'vod7e572f16bcdcd5b7fbd75b1be630fad7',
 flv:'http://tt01.redefine.pl:8180/x.vod?id=65830',
 pathToIpla:'ipla://playvod-1|7e572f16bcdcd5b7fbd75b1be630fad7',
 title:'TOPtrendy festiwal 2009',
 date:'15:05 | 2009.05.22',
 bigImg:'http://tt01.redefine.pl:8180/x.image?id=56626&version=maxi',
 description:"Najwa\u017Cniejsze wydarzenie muzyczne roku!",
 aspect:"4x3",
 vote: 0
 }; */

$(document).ready(function(){
 	vod.playerId = 'sg-player';
	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;
			}
		}
	}
	
		
});