function createPopup(module,itemID) {
    $("#popup-recommend .iframe").html('<iframe src="'+htaccess_rule+'modules/recommend-'+module+'.php?itemID='+itemID+'" width="470" height="365" frameborder="0"></iframe>');
    centerPopup("#popup-recommend");
    showPopup();
}

function showInfo(){
    $("#overlay").css("display","block");
	$("#popup").css("display","block");
}


function hideInfo(){
    $("#overlay").css("display","none");
	$("#popup").css("display","none");
}

function showPopup(){
    $("#overlay").css("display","block");
	$("#popup-recommend").css("display","block");
}

function hidePopup(){
    $("#overlay").css("display","none");
	$("#popup-recommend").css("display","none");
}

function centerPopup(selectorId){    
    var windowWidth = document.documentElement.clientWidth;  
    var windowHeight = document.documentElement.clientHeight;  
    var popupHeight = $(selectorId).height();  
    var popupWidth = $(selectorId).width();  
    
    
    $(selectorId).css({    
        "top": (windowHeight/2-popupHeight/2),  
        "left": windowWidth/2-popupWidth/2  
    });    
    
}

this.tooltip = function(){	
			
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append('<div id="tooltip"><div class="left">&#160;</div><div class="middle"><p>'+ this.t +'</p></div><div class="right">&#160;</div></div>');
		var pos = $(this).position();
		if(jQuery.browser.msie)
		{
            var left = pos.left + 150;
            var top = pos.top + 30;    
        }
        else
		{
            var left = pos.left;
            var top = pos.top;
        }
        /*var left = pos.left;
        var top = pos.top;*/
        //alert("top: "+top+", left: "+left)
		$("#tooltip")
			.css("top",top + "px")
			.css("left",left + "px")
			.fadeIn("fast");		 
    },
	function(){
		this.title = this.t;		
		$("#tooltip").fadeOut("fast");
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - 20) + "px")
			.css("left",(e.pageX + 20) + "px");
	});			
};

$(document).ready(function() { 
    tooltip();
    $(".teacher2school-table tr").mouseover(function(){
        $(this).addClass("hover");
    });
    $(".teacher2school-table tr").mouseout(function(){
        $(this).removeClass("hover");
    });
    
    $("form input.button").mouseover(function(){
        $(this).addClass("button-hover");
    });
    $("form input.button").mouseout(function(){
        $(this).removeClass("button-hover");
    });
    if(jQuery.browser.msie && jQuery.browser.version < "7.0"){
        $(".nav ul li.last").mouseover(function(){
            $(this).addClass("hover");
        });
        
        $(".nav ul li.last").mouseout(function(){
            $(this).removeClass("hover");
        });   
    }
    
    $("#tabs a.blue").click(function(){
        $("#find-school-form").fadeIn("slow");
        $("#find-teacher-form").fadeOut("slow");
        $(this).blur();
        $(".error").html("").css({"top": "30px","opacity": 0});
    });
    
    $("#tabs a.red").click(function(){
        $("#find-school-form").fadeOut("slow");
        $("#find-teacher-form").fadeIn("slow");
        $(this).blur();
        $(".error").html("").css({"top": "30px","opacity": 0});
    });
    
    var overlay = '<div id="overlay">&#160;</div>';
    var popup = '<div id="popup"><p>Data se načítají...</p><img src="'+htaccess_rule+'gfx/ajax-loader.gif"/></div>';
    
    $("body").append(overlay);
    
    $("#overlay").width( $(document).width() );
    $("#overlay").height( $(document).height() );
    $("#overlay").css('opacity','0.3');
    
    
    $("body").append(popup);
    centerPopup("#popup");
    
    $(document).keypress(function(e){  
        if(e.keyCode==27){  
            hidePopup();  
        }  
    });
    
    var path = htaccess_rule + 'jquerychained/region-city.php';
    
	$('#kraj').chainSelect('#city',path,
	{ 
		before:function (target)
		{ 
			showInfo(),2000;
		},
		after:function (target)
		{ 
            setTimeout("hideInfo()","1000");
            if($("#kraj").val()=="all")
                $("#city").attr("disabled",true);
            else
                $("#city").attr("disabled",false);
		}
	});
    
    if($(".rate-form textarea").length)
        $(".rate-form textarea").maxlength({  
            events: [], // Array of events to be triggerd   
            maxCharacters: 150, // Characters limit  
            status: true, // True to show status indicator bewlow the element   
            statusClass: "count-chars", // The class on the status div 
            statusText: "ZBÝVÁ ZNAKŮ:", // The status text 
            notificationClass: "notification",  // Will be added when maxlength is reached 
            showAlert: false, // True to show a regular alert message   
            alertText: "Zadali jste příliš mnoho znaků.", // Text in alert message  
            slider: false // True Use counter slider   
        });
    if($(".recommend-popup-form textarea").length)
        $(".recommend-popup-form textarea").maxlength({  
            events: [], // Array of events to be triggerd   
            maxCharacters: 200, // Characters limit  
            status: true, // True to show status indicator bewlow the element   
            statusClass: "count-chars", // The class on the status div 
            statusText: "ZBÝVÁ ZNAKŮ:", // The status text 
            notificationClass: "notification",  // Will be added when maxlength is reached 
            showAlert: false, // True to show a regular alert message   
            alertText: "Zadali jste příliš mnoho znaků.", // Text in alert message  
            slider: false // True Use counter slider   
        });
        
    $("#find-teacher-form").submit(function(){
        if($("input[name='n']").val() == "" && $("input[name='s']").val() == ""){
            $(".error").html("- zadejte jméno nebo příjmení učitele");
            $(".error").animate({
                opacity: 1,
                top: "15px"
            },1000);
            return false;
        }
    });  
    
    $("#find-school-form").submit(function(){
        if($("input[name='qs']").val() == ""){
            $(".error").html("- zadejte název školy");
            $(".error").animate({
                opacity: 1,
                top: "15px"
            },1000);
            return false;
        }
    });
    
    
    var sortTriggered = false;
    
    $(".sort-trigger").click(function(event){
        event.stopPropagation();
        $(".sort ul").slideToggle();
    });
    
    $(document).click(function(event) {
        $(".sort ul").slideUp();
    });
     
     
    if(jQuery.browser.mozilla){
        $("form input.button").css("padding-bottom","2px");
    } 
    
    $(".teacher2school-table td.sort-td a.tooltip img:not('.active')").mouseover(function(){
        var fileName = $(this).attr('src');
        $(this).attr('src', fileName.replace('.png', '_hover.png'));    
    });
    
    $(".teacher2school-table td.sort-td a.tooltip img:not('.active')").mouseout(function(){
        var fileName = $(this).attr('src');
        $(this).attr('src', fileName.replace('_hover.png', '.png'));    
    });
    
    /* mlink */
    $(".col-right table").attr("cellpadding","0");
    $(".col-right table").attr("cellspacing","0");
    
});
function countAverageRate()
{
    var s1 = $("#utulnostHidden").attr("value");
    var s2 = $("#stravovaniHidden").attr("value");
    var s3 = $("#vybaveniHidden").attr("value");
    var s4 = $("#vzdelavaniHidden").attr("value");
    var s5 = $("#spolupraceHidden").attr("value");
    var s6 = $("#naladaHidden").attr("value");
    
    var averageRateFloat = (parseInt(s1) + parseInt(s2) + parseInt(s3) + parseInt(s4) + parseInt(s5) + parseInt(s6))/6;
    var averageRateFloat100 = averageRateFloat * 100;
    var averageRate = (Math.round(averageRateFloat * 100))/100;
    $(".rate").html(averageRate);
}
