$(document).ready(function() {  
      // Initialise the table dnd
      $("#table-1").tableDnD();  
      
	    $('#up').click(function(){
	        $('html, body').animate({scrollTop:0}, 'slow');
	        return false;
	    });
	    
	    //**********************SLIDE MENU**************//
	    //Pridaj pluska pre zavrete li
	    $('li.dir').each(function(){
        if(($(this).find('ul').css("display"))=="none"){
          $(this).html('+ ' + $(this).html());  
        }
      });
      $('li.dir').each(function(){
        if(($(this).find('ul').css("display"))=="block"){
          $(this).html('- ' + $(this).html());  
        }
      });

      $('li.dir').click(function(){
          $('li.dir').each(function(){
              $(this).html("+" + $(this).html().substr(1, $(this).html().length));  
          });          
          if(($(this).closest('li').find('ul').css("display"))=="block"){
            $(this).closest('li').find('ul').slideUp();
          }else{
            $(this).html("-" + $(this).html().substr(1, $(this).html().length));
            $(this).closest('li').find('ul').slideDown();
          }          
	        $(this).closest('li').siblings('li').find('ul').slideUp();	        
	    }); 
      
      //fade, slide ... page effects
      $('#content').hide();
      $('#content').fadeIn('fast');                                                                                             
	    

	    //**********************************
        $('.language, .language2').click(function () {
	       $('ul.languages').slideToggle('medium');
        });
        
     //***********************************
      	$("#im1, #im2, #im3, #im4, #im5, #tm1, #tm2, #tm3, #tm4, #tm5").hover(function() {
      	      
      	      var im = $(this).attr("title");              
              var i = "#"+im;
              $(i).css("display","block");             
        },
              function(){
      	      
      	      var im = $(this).attr("title");              
              var i = "#"+im;
              $(i).css("display","none");
              
              $(i).hover(function() {
              $(i).css("display","block");
              },function(){
              $(i).css("display","none");
              });
                          
                           
              }
        
        );
        
        
        

      
      //**********************************************
      //last submenu style for mac users
      if($.client.os == "Mac")
      {
      $("#last").css("margin-left","-60px");
      }
      
       if($.client.browser == "Opera")
      {
      $("#nav").css("margin-top","576px");
      $(".sip").css("vertical-align","middle");
      $(".sip").css("padding-bottom","5px");
      $(".ko_green img").css("vertical-align","bottom"); 
      }
      
      if($.client.browser == "Chrome")
      {
      $("#nav").css("margin-top","577px");
      }
      

     $("#krajselect").selectbox();
     $("#typselect").selectbox();
      
     $('#krajselect').change(function() {
        var kraj = $("#krajselect").val();
        $("#ap_ajax").load("ajax/aplikatori.php", { 'kraj': kraj } ).fadeIn('slow');
     });

      
          	 
	});
    //**********************************************
    jQuery(document).ready(function($) {
          $('a[rel*=facebox]').facebox({
            loadingImage : 'modules/facebox/loading.gif',
            closeImage   : 'modules/facebox/closelabel.png'
          })
        })



          	
  
    function ajax(id)
    {
    $("#ajax").load("ajax/mediabox.php", { 'id': id } ).hide().fadeIn("slow");
    }
    
    function auto_ajax(id, pos)
    {
    t = $("#ajax").load("ajax/mediabox2.php", { 'id': id, 'pos': pos } ).hide().fadeIn("slow");
    }
    
    function ref(page)
    {
    $("#ap_ajax").load("ref.php", { 'page': page } ).fadeIn('slow');
    }
    
    function ref2(typ, page)
    {
    $("#ap_ajax").load("ref.php", { 'typ': typ, 'page': page } ).fadeIn('slow');
    }
    
    
    
    
    
    function info(i) {
        var show = ".text"+i;
        //alert(im);
        if ($(show).is(":hidden")) {
        $(".re_gallery").slideUp("slow");
        $(".re_text").slideUp("slow");
        $(show).slideDown("slow");
        }
        
    };
    
     function gallery(i) {
        var show = ".gal"+i;
        //alert(im);
        if ($(show).is(":hidden")) {
        $(".re_gallery").slideUp("slow");
        $(".re_text").slideUp("slow");
        $(show).slideDown("slow");
        }
        
    };
    
     function close() {
        $(".re_text").slideUp("slow");
        $(".re_gallery").slideUp("slow");
        
    };
    
    /*
    function tip()
    {
    $("#tip").load("ajax/tip.php").hide().fadeIn('slow');
    }
    tt = setTimeout("tip()",5000); */
    
    function slideSwitch() { 
        var $active = $('#slideshow IMG.active');
        //alert('#slideshow IMG:first');
        if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
        var $next = $active.next().length ? $active.next()
             : $('#slideshow IMG:first');
         
        $active.addClass('last-active');
          
        $next.css({opacity: 0.0}) 
            .addClass('active') 
            .animate({opacity: 1.0}, 1000, function() {
                $active.removeClass('active last-active');
            }); 
    } 
      
    $(function() { setInterval( "slideSwitch()", 5000 ); });
    
    
