/* JAVASCRIPT UZYWANY W WYBRANYM MATERIALE */
var isIpla = (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) ? false : iplaCheck();
$(document).ready(function(){
/* SCROLLER, OCENY, SEARCH FORM */	
		initScroller(1, 10, 0, '#vod_description .scroller_wrapper', '#vod_description .desc', '#vod_description .scroll_up', '#vod_description .scroll_down', '#vod_description .scroller_controls', true);
		initOceny();
		initSearchForm();	

/* START BELKA POBIERZ IPLA */
	if(globalIplaCheck() != true){
		var os = ipla.os();
		if(os == 'Windows'){$("#get-ipla-belka-win").show();}
		if(os == 'Mac'){$("#get-ipla-belka-mac").show();}
		if(os == 'Linux'){$("#get-ipla-belka-mac").show();}
	}
	var seeinipla = $("#zobacz_w_ipla");
	if(seeinipla.attr('href') == ''){seeinipla.hide();}
/* END BELKA POBIERZ IPLA */
	
/* START AUTOMATYCZNE ODPALENIE IPLA */
	if(location.search == "?play"){
		var interval= 0;
		interval= setInterval(function(){if(detectionDone()){elem= document.getElementById("zobacz_w_ipla");elemj= $("#zobacz_w_ipla");if(document.createEvent){if(!elem.click && !elem.onclick && iplaCheck()){location.href= elemj.attr("href");}else{var evt = document.createEvent("MouseEvents");evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);dis= elem.dispatchEvent(evt);}}else{if(!elem.click && !elem.onclick && iplaCheck()){location.href= elemj.attr("href");}else{elem.click();}}clearInterval(interval);}}, 500);
	}
/* KONIEC AUTOMATYCZNE ODPALENIE IPLA */
});


/* EMBED BROWSER */
function embedBrowser() {
	var heightThumb = (230 * 9) / 16;
	var flashvars = {   pathXMLWall: "/templates/iplatv/flash_xml/228.xml",
		kategorieURL: "/templates/iplatv/flash_xml/228.xml",
		serialeURL: "/templates/iplatv/flash_xml/1754.xml",
		rozrywkaURL: "/templates/iplatv/flash_xml/1756.xml",
		wiadomosciURL: "/templates/iplatv/flash_xml/1753.xml",
		sportURL: "/templates/iplatv/flash_xml/1757.xml",
		muzykaURL: "/templates/iplatv/flash_xml/1755.xml",
		logoURL: "/templates/iplatv/gfx/logo.png",
		iplaInstalled: globalIplaCheck(),
		pathSWF: "/templates/iplatv/swf/browser/browser_body2.swf",
		bgURL: "/templates/iplatv/gfx/main_bg.jpg",
		naZywoURL: encodeURIComponent($("#nazywourl").attr("href"))
		//,iplaDetectFunction: iplaCheckAndForce
	};
	if(!globalIplaCheck()) flashvars.iplaDetectFunction = iplaCheckAndForce;
	var params = {allowFullScreen: true};
	var attributes = {};
	swfobject.embedSWF("/templates/iplatv/swf/browser/browser.swf", "flash_content", $('body').width(), $('body').height(), "9.0.28", "", flashvars, params, attributes);
}


/* FUNKCJE UZYWANE W WYSZUKIWARCE */
function gup(src,name){
			name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
			var regexS = "[\\?&]"+name+"=([^&#]*)";
			var regex = new RegExp( regexS );
			var results = regex.exec( src );
			if(results == null){return "";}else{return results[1];}
}

function changeFrameRequest(obj){
	var servletUrl = "http://iplasearch.redefine.pl/search/cmsSearch4Ipla?vod_limit=500&matchopt=0&ver=6";
	var paramsToCopy = new Array("keywords","extra_text");
	var val;
	var paramsStr = "";
	for(var param in paramsToCopy){
		val = gup(window.location.href, paramsToCopy[param]);
		paramsStr += "&" + paramsToCopy[param] + "=" +val;
	}
	var iframeLoaded = gup(obj.src, 'iframeLoaded');
	if( obj.src == "" || iframeLoaded != 'iframeOk'){
		obj.src = servletUrl + "&iframeLoaded=iframeOk" + paramsStr;
	}
}


/* WKLEJKI START */
function iplaPasteLink(){
	var text = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname+'?play';
	$('#w-overlay').show();
	$('#w-overlay').click(function(){overlayClose('w-overlay-link');});
	$('#w-overlay-link .scroller_wrapper .desc2').text('');
	$('#w-overlay-link .scroller_wrapper .desc2').text(text);
	$('#w-overlay-link').show();
	clip = new ZeroClipboard.Client();
	clip.setHandCursor( true );
	clip.addEventListener('mouseOver', function(client) {clip.setText( document.getElementById('link-overlay-txt').value );});
	clip.glue( 'd_clip_button', 'd_clip_container' );
}
function overlayClose(ide){
	$('#w-overlay').hide();
	$('#'+ide).hide();
	clip.destroy();
	$('#fl2cp').remove();
}

function getContainterPos(){
	//(parseInt(ipla.getHeight / 2, 10)) + "px";
	var win_h;
	if(window.pageYOffset){
		win_h = (window.pageYOffset);
	}else if(document.documentElement.scrollTop){
		win_h = (document.documentElement.scrollTop);
	}else if(document.body.scrollTop){
		win_h = (document.body.scrollTop);
	}else{ 
		win_h = 0;
	}
	win_h = parseInt(win_h, 10);		
	win_h += 150;
	return win_h + 'px';
}

function iplaPasteImage(size){
	var text = '';
	text +='<!-- Start IPLA VOD -->\n';
	text +='<script type="text/javascript">\n';
	text +='if(typeof ipla === "undefined"){document.write(unescape("%3Cscript src=\'http://detector.ipla.pl/ipladetector2_02.js\' type=\'text/javascript\'%3E%3C/script%3E"));}\n';
	text +='</script>\n';
	text +='<a id="ipla_vod_'+iplaVodId+'" href="'+iplaUrl+'" style="outline:none;">';
	if(size == 0){
		text +='<img style="border:1px solid #89b335;" src="'+smallImg+'" alt="" />';
		$('div.w-images a').removeClass('sel');	
		$('div.w-images a.small').addClass('sel');
	}else{
		text +='<img style="border:1px solid #89b335;" src="'+bigImg+'" alt="" />';
		$('div.w-images a').removeClass('sel');	
		$('div.w-images a.big').addClass('sel');
	}
	text +='</a>\n';
	text +='';
	text +='<!--Koniec IPLA VOD -->';
	$('#w-overlay').show();
	$('#w-overlay').click(function(){overlayClose('w-overlay-image');});
	$('#w-overlay-image .scroller_wrapper .desc2').text('');
	$('#w-overlay-image .scroller_wrapper .desc2').text(text);
	$('#w-overlay-image').show();
	clip = new ZeroClipboard.Client();
	clip.setHandCursor( true );
	clip.addEventListener('mouseOver', function(client) {clip.setText( document.getElementById('image-overlay-txt').value );});
	clip.glue( 'd_clip_button-i', 'd_clip_container-i' );
}

function iplaPasteImageChange(size){
	var text = '';
	text +='<!-- Start IPLA VOD -->\n';
	text +='<script type="text/javascript">\n';
	text +='if(typeof ipla === "undefined"){document.write(unescape("%3Cscript src=\'http://detector.ipla.pl/ipladetector2_02.js\' type=\'text/javascript\'%3E%3C/script%3E"));}\n';
	text +='</script>\n';
	text +='<a id="ipla_vod_'+iplaVodId+'" href="'+iplaUrl+'" style="outline:none;">';
	if(size == 0){
		text +='<img style="border:1px solid #89b335;" src="'+smallImg+'" alt="'+iplaUrl+'" />';
		$('div.w-images a').removeClass('sel');	
		$('div.w-images a.small').addClass('sel');		
	}else{
		text +='<img style="border:1px solid #89b335;" src="'+bigImg+'" alt="'+iplaUrl+'" />';
		$('div.w-images a').removeClass('sel');	
		$('div.w-images a.big').addClass('sel');		
	}
	text +='</a>\n';
	text +='';
	text +='<!--Koniec IPLA VOD -->';
	$('#w-overlay-image .scroller_wrapper .desc2').text(text);
}


function iplaPasteTrailer(ide){
	var text = '';
	text +='<!-- Start IPLA TRAILER -->\n';
	text +='<script type="text/javascript" src="http://www.ipla.tv/templates/iplatv/wklejki/js.js"></script>\n';
	text +='<div id="div-'+ide+'"></div>\n';
	text +='<script type="text/javascript">\n';
	text +='embedIplaTrailer("'+ide+'");\n';
	text +='</script>\n';
	text +='<!-- Koniec IPLA TRAILER -->';
	$('#w-overlay').show();
	$('#w-overlay').click(function(){overlayClose('w-overlay-trailer');});
	$('#w-overlay-trailer .scroller_wrapper .desc2').text('');
	$('#w-overlay-trailer .scroller_wrapper .desc2').text(text);
	$('#w-overlay-trailer').show();
	clip = new ZeroClipboard.Client();
	clip.setHandCursor( true );
	clip.addEventListener('mouseOver', function(client) {clip.setText( document.getElementById('trailer-overlay-txt').value );});
	clip.glue( 'd_clip_button-t', 'd_clip_container-t' );
}




/* WKLEJKI END*/
