var lng = false;
var txt = new Array();
txt[0] = ["Filtrování titulů","Filter the titles"];

$(document).ready(function(){
	
	if($("#page.print").length > 0) {
		if(confirm("Přejete si vytisknout tuto stránku?")) {
			window.print();
		}
	}
	
	$('a[rel=showlink]').click(function(){
		$(this).replaceWith(this.href);
		return false;
	});
	
	if($("#cnbox").length > 0) {
    $("#cnbox").jScrollPane();
	}
	
	lng = $("#page").hasClass("cs") ? 0 : 1;
	
	lightboxes();
	pgContacts();
	pgNews();
	searchForm();
	tbcwFilter();
});

this.searchForm = function() {
	
	$(".fBtns input").hide();
	
	$("#todow").click(function(){
		if($(this).parent().hasClass("fBtnsRev")) {
			$(this).parent().removeClass("fBtnsRev");
			$("#Ffs_todow").attr("checked","true");
			$("#Ffs_todoa").attr("checked","false");
		}
	});
	
	$("#todoa").click(function(){
		if(!$(this).parent().hasClass("fBtnsRev")) {
			$(this).parent().addClass("fBtnsRev");
			$("#Ffs_todow").attr("checked","false");
			$("#Ffs_todoa").attr("checked","true");
		}
	}); 
	
	$("#frmSearch").submit(function(){
		if($(this).find("input#Ffs_todoa").attr("checked")) {
			$("#frmSearch").attr("action","http://archive.vaclavhavel-library.org/kvh_search/search.jsp");
		}
		
	});
}

this.lightboxes = function() {
	
	// lb musi byt <a rel="lightbox-galerie"..
	
	str = '';
	$('a[rel^=lightbox]').each(function(){
		uq = $(this).attr("rel").substr(9);
		if(str.indexOf("<" + uq + ">") == -1) {
			str += "<" + uq + ">";
		}
	});
	gals = str.substr(1, str.length-2).split("><");
	
	for(i = 0; i < gals.length; i++) {
		$("a[rel=lightbox-" + gals[i] + "]").lightBox({
			containerResizeSpeed: 400,
			txtImage: "Obrázek / Image :",
			txtOf: "/",
			imageLoading: "/img/lb-loading.gif",
			imageBtnClose: "/img/lb-btn-close.gif",
			imageBtnPrev: "/img/lb-btn-prev.gif",
			imageBtnNext: "/img/lb-btn-next.gif",
			imageBlank: "/img/empty.gif"
		});
	}

}

this.pgContacts = function() {

	if($("#mapLinks").length > 0) {
		 
		$(".mapChange").hover(function(){
			h = this.href;
			t = this.title;
			i = this.rel;
			$("#map").each(function(){
				$(this).attr("href", h);
				$(this).attr("title", t);
				$(this).find("img").attr("src", "/img/" + i + ".png");
				$(this).find("img").attr("alt", t);
			});
		}, false);
	 
	
	}

}

this.pgNews = function() {

	$(".pgNews .artsListItem, .pgCalendar .eventsListItem").hover(function(){
		$(this).find(".tinyicons").show();
	}, function(){
		$(this).find(".tinyicons").hide();
	});

}

this.tbcwFilter = function() {
	
	if(!$("table.tbCW").length) { return false; }
	
	$("table.tbCW").before('<div id="cwFilter"><label for="tbCWFilter">' + txt[0][lng] + ': </label><input id="tbCWFilter" name="filter" value="" /></div>');
	$("#tbCWFilter").each(function(){this.focus();})
	if(!$("#tbCWFilter").length) { return false; }
	
	$("#tbCWFilter").keyup(function(){	
		$(".tbCW tr").show();
		$(".tbCW tr").not('tr[title*=' + $(this).val().toLowerCase() + ']').hide();
	});
	
	var trtit;
	$(".tbCW tr").hover(function(){
		trtit = $(this).attr("title");
		$(this).removeAttr("title");
	}, function(){
		$(this).attr("title", trtit);
		trtit = false;
	} );
	

}

