// MENU ROZWIJANE
var timers = new Array(); 
var wobjazdowe = new Array();
var wobjazdowe_time = new Array();
var wobjazdowe_loaded = new Array();
var wobjazdowe_timer = new Array();
var wobjazdowe_n = new Array();
var wobjazdowe_last = new Array();


$(document).ready(function()
{   
  $(document).pngFix();
  $(".toper_down").css("bottom",0);
  $(".toper_down").css("left",0);
  var ie6=false;
  if ($.browser.msie==true)
  {
    if (parseInt(jQuery.browser.version.substr(0,1))<7)
      ie6=true;
  }
  var tuisp = $(".tuisp_menu .tuisp_linia");
  var zix = 1000;

  if (ie6==true)
  {
    $(".toper_down").css("bottom","-1px");
    $(".tuisp_rm .rlinks").css("left","-8px");
  }

  for (var cs=tuisp.length-1;cs>=0;cs--)
  {
    tuisp.eq(cs).css('z-index',zix);
    zix+=1;
  }
  
  zakladka_activate();
  $(".tuisp_menu").css("height",(tuisp.length*27)+"px");
  
  $(window).load( 
    function ()
    {
      if (ie6==true) 
      {
        $(".toper_down").css("bottom","-1px");
      }
      else $(".toper_down").css("bottom","0px");
      
      var ikonki = $("#topikony2").find("a");
      for (var n=0; n<ikonki.length;n++)
      {
        r=500+n*200;
        ikonki.eq(n).animate( { marginLeft: "0px" }, r );
      }
    }  
  );
  
  $("#topikony a").hover(
    function() {
    	$(this).animate( { marginLeft: "0px" }, 300 );
    }, 
    function() {
    	$(this).animate( { marginLeft: "135px" }, 300 );
    }
  );
  

});

function zamknij_banner()
{
  $(".banner_toplayer").css('display','none');
}

function openWindow(url, width, height) {
  var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=yes,menubar=no' );
}


function menu_rozwijane(id,bg,width)
{
  $(id).find("div").css({"background-color":bg,"width":width+"px"});
  $(id).css({"background-color":bg,"width":width+"px"});
  $(id).hover(
    function() {
    	if($(this).find('div').css('display') == 'none') {
        $(this).find('div').slideDown("fast");
    	}
    }, 
    function() {
    	$(this).find('div').slideUp("fast");
    }
  );
}

function show_searchadv()
{
  if ($("#wyszukiwarka_right").css('display')=='none')
  {
    $("#searchadv_buttton").css('display','none');
    //$("#wyszukiwarka_right").appendTo("#search_rozwijak");
    document.getElementById("adv_mode").value="1";
    $("#wyszukiwarka_right").slideDown();
  }
}

function submit_searchadv()
{
  //$("#wyszukiwarka_right").hide();
  //$("#wyszukiwarka_right").appendTo("#wyszukiwarka_contener");
  return true;
}



function sbtn_searchadv()
{
  //$("#wyszukiwarka_right").hide();
  //$("#wyszukiwarka_right").appendTo("#wyszukiwarka_contener");
  $("#kryteria_szukania").submit();
}

function wyszukiwarka_check(ishotel)
{
  var wyno = $(".wyszukiwarka").find(".sr_res").length;
  if (ishotel==1 && wyno==0)
    $(".wyszukiwarka").hide();
  else
    $(".wyszukiwarka").show();
}

function leftsuw_zwijanie(id)
{
  if ($("#"+id).css('display')=='block') $("#"+id).slideUp();
  else $("#"+id).slideDown();
}

function rozwin_modul(id)
{
  if ($(id+" .roz_tekst").css('display')=='block') $(id+" .roz_tekst").slideUp( function () { $(id+" .roz_wijacz").removeClass("roz_wijane"); } );
  else $(id+" .roz_tekst").slideDown( function () { $(id+" .roz_wijacz").addClass("roz_wijane"); } );
}

function nokazje_modul(id)
{
  $("#nokazje_"+id+" .oferty").find(".grupa").hide();
  timers[id]=9000;
  $("#nokazje_"+id+" .oferty").find(".grupa").eq(0).show();
  $("#nokazje_"+id+" .items").find("a").eq(0).attr('class','nokazje_on');
  window.setInterval("nokazje_check('"+id+"',-1)",100);
}

function nokazje_check(id,cp)
{
  if (cp!="-1") { timers[id]=0; }
  if (timers[id]<=0)
  {
    timers[id]=9000;
    var ecp = $("#nokazje_"+id+" .items").find("a");
    var wh=0;
    for (var im=0;im<ecp.length;im++)
    {
      if (ecp.eq(im).attr("class")=="nokazje_on") 
      {
        wh=im;
        ecp.eq(im).attr("class","nokazje_off");
      }
    }
    $("#nokazje_"+id+" .oferty").find(".grupa").hide();
    wh+=1;
    if (cp!="-1") wh=parseInt(cp);
    if (wh>=ecp.length) wh=0;
    ecp.eq(wh).attr('class','nokazje_on');
    $("#nokazje_"+id+" .oferty").find(".grupa").eq(wh).fadeIn();
  }
  else
  {
    timers[id]-=100;
  }
}

function kwycieczek_modul(id)
{
  $("#kwycieczka_"+id+" .desc").find(".item").hide();
  timers[id]=9000;
  $("#kwycieczka_"+id+" .desc").find(".item").eq(0).show();
  $("#kwycieczka_"+id+" .menus").find("a").eq(0).attr('class','active');
  $("#arowek_"+id).css("left","60px");
  window.setInterval("kwycieczek_check('"+id+"',-1)",100);
}

function kwycieczek_check(id,cp)
{
  if (cp!="-1") { timers[id]=0; }
  if (timers[id]<=0)
  {
    timers[id]=9000;
    var ecp = $("#kwycieczka_"+id+" .menus").find("a");
    var wh=0;
    for (var im=0;im<ecp.length;im++)
    {
      if (ecp.eq(im).attr("class")=="active") 
      {
        wh=im;
        ecp.eq(im).attr("class","");
      }
    }
    $("#kwycieczka_"+id+" .desc").find(".item").hide();
    wh+=1;
    if (cp!="-1") wh=parseInt(cp);
    if (wh>=ecp.length) wh=0;
    ecp.eq(wh).attr('class','active');
    $("#kwycieczka_"+id+" .desc").find(".item").eq(wh).show();
    var ls = 60+(138*wh);
    $("#arowek_"+id).css("left",ls+"px");
    //$("#ars_"+id).css("margin-left","300px");
    //$("#ars_"+id).hide();
    //alert($("#ars_"+id).attr("src"));
  }
  else
  {
    timers[id]-=100;
  }
}

function zakladka_change(id,cp)
{
  var ecp = $("#zakladki_"+id+" .menus").find("a");
  var wh=0;
  for (var im=0;im<ecp.length;im++)
  {
    ecp.eq(im).removeClass("active");
    $("#zakladki_"+id+" .items").find(".item").eq(im).hide();
  }
  $("#zakladka_"+id+" .inforegion").slideUp();
  $("#zakladki_"+id+" .menus").find("a").eq(cp).addClass("active");
  $("#zakladki_"+id+" .items").find(".item").eq(cp).fadeIn();
}

function zakladka_activate()
{
  $(".zakitem").hover(
    function() {
    	$(this).addClass("link");
    }, 
    function() {
    	$(this).removeClass("link");
    }
  );
}

function rozwijanie_modulu(id)
{
  if ($(id).css("display")=="none")
  {
    $(id).slideDown();
  }
  else
    $(id).slideUp();
}

function rozwijaj_submenu(id)
{
  if ($(id).find(".rlinks").css("display")=="none")
  {
    $(id).find(".rlinks").show();
    $(id).find(".rlink").addClass("rm_zaznacz");
  }
  else
  {
    $(id).find(".rlinks").hide();
    $(id).find(".rlink").removeClass("rm_zaznacz");
  }
}

function ichwill_zwijanie(idc,rozwin,ukryj)
{
  if ($("#"+idc+" .rozwiniete").css("display")=="none")
  {
    $("#"+idc+" .rozwiniete").slideDown();
    $("#"+idc+" .more").find("img").attr({src:ukryj});
  }
  else
  {
    $("#"+idc+" .rozwiniete").slideUp();
    $("#"+idc+" .more").find("img").attr({src:rozwin});
  }
}

function infohotel(idh,links,imgs)
{
  if ($("#DIV_"+idh+" .infohotel").css("display")=="none")
  {
    $(".hot_highlight .infohotel .infohotel_opis").hide();
    $(".hot_highlight .infohotel").slideUp();
    $(".hot_highlight .hot_link").find("img").eq(0).attr("src",imgs+"hot_linkoff.gif");
    $(".hot_highlight").removeClass("hot_highlight");
    if ($("#DIV_"+idh).hasClass('hot_premium')==false) $("#DIV_"+idh).addClass('hot_highlight');
    $("#DIV_"+idh+" .infohotel .infohotel_opis").fadeIn();
    $("#DIV_"+idh+" .infohotel").slideDown();
    $("#DIV_"+idh+" .hot_link").find("img").eq(0).attr("src",imgs+"hot_linkon.gif");
    
    if($("#hotload_"+idh).attr("value")=="0")
    {
      $.ajaxSetup({
        contentType: "application/x-www-form-urlencoded; charset=iso-8859-2"
      });

      $.get(links+"&rnd="+Math.random(), function(data){
        $("#DIV_"+idh+" .infohotel .infohotel_desc").html(data);
        $("#hotload_"+idh).attr("value","1");
        $("#DIV_"+idh+" .infohotel_gallery").jHotelFoto({
            btnNext: "#DIV_"+idh+" .infohotel .next",
            btnPrev: "#DIV_"+idh+" .infohotel .prev",
            visible : 1,
            scroll : 1
        });
        $("#DIV_"+idh+" .infohotel_gallery2").jHotelFoto({
            btnNext: "#DIV_"+idh+" .infohotel .next2",
            btnPrev: "#DIV_"+idh+" .infohotel .prev2",
            visible : 1,
            scroll : 1
        });
      });
    }  
  }
  else
  {
    $("#DIV_"+idh+" .infohotel .infohotel_opis").hide();
    $("#DIV_"+idh+" .infohotel").slideUp();
    $("#DIV_"+idh+" .hot_link").find("img").eq(0).attr("src",imgs+"hot_linkoff.gif");
    $("#DIV_"+idh).removeClass("hot_highlight");
  }
}

function infowycieczka(idh,links,imgs)
{
  if ($("#DIV_"+idh+" .infohotel").css("display")=="none")
  {
    $("#DIV_"+idh+" .infohotel .infohotel_opis").fadeIn();
    $("#DIV_"+idh+" .infohotel").slideDown();    
    if($("#hotload_"+idh).attr("value")=="0")
    {
      $.ajaxSetup({
        contentType: "application/x-www-form-urlencoded; charset=iso-8859-2"
      });

      $.get(links+"&rnd="+Math.random(), function(data){
        $("#DIV_"+idh+" .infohotel .infohotel_desc").html(data);
        $("#hotload_"+idh).attr("value","1");
        $("#DIV_"+idh+" .infohotel_gallery").jHotelFoto({
            btnNext: "#DIV_"+idh+" .infohotel .next",
            btnPrev: "#DIV_"+idh+" .infohotel .prev",
            visible : 1,
            scroll : 1
        });
        $("#DIV_"+idh+" .infohotel_gallery2").jHotelFoto({
            btnNext: "#DIV_"+idh+" .infohotel .next2",
            btnPrev: "#DIV_"+idh+" .infohotel .prev2",
            visible : 1,
            scroll : 1
        });
        
      });
    }
  }
  else
  {
    $("#DIV_"+idh+" .infohotel .infohotel_opis").hide();
    $("#DIV_"+idh+" .infohotel").slideUp();
  }
}

function infohotel_showdzial(dzial,ajdi)
{
  $("#"+ajdi+" .infohotel_d_opis").hide();
  $("#"+ajdi+" .infohotel_d_opisinny").hide();
  $("#"+ajdi+" .infohotel_d_pogoda").hide();
  $("#"+ajdi+" .infohotel_d_mapa").hide();
  
  if (dzial==1)
  {
    $("#"+ajdi+" .infohotel_d_opis").show();
  }
  else if (dzial==2)
  {
    $("#"+ajdi+" .infohotel_d_pogoda").show();  
  }
  else if (dzial==3)
  {
    $("#"+ajdi+" .infohotel_d_opisinny").show();
  }
  else if (dzial==4)
  {
    $("#"+ajdi+" .infohotel_d_mapa").show();
  }
}


function inforegion(idh,links,imgs)
{
  if ($("#DIV_"+idh+" .infohotel").css("display")=="none")
  {
    $(".hot_highlight .opis").hide();
    $(".hot_highlight .infohotel").slideUp();
    $(".hot_highlight .hot_link").find("img").attr("src",imgs+"hot_linkoff.gif");
    $(".hot_highlight").removeClass("hot_highlight");
    $("#DIV_"+idh).addClass('hot_highlight');
    $("#DIV_"+idh+" .infohotel_opis").fadeIn();
    $("#DIV_"+idh+" .infohotel").slideDown();
    $("#DIV_"+idh+" .hot_link").find("img").attr("src",imgs+"hot_linkon.gif");
    if($("#hotload_"+idh).attr("value")=="0")
    {
      $.ajaxSetup({
        contentType: "application/x-www-form-urlencoded; charset=iso-8859-2"
      });

      $.get(links, function(data){
        $("#DIV_"+idh+" .infohotel_desc").html(data);
        $("#hotload_"+idh).attr("value","1");
        $("#DIV_"+idh+" .infohotel_opis .opis").eq(0).show();
        $("#DIV_"+idh+" .infohotel_gallery").jHotelFoto({
            btnNext: "#DIV_"+idh+" .next",
            btnPrev: "#DIV_"+idh+" .prev",
            visible : 1,
            scroll : 1
        });
      });
    }  
  }
  else
  {
    $("#DIV_"+idh+" .infohotel_opis").hide();
    $("#DIV_"+idh+" .infohotel").slideUp();
    $("#DIV_"+idh+" .hot_link").find("img").attr("src",imgs+"hot_linkoff.gif");
    $("#DIV_"+idh).removeClass("hot_highlight");
  }
}

function inforegion2(idh,links,imgs)
{
  if ($("#DIV_"+idh+" .inforegion").css("display")=="none")
  {
    $("#DIV_"+idh+" .inforegion .infohotel_opis").fadeIn();
    $("#DIV_"+idh+" .inforegion").slideDown();
    $("#DIV_"+idh+" .hot_link").find("img").eq(1).attr("src",imgs+"hot_linkon.gif");
    if($("#hotloadr_"+idh).attr("value")=="0")
    {
      $.ajaxSetup({
        contentType: "application/x-www-form-urlencoded; charset=iso-8859-2"
      });

      $.get(links, function(data){
        $("#DIV_"+idh+" .inforegion .infohotel_desc").html(data);
        $("#hotloadr_"+idh).attr("value","1");
        $("#DIV_"+idh+" .inforegion .infohotel_opis .opis").eq(0).show();
        $("#DIV_"+idh+" .inforegion .infohotel_gallery").jHotelFoto({
            btnNext: "#DIV_"+idh+" .inforegion  .next",
            btnPrev: "#DIV_"+idh+" .inforegion .prev",
            visible : 1,
            scroll : 1
        });
      });
    }  
  }
  else
  {
    $("#DIV_"+idh+" .inforegion .infohotel_opis").hide();
    $("#DIV_"+idh+" .inforegion").slideUp();
    $("#DIV_"+idh+" .hot_link").find("img").eq(1).attr("src",imgs+"hot_linkoff.gif");
  }
}

function inforegion_zakladki(ajdi,links)
{
  if ($("#"+ajdi+" .inforegion").css("display")=="none")
  {
    $("#"+ajdi+" .inforegion .infohotel_opis").fadeIn();
    $("#"+ajdi+" .inforegion").slideDown();
    $.ajaxSetup({
      contentType: "application/x-www-form-urlencoded; charset=iso-8859-2"
    });
    $.get(links, function(data){
      $("#"+ajdi+" .inforegion").html(data);
      $("#"+ajdi+" .inforegion .infohotel_opis .opis").eq(0).show();
    });
  }
  else
  {
    $("#"+ajdi+" .inforegion").slideUp();
  }
}

function inforegion_showdzial(dzial,ajdi)
{
  $("#"+ajdi+" .opis").hide();
  $("#"+ajdi+" .opis").eq(dzial).show();
}

function submit_form(ajdi)
{
  document.getElementById(ajdi).submit();
}

function submit_search()
{
    $("#preload_search").css({
        marginTop:    100 + jQuery(window).scrollTop()
    });
    $("#preload_search").show();
    return true;
}

function submituj_search(ajdi)
{
  if (submit_search())
    $("#"+ajdi).submit();
}

function sortuj_premium(check)
{
  document.getElementById('adv_premium').checked=check;
  document.getElementById('kryteria_szukania').submit();
}

function czat_online()
{
  var Win = window.open('http://chat.livechatinc.net/licence/1026595/open_chat.cgi?groups=0'+'&s=1&lang=pl&layout=tui&params='+escape('strona=TUI'),'czatonline','width=604,height=247,resizable=no,scrollbars=no,status=1');
}

function nhotel_zakladka(id,nr)
{
  if ($("#nhotel_"+id+" .zaklada").eq(nr).css('display')=="block") { $("#nhotel_"+id+" .zaklada").eq(nr).slideUp(); }
  else
  {
    $("#nhotel_"+id+" .zaklada").each(function (){
      if ($(this).css('display')=="block") $(this).slideUp();
    });
    $("#nhotel_"+id+" .zaklada").eq(nr).slideDown(
      function () {
        if ($.browser.mozilla && typeof(load)!='undefined') load();
      }
    );
  } 
}

function hotelregion(id,links,imgs,nr)
{
  if ($("#nhotel_"+id+" .zaklada").eq(nr).css('display')=="block") { $("#nhotel_"+id+" .zaklada").eq(nr).slideUp(); }
  else
  {
    $("#nhotel_"+id+" .zaklada").each(function (){
      if ($(this).css('display')=="block") $(this).slideUp();
    });
    $("#nhotel_"+id+" .zaklada").eq(nr).slideDown(
      function () 
      {
        // loading
        if($("#load_hotelregion_"+id).attr("value")=="0")
        {
          $.ajaxSetup({
            contentType: "application/x-www-form-urlencoded; charset=iso-8859-2"
          });
    
          $.get(links, function(data){
            $("#nhotel_"+id+" .zaklada").eq(nr).find(".nopis_region").eq(0).html(data);            
            $("#load_hotelregion_"+id).attr("value","1");
            $("#nhotel_"+id+" .zaklada").eq(nr).find(".opis").eq(0).show();
            
          });
        }
      }
      
    );
  }
}

function hotelregion_dzial(dzial,ajdi)
{
  $("#nhotel_"+ajdi+" .zaklada .nopis_region .opis").hide();
  $("#nhotel_"+ajdi+" .zaklada .nopis_region .opis").eq(dzial).show();
}



function wobjazdowe_start(sid)
{
  wobjazdowe_timer = window.setInterval("wobjazdowe_check("+sid+")",100);
  wobjazdowe_toload(sid,0);
}

function wobjazdowe_change_value(sid,i)
{
  $(document).ready(function()
  {   
    wobjazdowe[sid][i][2]=true;
  });
}

function wobjazdowe_toload(sid,cn)
{
  if (wobjazdowe[sid][cn][2]==false)
  {
    $("#wobjazdowe_"+sid+"_foto"+cn).attr("src",wobjazdowe[sid][cn][0]);
  }
  wobjazdowe_time[sid]=6000;
  wobjazdowe_n[sid]=cn;
}


function wobjazdowe_check(sid)
{
  if (wobjazdowe_time[sid]>6000 && wobjazdowe[sid][wobjazdowe_n[sid]][2]==true)
  {
    lasts=wobjazdowe_last[sid];
    $("#wobjazdowe_"+sid+"_foto"+wobjazdowe_n[sid]).fadeIn("slow", function () {
      $(this).css({'z-index':7});
      $("#wobjazdowe_link_"+sid).attr("href",wobjazdowe[sid][wobjazdowe_n[sid]][1]);
      wobjazdowe_last[sid]=wobjazdowe_n[sid];
      $("#wobjazdowe_"+sid+" .oferty .item").eq(lasts).removeClass("item_active");
      $("#wobjazdowe_"+sid+" .oferty .item").eq(wobjazdowe_n[sid]).addClass("item_active");
      wobjazdowe_n[sid]+=1;
      if (wobjazdowe_n[sid]==wobjazdowe[sid].length) wobjazdowe_n[sid]=0;
      $("#wobjazdowe_"+sid+"_foto"+wobjazdowe_n[sid]).css({'z-index':8, 'display':'none'});
      if (wobjazdowe[sid][wobjazdowe_n[sid]][2]==false) 
      {
        $("#wobjazdowe_"+sid+"_foto"+wobjazdowe_n[sid]).attr("src",wobjazdowe[sid][wobjazdowe_n[sid]][0]);
      }
      
      $("#wobjazdowe_"+sid+"_foto"+lasts).hide();      
    });
    wobjazdowe_time[sid]=0;
  }
  else
    wobjazdowe_time[sid]+=100;
}

function ruster_show()
{
  if ($("#ruster_uklad").css('display')=='block') $("#ruster_uklad").slideUp();
  else $("#ruster_uklad").slideDown();
}