/**
 * @author krizz
 */

var vod = {};
vod.isHP = false;
vod.isArchive = false;
vod.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"
};
vod.msgTextIpla = '';
vod.isInstalledIpla = false;
vod.isHomepage = "false";
vod.showPlayerOnLoad = false;
vod.isDisplayed = false;
tabsAktualnosciModuleId = '';



vod.params = {};
vod.attributes = {};
vod.flashvars = {};


vod.init = function(){
	vod.isInstalledIpla = (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) ? false : iplaCheck();
	vod.isHomepage = (vod.isHP)? "true" : "false";
	vod.setMsgTextIpla();
	vod.params = {
	quality: "high",
	scale: "showall",
	wmode: "window",
	devicefont: "false",
	bgcolor: "#232323",
	menu: "false",
	allowFullScreen: "true",
	allowScriptAccess: "sameDomain"
	};
	vod.attributes = {};
	vod.flashvars = {
	isInstalledIpla: vod.isInstalledIpla, 
	getIplaPath: encodeURIComponent(iplaPageUrl),
	textIpla: vod.msgTextIpla,
	isHomepage: vod.isHomepage
	};	
}

vod.setMsgTextIpla = function(){
	if(vod.isHP){	//jesli strona glowna to pelny film
		if (iplaCheck()) vod.msgTextIpla = vod.msg.iplaTrueHP;
		else vod.msgTextIpla = vod.msg.iplaFalseHP;
	}else{	//jesli podstrony to zajawka
		if (iplaCheck()) vod.msgTextIpla = vod.msg.iplaTrue;
		else vod.msgTextIpla = vod.msg.iplaFalse;
	}
}
vod.displayPlayerWindow = function() {
	if(vod.isArchive){
		vod.isInstalledIpla = false;
		vod.flashvars.isInstalledIpla = false;
		vod.flashvars.getIplaPath = '';
		iplaPageUrl = '';
		vod.msgTextIpla = vod.msg.iplaArchive; 
		vod.flashvars.textIpla =vod.msg.iplaArchive;
	}
	vod.isDisplayed = true;
	swfobject.embedSWF("/templates/jos6/swf/mainPlayer.swf", vod.playerId+"swf", "557", "315", "9.0.0", false, vod.flashvars, vod.params, vod.attributes);
	$("#"+vod.playerId).show();
	
}
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.showPlayerOnLoad || vod.forceDisplay){
		vod.displayPlayerWindow();
	}
}
vod.setMovie = function(id){
	if(typeof vod.swfHandler === "undefined"){vod.swfHandler = {};};
	vod.swfHandler = document.getElementById(vod.playerId+'swf');
	$.scrollTo("#h3video",200);
	if (!vod.isDisplayed) {
		vod.forceDisplay = true;
//		vod.flashvars.autoPlay = "true";
		vod.showPlayer(id);
		$.scrollTo("#h3video");
	}
	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.setImage = function(id){
	if(typeof vod.swfHandler === "undefined"){vod.swfHandler = {};};
	vod.swfHandler = document.getElementById(vod.playerId+'swf');
	$.scrollTo("#h3video",200);
	if (!vod.isDisplayed) { 
		vod.forceDisplay = true;
		vod.flashvars.autoPlay = "false";
		vod.showPlayer(id);
	}else{ 

		// ł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
		);
	}
}

vod.bindItems = function(){$("#"+vod.playerId+"mediaList").find(".item").each(function(i){$(this).click(function(){if(!vod.isInstalledIpla){ vod.setMovie(i);}else{ vod.setImage(i);}});});}



/* Obsluga zakladek Video */
vod.module_selected_tab_id = '';

vod.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();
	if (vod.module_selected_tab_id == tabsAktualnosciModuleId){
		$("#"+vod.playerId).hide();
	}
	else{
		$("#"+vod.playerId).show();
		$('#vod'+vod.module_selected_tab_id+' .mediaList .item:eq(0)').click();	
	}
	return false;
};

vod.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 = 2;}
	var _cnt = 0;
	var txt ='';
	for(i in tabs){
		txt='<li id="tab'+tabs[i]+'"><a class="tab_'+_cnt+'" href="javascript:void(0)" onclick="vod.selectTab('+tabs[i]+')"><!-- --></a></li>'+txt;
		_cnt = _cnt +1;
	}
	$('#videoPanels').html(txt);
	$('.tabBlock').hide();
	if (typeof pagination_module_id == 'undefined') {
		nrs = 2 - 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();
		$.scrollTo("#h3video");
		if(vod.showPlayerOnLoad == true){	
			vod.showPlayer($('#videoPlayer'+pagination_module_id+'mediaList .item:eq(0)').attr('id'));
		}
	}
};

/* METODY DO ZAKLADEK */
vod.bindItemsToTabs = function(ide){
	$("#"+ide+"mediaList").find(".item").each(function(i){
		$(this).click(function(){	
			if(!vod.isInstalledIpla){
				vod.setMovie($(this).attr('id'));
			}else{
				vod.setImage($(this).attr('id'));
			};
		});
	});
}
/* UCZESTNICY */
vod.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 = 2;}
	vod.selectUserTab(hsh);
};
vod.selectUserTab = function(i){
	$('#videoPanels li').removeClass('sel');
	$('#videoPanels li:eq('+i+')').addClass('sel');
	$('.tabBlock').hide();
	$('#tabbedPlayer div.tabBlock:eq('+(2-i)+')').show();
	if(i == 2){$('#tabbedPlayer div.wrapPlayer').hide();}else{$('#tabbedPlayer div.wrapPlayer').show();	$('#tabbedPlayer div.tabBlock:eq('+(2-i)+') .mediaList .item:eq(0)').click();}
	

	
	return false;
};
vod.bindToItemsStars = function(ide){
	$("#"+ide+"mediaList").find(".item").each(function(i){
		$(this).click(function(){	
			if(!vod.isInstalledIpla){
				vod.setMovie($(this).attr('id'));
			}else{
				vod.setImage($(this).attr('id'));
			};
		});
	});
}
/*KONIEC METODY DO ZAKLADEK*/
/**/
