  function show(id){document.getElementById(id).style.display='block';}
  function hide(id){document.getElementById(id).style.display='none';}
  $(document).ready(function()
    {
    $("#mainmenu li:has(ul)").hover(function()
        {
        $(this).children("ul").css("display", "none");
        $(this).children("ul").css("z-index", "10000");
        $(this).children("ul").animate({opacity: 0.9}, 250);
        $(this).children("ul").show();
        },
    function()
    {
      $(this).children("ul").slideUp("fast");
      $(this).stop();
    });
    
     
    function showhide() {
      $(".showhide").hide();
      $(window.location.hash).show();
      $("#mainbottom").hide();
      $("#mainbottom").show();
      $(".jactive").removeClass("jactive");
      hash = window.location.hash;
      $("a[rel='"+hash+"']").parent().addClass("jactive");    
    }
    
    $("#w3-contactform").submit(function(){
    
      name = $("#name").attr("value");
      mail = $("#mail").attr("value");
      text = $("#message").val();
      
      message = '';
      
      if(name == '' || mail == '' || text == '') {
        message = message + 'Musíte vyplniť všetky polia.\n';
      }
            
      at = mail.indexOf("@");
      dot = mail.lastIndexOf(".");
      if (at == -1 || dot == -1) {
        message = message + 'Zadajte prosím platnú emailovú adresu\n';
      }
      
      if(message != '') {
        alert(message);
        return false
      }      
    })
  
    $("#mailerform").submit(function() {
      value = $("input[name='mailing']").attr("value");
      at = value.indexOf("@");
      dot = value.lastIndexOf(".");
      if (at == -1 || dot == -1) {
        alert('Zadajte prosím platnú emailovú adresu\n');
        return false;
      }
    })
    $("input[name='mailing']").focus(function() {
      $(this).attr("value","@");
    },
    function(){
      alert('a');
    })
    $(".show").bind("click", function() {
      $(".showhide").hide();
      $(".jactive").removeClass("jactive");
      hash = $(this).attr("rel");
      $("a[rel='"+hash+"']").parent().addClass("jactive");
      $(hash).show();
      $(this).parent().parent(".w3-hidden").slideUp("fast");
      $("#mainbottom").hide();
      $("#mainbottom").show();
    })
     
    if(window.location.hash != '') {
      if ( $("#cennik").length > 0 ) {
        $("#cennik tr").hide();
        hash = '.' + window.location.hash.substr(1);
        $(hash+' ,.cennik-header').show();
      }
      showhide();
    }
    
    $("map area").mouseover(function() {
      rel = $(this).attr("rel").split(";");
      image = "url(\"./images/bytovka/"+rel[0]+".jpg\")";
      $("#blank").css("background-image", image);
      $("#blank").css("background-position", rel[1]+"px "+rel[2]+"px");
      return false;
    });
    $('map area').mouseout(function() { 
      $("#blank").css("background-image", "none");
    });
    image = new Array();
    $("map area").each( 
      function(intIndex) { 
        preload = $(this).attr("rel").split(";");
        link = "./images/bytovka/"+preload[0]+".jpg";
        image[intIndex] = new Image();
        image[intIndex].src = link;
      }
    );
    
    $("#cennik-form select").change(function(){
      $("#cennik tr").show();
      vchod = $("#vchod option[selected]").attr("value");      
      poschodie = $("#poschodie option[selected]").attr("value");
      cena = $("#cena option[selected]").attr("value");
      pocetizieb = $("#pocet-izieb option[selected]").attr("value");
      
      vchod = 'v'+vchod;
      poschodie = 'p'+poschodie;
      cena = 'c'+cena;
      pocetizieb = 'pi'+pocetizieb;
      
      $(".cennik-header").show();
      $("#cennik .vall").hide();
      $("."+vchod).attr("rel","filter");
      $("."+poschodie).hide();
      $("."+poschodie+"[rel='filter']").show();
      
      $("#cennik .vall:visible").attr("rel","filter1");
      $(".call").hide();
      $("."+cena+"[rel='filter1']").show();
      
      $("#cennik .vall:visible").attr("rel","filter2");
      $(".piall").hide();
      $("."+pocetizieb+"[rel='filter2']").show();
      
      $("#cennik .vall").attr("rel","");
    })
    $(".viac").hover(
      function(e) {
        id = $(this).attr("rel");
        $("#viac"+id).show();
        mousey = e.pageY - 350;
        mousex = e.pageX - 440;
        $("#viac"+id).css("position", "absolute");
        $("#viac"+id).css("top", mousey);      
      },
      function() {
        $("#viac"+id).hide();
      }
    );
    $(".j-reload").click(function() {
      hash = $(this).attr("rel");
      window.location = hash;
      window.location.reload()
    });
  })
  
  $(window).load(function () {
    $(".w3-loading").hide();
    $(".rolloverimage").fadeIn(1000);
    $("#w3media").show();
    $("#googlemap").css("background-image","none");
    gload();
  });
  $(window).unload(function () {
    GUnload();
  });
