$(document).ready(function(){
     // Change the image of hoverable images
     $(".imgHoverable").hover( function() {  
         var hoverImg = HoverImgOf($(this).attr("src"));
         $(this).attr("src", hoverImg);
       }, function() {
         var normalImg = NormalImgOf($(this).attr("src"));
         $(this).attr("src", normalImg);
       }
     );




    $("#newsletter-form .formmailing").focus(function(){
        if($(this).attr("value") == $(this).attr("title")){
            $(this).attr("value","");
        }
    });

    $("#newsletter-form .formmailing").blur(function(){
        if($(this).attr("value") == ""){
            $(this).attr("value",$(this).attr("title"));
        }
    });

	$("#newsletter-form").submit(function(){
		$("#newsletter-bt").hide();
		$("#newsletter-ajax-loader").html("<img src=\"/images/newsletter-ajax-loader.gif\" />");
		var data = {};
		data['email'] = $("input[name=Email]", this).val();
		$.post("/tool/mailing-subscribe", data,
			function(result){
				$("#newsletter-bt").show();
				$("#newsletter-ajax-loader").html('');
				$("#newsletter-result").html(result);
				$("input[name=Email]").val("")
			}, 
			"html"
		);
		return false;
	});
	
	$("#print-button").click(function(){
		var printUrl = window.location.pathname + (window.location.search.length ? window.location.search + "&" : "?") + "p=true";
		window.open(printUrl, 'win', 'location=1,status=1,scrollbars=1,width=980,height=700');
		return false;
	});
	
	$(".send-link-button").click(function(){

		var dialog = $("#send-link-dialog");
		dialog.load("/tool/send-link-form");
		dialog.dialog({
			bgiframe: true,
			autoOpen: false,
			modal: true,
			width: 508,
			minHeight: 150,
			draggable: false
		});
		dialog.dialog("open");
		return false;

	});
	
	$(".contact-button,#napiste-nam-id,#poslat-otazku-id").click(function(){

		var dialog = $("#contact-dialog");
		dialog.load("/tool/contact-form");
		dialog.dialog({
			bgiframe: true,
			autoOpen: false,
			modal: true,
			width: 508,
			minHeight: 150,
			draggable: false
		});
		dialog.dialog("open");
		return false;

	});
	
	$(".leave-contact-button,#zavolame-vam-id").click(function(){

		var dialog = $("#leave-contact-dialog");
		dialog.load("/tool/leave-contact-form");
		dialog.dialog({
			bgiframe: true,
			autoOpen: false,
			modal: true,
			width: 508,
			minHeight: 150,
			draggable: false
		});
		dialog.dialog("open");
		return false;

	});

	$("#SearchForm .form-search").focus(function(){
        if($(this).attr("value") == $(this).attr("title")){
            $(this).attr("value","");
        }
    });

   	$("#SearchForm .form-search").blur(function(){
        if($(this).attr("value") == ""){
            $(this).attr("value",$(this).attr("title"));
        }
    });
	
	$("#SearchForm").submit(function(){
		if($('#term_id').val().length < 3 || $('#term_id').val() == $('#term_id').attr("title")){
			return false;
		} 
	});

	$("#menu li.dir").hover(
		function(){
			$("a:first", this).addClass("on-hover");
		},
		function(){
			$("a:first", this).removeClass("on-hover");
		}
	);
	
	$("#sliderlink").click(function () {
		if ($("#show_hide_menu").is(":visible") == true){
			$("#show_hide_menu").animate({"height": "hide"}, {duration: 500});                
			$("#sliderlink").removeClass("hide").addClass("show"); 
		} 
		else {
			$("#show_hide_menu").animate({"height": "show"}, { duration: 500 });    
			$("#sliderlink").removeClass("show").addClass("hide");
		}
		return false;
	});

	$("#clasp-1").click(function () {
		if ($("#lunch-1-show").is(":visible") == true){
			$("#lunch-1-show").animate({"height": "hide"}, {duration: 500});                
		} 
		else {
			$("#lunch-1-show").animate({"height": "show"}, { duration: 500 });    
		}
		return false;
	});

	$("#clasp-2").click(function () {
		if ($("#lunch-2-show").is(":visible") == true){
			$("#lunch-2-show").animate({"height": "hide"}, {duration: 500});                
		} 
		else {
			$("#lunch-2-show").animate({"height": "show"}, { duration: 500 });    
		}
		return false;
	});

	$("#clasp-3").click(function () {
		if ($("#lunch-3-show").is(":visible") == true){
			$("#lunch-3-show").animate({"height": "hide"}, {duration: 500});                
		} 
		else {
			$("#lunch-3-show").animate({"height": "show"}, { duration: 500 });    
		}
		return false;
	});

	$("#clasp-4").click(function () {
		if ($("#lunch-4-show").is(":visible") == true){
			$("#lunch-4-show").animate({"height": "hide"}, {duration: 500});                
		} 
		else {
			$("#lunch-4-show").animate({"height": "show"}, { duration: 500 });    
		}
		return false;
	});

	$("#clasp-5").click(function () {
		if ($("#lunch-5-show").is(":visible") == true){
			$("#lunch-5-show").animate({"height": "hide"}, {duration: 500});                
		} 
		else {
			$("#lunch-5-show").animate({"height": "show"}, { duration: 500 });    
		}
		return false;
	});

	/* ------------------------------------
    HOME PAGE SLIDES
--------------------------------------*/
    var activeSlide = 1;

    $("#home-slides-thumbs .item").mouseover(function(){
        id = $(this).attr("id");
        id = id.substring(id.length-1,id.length);
        offset = (190 * (id-1)) + 85;
        goTo = offset + "px";
        $('#home-slides-indicator span').stop();
        $('#home-slides-indicator span').animate({
            left: goTo
          },
          { duration: 200 }
        );
    });

    $("#home-slides-thumbs").mouseout(function(){
        offset = (190 * (activeSlide - 1)) + 85;
        goTo = offset + "px";
        $('#home-slides-indicator span').stop();
        $('#home-slides-indicator span').animate({
            left: goTo
          },
          { duration: 200 }
        );
    });
    
    $("#home-slides-thumbs .item").mouseover(function(){
        id = $(this).attr("id");
        id = id.substring(id.length-1,id.length);
        if(id != activeSlide){
            $("#home-slides #slide-" + activeSlide).fadeOut('slow');
            $("#home-slides #slide-" + id).fadeIn('slow');
            activeSlide = id;
        }
    });
	
	$(".menutree li:last").addClass("last");
	
	// on site search engine referrer highlight
	var d = document.domain;
	var d = d.split(".");
	var d = d.join("\\.");
	
	var options = {
		exact: "partial",
		style_name_suffix: false,
		highlight: "#content-section2",
		nohighlight: ".nohighlight",
		engines: [new RegExp("^http:\\/\\/" + d, "i"),/q=([^&]+)/i]
	}
		
	$(document).SearchHighlight(options);

   
});

    /* ------------------------------------
    Change the image of hoverable images
    --------------------------------------*/
            
    function HoverImgOf(filename)
    {
       var re = new RegExp("(.+)_off\\.(jpg)", "g");
       return filename.replace(re, "$1_on.$2");
    }
    function NormalImgOf(filename)
    {
       var re = new RegExp("(.+)_on\\.(jpg)", "g");
       return filename.replace(re, "$1_off.$2");
    }

