﻿$(document).ready(function(){
	vysky();
	$("a[href^=mailto]").addClass("mail");
	$("a[href^=posta/?]").addClass("mail");
	$("a[href$=pdf]").addClass("pdf");
	$("a[href$=doc]").addClass("doc");
	$("a[href$=xls]").addClass("xls");
	$("a[href$=htm]").addClass("htm");
  $("a[href^=http]").each(function() {
    if(this.href.indexOf(location.hostname) == -1) {
      $(this).click(function(){window.open(this.href);return false;}).addClass("external");
    }
  });
$("#searchform").submit(function() {
	$('#searchtype').css({width:"0",height:"0"}).hide(); 
	$("#sloupecek").slideUp("slow");
	$("#content").animate({marginRight:"330"}, "slow");
	  if($("#sloupecek").is(':visible')) { $("#text").animate({marginRight:"0"}, "slow"); }
	$("#searchsubmit").focus();
	if($(".radio:checked").val()=='forum') { window.location="http://dolnibrezany.cz/vyhledavani/?q="+$("#searchinput").attr("value")+"&r=forum" } else {
	loadit("http://dolnibrezany.cz/vyhledavani/",  { q: $("#searchinput").attr("value"), o: "ajax", r: $(".radio:checked").val()}); }
   return false;
});
$("#searchinput").focus(function() {
	if( this.value == this.defaultValue ) {
		this.value = ""; }
	$("#searchtype").css({width:"183",height:"165"}).show("fast");
	$("#searchform").addClass("writing");
}).blur(function() {
	if( !this.value.length ) {
		this.value = this.defaultValue;
		$("#searchform").removeClass("writing");
	}
});
$("#closesearch").click(function() {
	  $(this).hide();
	  $("#searchresults").animate({opacity: "0"}, 300).children().remove();
	  $("#content").animate({marginRight:"15"}, "slow");
	  $("#sloupecek").slideDown("slow");
	  if($("#sloupecek").is(':visible')) { $("#text").animate({marginRight:"180"}, "slow"); }
	  return false;
   });
$(".showsub").click(function() {
	  $(this).next().next().slideToggle('normal', function() {vysky()});
	  return false;
});
$("table.zvyraznit tr").not(".malahlavicka").hover(
	function(){ $(this).css({backgroundColor:"#ddd"}); },
	function(){ $(this).css({backgroundColor:"#fff"}); }
);
$("p.zvyraznit").hover(
	function(){ $(this).css({backgroundColor:"#ebebeb"}); },
	function(){ $(this).css({backgroundColor:"#fff"}); }
);
$(".forum-prispevek.zvyraznit").hover(
	function(){ $(this).css({backgroundColor:"#ddd"}); },
	function(){ $(this).css({backgroundColor:"#ebebeb"}); }
);
$("table.list tr.tmavsi").hover(
	function(){ $(this).css({backgroundColor:"#ddd"}); },
	function(){ $(this).css({backgroundColor:"#ebebeb"}); }
);
$("table.list tr.svetlejsi").hover(
	function(){ $(this).css({backgroundColor:"#ddd"}); },
	function(){ $(this).css({backgroundColor:"#fff"}); }
);
$('#searchform').click(function(e) { 
	e.stopPropagation(); 
}); 
$(document).click(function() { 
	$('#searchtype').css({width:"0",height:"0"}).hide(); 
}); 
});

function loadit(path,query) {
	$("#closesearch").hide();
	$("#searchresults").slideUp().children().remove();
	$("#searchresults").append('<p class="grey">Načítám výsledky hledání...</p>');
	$("#searchresults").css({opacity: "0"}).animate({opacity: "+=1"}, 500).slideDown();
	$.get(path, query,
		function(data){
		$("#searchresults").children().remove();
		$("#searchresults").append(data);
		vysky();
		$("a.viaajax").click(function() {
		$('html').animate({scrollTop:0}, 800);
		loadit(this.href);
		return false;
		});
		$("#closesearch").show("slow");
	});
}

function vysky() {
	var sh=$("#sloupecek").height()+15;
	var th=$("#text").height()+15;
	var nh=$("#navigace").height()+15;
	var rh=$("#searchresults").height()+15;
	var xxxx=Math.max(sh,th,nh,rh);
	if(th<xxxx) { $("#text").animate({height:xxxx}, 300); }
}