$(document).ready(function(){
  
 
     
     if (banner_count > 1){
       
       var banner_actual = 1;
       var refreshId = setInterval(function(){
        $("#banner_content").load(httpRoot+"ajax/getbanner.php?randval="+ Math.random()+"&id="+banner_array[banner_actual]);
        $(".switcher").removeClass("active");
        $("#switcher_"+banner_array[banner_actual]).addClass("active");  
          if ((banner_actual+1)==banner_count){
            banner_actual = 0;
          }else{
            banner_actual++;
          }
        }, 7000);

     } 


  

      $("#loading").bind("ajaxSend", function(){
           $(this).show();
      }).bind("ajaxComplete", function(){
           $(this).hide();
      });

      $("#menu ul").css("display", "none");
      $("#menu li").hover(function(){
		      $(this).find("ul:first").css({visibility: "visible", display: "block"}).show(1268);
		      },function(){
		      $(this).find("ul:first").css({visibility: "hidden", display: "none"});
	    });



      $(window).load(function(){
        $.ajax({
          type: "get",
          url: httpRoot+"ajax/getforms_"+language+".php",
          cache: false,
          data: "randval="+ Math.random()+"&type=1",
          success: function(j){
            $("#form_quick_search").html(j);       
          }
        });


      });
    
    $(".switcher").click(function(){
      id = ($(this).attr("id")).split("_");
      $.ajax({
          type: "get",
          url: httpRoot+"ajax/getbanner.php",
          cache: false,
          data: "randval="+ Math.random()+"&id="+id[1],
          success: function(j){
            $("#banner_content").html(j);       
          }
        });
        
        $(".switcher").removeClass("active");
        $(this).addClass("active");;
    });
    
    
    $("#buy, #sell, #rent").click(function(){
      var type = 1;
      $(".quick_search_select").hide();
      if(this.id=="buy"){
        type=1;
        $("#buy").addClass("active");
        $("#sell, #rent").removeClass("active");
      }else if(this.id=="sell"){
        type=3
        $("#sell").addClass("active");
        $("#buy, #rent").removeClass("active");
      }else if(this.id=="rent"){
        type=2
        $("#rent").addClass("active");
        $("#buy, #sell").removeClass("active");
      }
      
      $.ajax({
        type: "get",
        url: httpRoot+"ajax/getforms_"+language+".php",
        cache: false,
        data: "randval="+ Math.random()+"&type="+type,
        success: function(j){
          $("#form_quick_search").html(j);
          $.ajax({
            type: "get",
            url: httpRoot+"ajax/getnumber.php",
            cache: false,
            data: "randval="+ Math.random()+"&type="+type,
            success: function(j){
              $("#count").html(j);       
            }
          });
          
                        
        }
      });
    });
  

        $("#quick_search_item_input_10, #quick_search_item_input_11").click(function(){
            $(this).val("");
        });
      
        
        var pos = 0;
       
        /*kolik jich je na strance*/
        var on_page = 4;
        var ar = "";
        $(".previous").click(function(){
          $("#container .latest_item").animate({"left": "+=230px"}, "fast");
            if (pos>0){
              pos--;
            } else{
              pos = (cou-1);
            }
            
            var array = new Array();
            var j =0;

            if ((pos+on_page-1) < cou){
              
              for(i=pos;i<(pos+on_page);i++){
                array[j]= arrayID[i];
                j++;
              }
              ar = array.join(",");
            }else{
              var rest = cou % pos;
              
              for(i=pos;i<=(pos+rest);i++){
                array[j]= arrayID[i];
                j++;
              }
              j--;
              var rest2 = on_page - rest;
              for(i=0;i<rest2;i++){
                array[j]= arrayID[i];
                j++;
              }
              
              
              ar = array.join(",");
            }    
            $.ajax({
              type: "get",
              url: httpRoot+"ajax/getslides.php",
              cache: false,
              data: "randval="+ Math.random()+"&ar="+ar,
              success: function(j){
                $("#container").html(j);       
              }
            });          
        });
        
        $(".next").click(function(){
          $("#container .latest_item").animate({"left": "-=230px"}, "fast");
            if (pos<(cou-1)){
              pos++;
            } else{
              pos =0;
            }
            
            var array = new Array();
            var j =0;

            if ((pos+on_page-1) < cou){
              
              for(i=pos;i<(pos+on_page);i++){
                array[j]= arrayID[i];
                j++;
              }
              ar = array.join(",");
            }else{
              var rest = cou % pos;
              
              for(i=pos;i<=(pos+rest);i++){
                array[j]= arrayID[i];
                j++;
              }
              j--;
              var rest2 = on_page - rest;
              for(i=0;i<rest2;i++){
                array[j]= arrayID[i];
                j++;
              }
              
              
              ar = array.join(",");
            }    
            $.ajax({
              type: "get",
              url: httpRoot+"ajax/getslides.php",
              cache: false,
              data: "randval="+ Math.random()+"&ar="+ar,
              success: function(j){
                
                $("#container").html(j);       
              }
            });           
        });

    
    });

