$(document).ready(function() {

  setFooter();

	$(window).resize(function() {
// 		delay(function(){
		  setFooter();
// 		}, 500);
	});





  $("div.menu_item").hover(
    function() {
//      alert("in");
      var id = $(this).attr("id");
      id = id.substr(3);
//      alert(id);
      $("div#submenu_"+id).css("display", "block");
    },
    function() {
//      alert("out");
      var id = $(this).attr("id");
      id = id.substr(3);
//        alert(id);
      $("div#submenu_"+id).css("display", "none");
    }
  );
});


function setFooter()
{
      var windowHeight = $(window).height();
      var contentHeight = $("#page").height();

      var ratio = windowHeight - contentHeight - 40;


      if(ratio > 0){
        $("#bottom").css("position","absolute");
        $("#bottom").css("padding-bottom","0px");
//         var top = windowHeight - 100;

        $("#bottom").css("bottom",10);
      }else{
        $("#bottom").css("padding-bottom","10px");
        $("#bottom").css("position","static");
//         $("#bottom").css("padding-bottom","40px");
      }
}


// při změně okna nastavíme víšku contentu
var delay = (function(){
	var timer = 0;
	return function(callback, ms){
		clearTimeout (timer);
		timer = setTimeout(callback, ms);
	};
})();


/**
   * AJAX Souhlas box formulář
   */
		function zobraz_podminky(idecko){
		el=document.getElementById(idecko).style;
		el.display=(el.display == 'block')?'none':'block';
		}

		function schovat_podminky(idecko){
		el=document.getElementById(idecko).style;
		el.display=(el.display == 'none')?'block':'none';
		}


  /**
   * AJAX Sekce
   */
   

	function handleAjaxQuery(query)
	{
   	http.open("GET", query, true);
  	http.onreadystatechange = handleHttpResponse;
  	http.send(null);
  }

	function sekce_getMesto()
  {
    subject_id 	 	 = "mesto";
    var select = document.getElementById("kraj");



  if (select) {
      var parentIdMesto = select.options[select.selectedIndex].value;
      $('#mestodiv').load("ajax.php?parentId=" + parentIdMesto + "&sekce=" + subject_id);
      
      var parentIdTermin = select.options[select.selectedIndex].value;
      $('#termindiv').load("ajax.php?parentId=" + parentIdTermin + "&sekce=" + subject_id);
      
      document.getElementById("logo_spirala").setAttribute("class", "spirala");

  	}
  }
  
  function sekce_getTermin()
  {
    subject_id = "termin";
    var select = document.getElementById("mesto");



  if (select) {
      var parentId = select.options[select.selectedIndex].value;
			$('#termindiv').load("ajax.php?parentId=" + parentId + "&sekce=" + subject_id);

      document.getElementById("logo_spirala").setAttribute("class", "spirala");
  	}
  }
  
  function sekce_getSpirala()
  {
    subject_id = "spirala";
		var select = document.getElementById("termin");
//     if (select) {

//       $('#logo_spirala').load("ajax.php?parentId=" + parentId + "&sekce=" + subject_id);
//     }
    
     var parentId = select.options[select.selectedIndex].value;
     
     $.ajax({
 		  url: "ajax.php?parentId=" + parentId + "&sekce=" + subject_id,
 		  success: function(data) {
				/*
				$('#logo_spirala').removeClass(data);
				$('#logo_spirala').addClass(data);
				*/
				$('#logo_spirala').attr("class", data);
		  }
   	});

  }


