function trim(str) {
	a = str.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
}

function get_home_url(){
	return $("base").attr("href");
}

function get_url_to_ajax(){
	return get_home_url()+"ajax/";
}

function print_page() {
	var homeurl = get_home_url();
	var href = window.location.href;
	var sufix = href.replace(homeurl, '');

	if(sufix.length == 0) sufix = '.html';
	else sufix = '/' + sufix;

	window.open(homeurl+'print'+sufix, '', 'width=800,height=600,left=0,top=0,scrollbars=1,resizable=1');
}

function recommend_page() {
	var homeurl = get_home_url();
	var href = window.location.href;
	var sufix = href.replace(homeurl, '');
	if(sufix.length == 0) sufix = 'index.html';
	window.open(homeurl+'polec/'+sufix, '', 'width=350,height=500,top=0,left=0,scrollbars=1,resizable=1');
}

function biuletyn(action) {

	var email = trim($("#b_email").val());

	if(email.length == 0) {
		alert("Proszę wpisać adres email");
	} else if(!email.match(/[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})/)) {
		alert("Podany adres email jest nieprawidłowy");
	} else {
		$.post(get_url_to_ajax()+'biuletyn.html',
		$("#form_biuletyn").serialize()+'&action='+action,
		function(data) {
			$("#biuletyn").html(data);
		});
	}

}

function binfo() {

	if($("#biuletyn_opis").css('display') != 'none') {
		$("#brozwin").attr('title', 'Pokaż informacje o biuletynie');
	} else {
		$("#brozwin").attr('title', 'Ukryj informacje o biuletynie');
	}
	$("#biuletyn_opis").slideToggle(500);

}

var sentencja_ch;
var litera;
var txt;
var tmp;

$(document).ready(function() {

	$('a.zdjecie').lightBox({fixedNavigation:true});

	$('.menu_right, .menu_right_child').tooltip({showURL: false});

	sentencja_ch = 0;
	litera = 0;
	txt = $("#sentencja_text_hidden").html();
	tmp = $("#sentencja_text").html();
	if(txt != null) sentencja();

	// top dla gradientu u gory
	/*if($("#reklama_gora").html() != null && $("#reklama_gora").html().length != 0) {
		top = 124 + $(".reklama_img_gora img").height();
		$("body").css("background", "url(dom/gfx/main_bg_new.gif) repeat-x scroll 0 "+top+"px");
	}*/

});

function sentencja() {

	if(sentencja_ch == 0) {
		znak = txt.charAt(litera);

		if(znak == "#") tmp += "<br />";
		else if(znak == "^") tmp += "&#8222;";
		else if(znak == "$") tmp += "&#8221;";
		else tmp += znak;

		$("#sentencja_text").html(tmp);
		litera++;
		if(litera == txt.length) {
			sentencja_ch = 1;
			$("#sentencja").animate({"top":0}, 1500, function() {
				$("#sentencja_extra").slideDown(1000);
			});
			setTimeout("sentencja()", 10000);
		} else setTimeout("sentencja()", 50);
  } /*else {

		$("#sentencja").hide(1000, function() {
			$("#sentencja_text").html("");
			$("#sentencja_extra").hide();
			$("#sentencja").show();
			tmp = "";
			litera = 0;
			sentencja_ch = 0;
			setTimeout("sentencja()", 500);
		});
  	}*/

}

