/* OBSLUGA VOD */
var iplaPageUrl ='http://www.ipla.pl/Ipla__Pobierz_Ipla,2221/index.html';
var vod = {
	
	isInstalledIpla : false,
	isDisplayed : false,
	isHP : false,
	showPlayerOnLoad : false,
	module_selected_tab_id : '',	
	params : {},
	attributes : {},
	flashvars : {},
	movies : [],
	playerId : '',
	msg : {
		iplaTrueHP: "Kliknij, aby obejrzeć całość w ipla >>",
		iplaFalseHP: "Oglądasz zwiastun. Aby zobaczyć całość pobierz i zainstaluj ipla >>",
		iplaTrue: "Kliknij, aby obejrzeć całość w ipla >>",
		iplaFalse: "Oglądasz zwiastun. Aby zobaczyć całość pobierz i zainstaluj ipla >>",
		iplaArchive: "Oglądasz materiał archiwalny"
		},
	init : function(){
		vod.isInstalledIpla = iplaCheck();
		vod.params = {
			quality: "high",
			scale: "showall",
			wmode: "transparent",
			devicefont: "false",
			bgcolor: "#000000",
			menu: "false",
			allowFullScreen: "true",
			allowScriptAccess: "sameDomain"
		};
		vod.attributes = {};
		vod.flashvars = { 
			pathToFooter : iplaPageUrl, 
			textFooter: vod.msg['iplaFalse']
		};	
	},
	/* Metoda uruchamiana na onload */
	showPlayer : function(id){
		if (id == undefined || id == null) id = 0;
		a = vod.movies[id];
		for (var i in a) {
			if(i =='pathToIpla'){
				if(vod.isInstalledIpla){
					vod.flashvars[i] = encodeURIComponent(a[i]);	
				}else{
					vod.flashvars[i] = '';
				}
			}else{
				vod.flashvars[i] = encodeURIComponent(a[i]);
			}
		}
		if (vod.showPlayerOnLoad || vod.forceDisplay){
			vod.displayPlayerWindow();
		}
	},
	
	/* Metoda embedująca player na stronie */
	displayPlayerWindow : function() {
		if(vod.isDisplayed == false){
			swfobject.embedSWF("/templates/toptrendy2010/swf/us2videoPlayer.swf", vod.playerId+"swf", "558", "315", "10.0.0", false, vod.flashvars, vod.params, vod.attributes);
			$("#"+vod.playerId).show();
			vod.isDisplayed = true;
		}
	},
	/* drugi parametr informuje o odpaleniu trailera */
	fireVod : function(id,isIpla){
		if(typeof vod.swfHandler === "undefined"){vod.swfHandler = {};};
		vod.swfHandler = document.getElementById(vod.playerId+'swf');
		if (!vod.isDisplayed){
			vod.forceDisplay = true;
			vod.showPlayer(id);
		}else{
			if(isIpla){
				vod.swfHandler.initStartScreen(vod.movies[id].imageURL,vod.movies[id].pathToIpla);
				vod.swfHandler.initInfo(vod.movies[id].title, vod.movies[id].description,vod.movies[id].vote,vod.movies[id].date);
				vod.swfHandler.changeVisibleStartScreen("true");				
			}else{
				vod.swfHandler.initStartScreen(vod.movies[id].imageURL);
				vod.swfHandler.initInfo(vod.movies[id].title, vod.movies[id].description,vod.movies[id].vote,vod.movies[id].date);
				vod.swfHandler.initVideo(vod.movies[id].videoURL, vod.movies[id].aspect);
				vod.swfHandler.loadVideo();			
			}
		}
	},
	
	bindItems : function(){$("#"+vod.playerId+"mediaList").find(".item").each(function(i){$(this).click(function(){
			vod.fireVod(i,vod.isInstalledIpla);
		});});},

	/* UCZESTNICY */
	selInitTab : function(){
		if(window.location.hash == '#t0'){hsh = 0;}else if(window.location.hash == '#t1'){hsh = 1;}else if(window.location.hash == '#t2'){hsh = 2;}else{hsh = 0;}
		vod.selectUserTab(hsh);
	},
	
	selectUserTab : function(i){
		$('#videoPanels li').removeClass('sel');
		$('#videoPanels li:eq('+i+')').addClass('sel');
		$('.tabBlock').hide();
		$('#tabbedPlayer div.tabBlock:eq('+(i)+')').show();
		if(i == 0){
			$('#tabbedPlayer div.wrapPlayer').hide();
		}else{
			
			if(!$('#tabbedPlayer div.tabBlock:eq('+(i)+') div').hasClass('info')){
				$('#tabbedPlayer div.wrapPlayer').show();
				$('#tabbedPlayer div.tabBlock:eq('+(i)+') .mediaList .item:eq(0)').click();
			}
		}
		return false;
	},
	bindToItemsStars : function(ide){
		$("#"+ide+"mediaList").find(".item").each(function(i){
			$(this).click(function(){vod.fireVod($(this).attr('id'),vod.isInstalledIpla);});
		});
	},
	
	/* Zakladki video */
	selectTab : function(id){
		vod.tabbedClick = true;
		vod.module_selected_tab_id = id;
		$('#videoPanels li').removeClass('sel');
		$('#tab'+id).addClass('sel');
		$('.tabBlock').hide();
		$('#vod'+id).show();
		$("#"+vod.playerId).show();
		$('#vod'+vod.module_selected_tab_id+' .mediaList .item:eq(0)').click();	
		return false;
	},
	
	genTabs : function(){
		if(window.location.hash == '#t0'){hsh = 0;}else if(window.location.hash == '#t1'){hsh = 1;}else if(window.location.hash == '#t2'){hsh = 2;}else{hsh = 0;}
		var _cnt = 0;
		var txt ='';
		for(i in tabs){
			txt=txt+'<li id="tab'+tabs[i]+'"><a class="tab_'+_cnt+'" href="javascript:void(0)" onclick="vod.selectTab('+tabs[i]+')"><!-- --></a></li>';
			_cnt = _cnt +1;
		}
		$('#videoPanels').html(txt);
		$('.tabBlock').hide();
		if (typeof pagination_module_id == 'undefined') {
			nrs = parseInt(hsh);
			$('#videoPanels li:eq(' + hsh + ')').addClass('sel');
			$('#tabbedPlayer .tabBlock:eq('+nrs+')').show();
			if(vod.showPlayerOnLoad == true){
				vod.showPlayer($('#tabbedPlayer .tabBlock:eq(0) .mediaList .item:eq(0)').attr('id'));
			}
		}else{
			$('#tab'+pagination_module_id+'').addClass('sel');
			$('#vod'+pagination_module_id+'').show();
			if(vod.showPlayerOnLoad == true){	
				vod.showPlayer($('#videoPlayer'+pagination_module_id+'mediaList .item:eq(0)').attr('id'));
			}
		}
	}
}


function openURL(urle){location.href = urle;}




