$(document).ready(function(){

  //$(".submenu").append("<div class=\"clearboth\"></div>");

  $(".openpage").live("click",function(){
    $(".content_in").load("load.php"+$(this).attr("href"));
    return false;
  });

  $(".datepicker").datepicker({
    dateFormat: 'yy-mm-dd',
    showAnim: ''
  });


  //bublina
 
  $(".hover").live("mouseover",function(e){
    var bub = "#bub_"+$(this).attr("id");
    //var leftVal = e.pageX + 5 + "px";
    //var topVal = e.pageY + 5 + "px";
    /*if($(this).hasClass("load_bub")){
	 //$(".load_bub").hover(function (){
	      var rel=$(this).attr("rel");
	      $(bub).html("Načítá se...");
	      $(bub).load(rel);
	  //});
    
    }*/
    
	    var leftVal = e.pageX + 5;
    	var topVal = e.pageY + 5;
    	if(leftVal+$(bub).width()+5-$(document).scrollLeft() > $(window).width()){
    		var leftVal=$(window).width() - 30 - $(bub).width() + $(document).scrollLeft();
    	}
    	if(topVal+$(bub).height()+5-$(document).scrollTop() > $(window).height()){
    		var topVal=$(window).height() - 20 - $(bub).height() + $(document).scrollTop();
    	}
    	if(leftVal<5){var leftVal=5;}
    	if(topVal<5){var topVal=5;}
    	var leftVal = leftVal + "px";
    	var topVal = topVal + "px";    
    
    
    $(bub).css({left:leftVal,top:topVal});
    $(bub).show();
  });
  
  $(".hover").live("mouseout",function(){
    var bub = "#bub_"+$(this).attr("id");
    $(bub).hide();
  });
  //konec bublina
  
  $(".bublina").live("click",function(){
    $(this).hide();
  });
  
  //vysouvaci menu
  $('.hover1').livequery(function(){ 
    // use the helper function hover to bind a mouseover and mouseout event 
        $(this).hover(function() { 
                var bub = "#pod_"+$(this).attr("id");
                $(bub).show();
            }, function() { 
                var bub = "#pod_"+$(this).attr("id");
                $(bub).hide(); 
            }); 
    }, function() { 
        // unbind the mouseover and mouseout events 
        $(this) 
            .unbind('mouseover') 
            .unbind('mouseout'); 
    }); 
  //
  
 
  $(".load_bub").hover(function (){
      var rel=$(this).attr("rel");
      var id=$(this).attr("id");
      $("#bub_"+id).html("Načítá se...");
      $("#bub_"+id).load(rel);
  });
  
  //přepis časů ve formuláři do formátu
  $('.form_time').keyup(function(){
    var val=$(this).attr('id');
    var h=$('#'+val+' .h').val()*1;
    var m=$('#'+val+' .m').val()*1;
    var s=$('#'+val+' .s').val()*1;
    $('.'+val).val(h+':'+m+':'+s);
  });
  
  //přepis časů ve formuláři na minuty
  $('.form_min').keyup(function(){
    var val=$(this).attr('id');
    var h=$('#'+val+' .h').val()*1*60;
    var m=$('#'+val+' .m').val()*1;
    var s=$('#'+val+' .s').val()*1/60;
    var hodn=Number(h+m+s);
    $('.'+val).val(hodn);
  });
  
  //kopírování řádku tabulky do "schránky"
  $(".copy_tbl").live("click",function(){
    var id=$(this).attr("id");
    var tbl=$(this).attr("rel");
    $.get('tbl/scripts/copy.php', { tbl: tbl, id: id }, function(data){
      if(data=="1"){
        $("#"+id).append("<b class=\"copy_ok\">&nbsp;&nbsp;OK</b>");
        $(".copy_ok").fadeOut("slow");
        $(".paste_tbl").fadeIn("slow");
      }
    });
    return false;
  });
  
  $(".ookno").live("click",function(){
        var cl=$(this).attr("class");
        var param=cl.split(" ");
        var size=param[1].split("x");
        var href=$(this).attr("href");
        var nick=$(this).attr("name");
        var okno=window.open(href, nick, 'width='+size[0]+', height='+size[1]+', resizable=yes, scrollbars=yes');
        vyska = screen.height;
        sirka = screen.width;
        var levy = (sirka - size[0])/2;
        var horni = (vyska - size[1])/2;
        okno.moveTo(levy, horni);
        okno.focus();
        return false;
  });
  
  //přihlašovací formulář
  /*$("form[name='login_form'] > .input_top").focus(function(){
      if($(this).val()=="nick"){
        $(this).css({"color": "black"});
        $(this).val("");
      }
      if($(this).val()=="heslo"){
        $(this).hide();
        $(".input_top.password").show().focus();  
      }
  });
  $("form[name='login_form'] > .input_top").blur(function(){
      if($(this).attr("name")=="pass" && $(this).val()==""){
        $(this).hide();
        $(".input_top.text").show(); 
      }
      if($(this).attr("name")=="nick" && ($(this).val()=="" || $(this).val()=="nick")){
        $(this).css({"color": ""});
        $(this).val("nick");
      }
  });*/
  
  $("form[name='loginform'] > input").focus(function(){
      if($(this).val()=="nick"){
        //$(this).css({"color": "black"});
        $(this).val("");
      }
      if($(this).val()=="heslo"){
        $(this).hide();
        $("input.password").show().focus();  
      }
  });
  $("form[name='loginform'] > input").blur(function(){
      if($(this).attr("name")=="pass" && $(this).val()==""){
        $(this).hide();
        $("input.text").show(); 
      }
      if($(this).attr("name")=="nick" && ($(this).val()=="" || $(this).val()=="nick")){
        //$(this).css({"color": ""});
        $(this).val("nick");
      }
  });
  
   
});
