$(document).ready(function() {
if(!jQuery.browser.msie)$('#fb_main').html('<script type="text/javascript" src="http://static.ak.connect.facebook.com/connect.php/pl_PL"></script><script type="text/javascript">FB.init("cc7a23dac02229269ed1448fa9d08251");</script><fb:fan profile_id="233594943714" stream="0" connections="10" logobar="1" width="300"></fb:fan>');
if($('#r').height()<160)$('#r').css({'padding-top':'50px','height':'80px','margin-bottom':'-50px','padding-top':'45px','position':'relative','top':'-18px'});	
	var count = 1;
	/*ile jest newsów*/
	var ile = 0;
	$.ajax({
				url: '/newsy/ile.php',
				success:function(data){
					ile = data;
				}
			});
	$('#newsTxt').live("click",function(){
		window.location=$(this).prev().attr('href');
	});
	$('#next').click(function(){
    	count+=1;
		if (count > ile) count = 1;
        chng(count);
		pageTracker._trackPageview("nextArt"); 
    });
	$('#back').click(function(){
        count-=1;
		if (count == 0) count = ile;
        chng(count);
		pageTracker._trackPageview("prevArt"); 
    });
	$('#nextFilm').click(function() {
		pageTracker._trackPageview("nextFilm"); 
		window.location.reload();
	});
	$('#tg li:last a').css('background','none');
		$('#rt').click(function(){
		$.ajax({
		   type: "POST",
		   url: "zapisz_klik.php",
		   data: "place=rt"
		});
	});
	$('#tright form').submit(function(){
		emailReg = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
		if(!emailReg.test($('#tright form input[name=mail]').val())){
			gg('Nieprawidłowy adres e-mail');
			return false;
		}
		else{
			 $.ajax({
				url: $(this).attr('action'),
				type: $(this).attr('method'),
				data: '&mail='+$('input[name=mail]').val(),
				success:function(data){
					gg('Twój mail został dopisany do naszej bazy.<br/>Będziesz otrzymywał nasz newsletter raz na 2 tygodnie');
					return false;
				}
			}); 
			return false;
		}
	});
$('#menu a:last').click(function(){
_gaq.push(['_trackEvent','event','klik-megapower',document.location.pathname]);
window.open(this.href); 
return false;
});
});
function chng(count) {
$('#newsTxt').prev().remove();
$('#newsTxt').remove();
$.ajax({
url: "newsy/"+count+".htm",
type: 'GET',
success: function(html){
$('#imgNews').prepend(html);
}
}); 
}
function split (html) {
				html = replace(html,"\n","");
				html = replace(html,"\r","");
				reg1 = /^\<a href(.*)?a\>/;
				reg2 = /^[^&]+\<span(.*)?p\>/;
				reg3 = /^\<a href=\"(.*)?\"/;
				wynik1 = html.match(reg1);
				wynik2 = html.match(reg2);
				wynik3 = html.match(reg3);
				obrazek = '<a href'+wynik1[1]+'a>';
				tekst = "<span"+wynik2[1]+"p>";
				wynik = new Array();
				wynik[1] = obrazek;
				wynik[2] = tekst;
				wynik[3] = wynik3;
				return wynik;
}
function replace(string,text,by) {
	var strLength = string.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return string;
	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0,txtLength))) return string;
	if (i == -1) return string;
	var newstr = string.substring(0,i) + by;
	if (i+txtLength < strLength)
	newstr += replace(string.substring(i+txtLength,strLength),text,by);
	return newstr;
}
function gg(napis){
$('body').prepend('<div id="cover" style="position:fixed;_position:absolute;top:0;left:0;height:'+screen.height+'px;width:'+screen.width+'px;background-color:#000;filter:alpha(opacity=75);opacity:0.75;z-index:10"></div>');
$('body').prepend('<div id="getka" style="position:absolute;top:50%;left:50%;background-color:#fff;z-index:11;border:5px solid #ddd;padding:50px"><strong id="close" style="position:absolute;right:5px;top:3px;cursor:pointer">X</strong>'+napis+'</div>');
$('#getka').css({'margin-top':-($('#getka').height()/2+40),'margin-left':-($('#getka').width()/2+40),'width':$('#getka').width()});
$('#getka #close').click(function(){
$('#getka,#cover').remove();
});
}