﻿
 $(document).ready(function(){
 
  //MENU GLOWNE
  
   $("#main li").mouseover(function(){
   
    $("div[class='submenu']",this).fadeIn();
	
	$("a[name='menuoption']",this).css("background","url('/images/menuarrow.gif') center bottom no-repeat");
   
   });
   
    $("#main li").mouseleave(function(){
   
      $("div[class='submenu']",this).fadeOut();
	  
	  $("a[name='menuoption']",this).css("background","");
   
   });
  
  //
  
  //SUB MENU

   $(".mainbanermenu ul li:eq(0)").css("background-color","#f47a20").find("a").css("color","#fff");
  
   $(".mainbanermenu ul li a[name='megamenu']").mouseover(function(){
/*
	   $(".mainbanermenu ul li").each(function(){
		  
		   $(this).css("background-color","").find("a").css("color","#1e3c72");
		   
	   });
*/   
    $(this).parent().css("background-color","#f47a20").find("a[name='megamenu']").css("color","#fff");
   
   });
   
   $(".mainbanermenu ul li").mouseout(function(){
   
    if($(this).parent().parent().attr("class") == "mainbanermenu"){
   
      $(this).css("background-color","").find("a").css("color","#1e3c72");
	
	}
   
   });
  
  //
  
   //MEGA MENU
   
    $(".mainbanermenu ul li a[name='megamenu']").click(function(){
	
	  p = $(this).parent();

      $(p).find(".kategoryzacje").show('fast')
	
	}).parent().mouseleave(function(){
	
	 $(this).find(".kategoryzacje").hide('fast');
	
	});
	
   //
   
   //KATALOGI
   
    $('#parent1').wslide({
	
	  width: 254,
	  height: 300,
	  fade:true,
	  autolink: false


    });
	
	$(".control_new_l li:eq(0)").css("background","url(/images/thbuttonon.png) no-repeat");
	
	$(".control_new_l li a").click(function(){
	
	 $(".control_new_l li").css("background","url(/images/thbuttonoff.png) no-repeat");
	 
	 $(this).parent().css("background","url(/images/thbuttonon.png) no-repeat");

	});
	
   //TOP HOTEL
   
    $('#hotelt1').wslide({
	
	  width: 267,
	  height: 219,
	  col:14,
	  autolink: false


    });
	
	$(".control_th li:eq(0)").css("background","url(/images/thbuttonon.png) no-repeat");
	
	$(".control_th li a").click(function(){
	
	 $(".control_th li").css("background","url(/images/thbuttonoff.png) no-repeat");
	 
	 $(this).parent().css("background","url(/images/thbuttonon.png) no-repeat");

	});
	
   //LAST MINUTE INDEX
   
    $('#lm1').wslide({
	
	  width: 419,
	  height: 307,
	  autolink: false


    });
	
	$('#lmcontrollist li a:eq(0)').addClass("selected_lm");
	
	$('#lmcontrollist li a').click(function(){
	
	 $('#lmcontrollist li a').removeAttr("class");
	 
	 $(this).addClass("selected_lm");
	
	});
	
	//SLIDER

         
	
   			$("#slider").easySlider({
				auto: true, 
				continuous: true, 
				numeric: false,
				controlsShow: false
			});
          
			
	//STYLISH SELECT
			
			$("select[name='searchform']").sSelect();
			$("select[name='krajsearchform']").sSelect();
			$("select[name='hotelsearchform']").sSelect();
			$("select[name='pokojsearchform']").sSelect();
			$("select[name='wyzywieniesearchform']").sSelect();
			$("select[name='tripFrom']").sSelect();
			$("select[name='tripBoardDb']").sSelect();
			//$("select[name='roomtype']").sSelect();
			$("select[id='roomtype']").sSelect();
			$("select[name='roomname']").sSelect();
			$("select[name='kraje_lm']").sSelect();
			$("select[name='lotniska_lm']").sSelect();
			$("select[name='AgentFullList[voivodeship]']").sSelect();
			$("select[name='AgentFullList[city]']").sSelect();
			$("#kraj_rozklad").sSelect();
			$("#from_rozklad").sSelect();
			$("#miesiac_rozklad").sSelect();
			$("#flight_type").sSelect();
			
		    $('div[class="selectedTxt"]').each(function(){
			
			 $(this).text($(this).text().replace("&amp;","&"));
			 
			});
			
	//DATA PICKER

	            $('.date_input_right').click(function(){
                                
                                 id = $(this).prev().find("input").attr("id");
                                 $("#"+id).focus();
				
		    });
			
                $('#data_od,#d1print').datepicker({
			
					dateFormat: "yy-mm-dd",
					monthNames: ['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec',
			        'Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'],
					dayNamesMin: ['Nie', 'Pon', 'Wto', 'Sro', 'Czw', 'Pia', 'Sob'],
					firstDay: 1,
					showAnim: 'slide',
					showButtonPanel: false,
					
					onSelect: function(){
					
					 	
		
		                  today = $("#data_od").val().split("-");
		                  var d = new Date(today[0]+"/"+today[1]+"/"+today[2]);
                          d.setDate(d.getDate()+30);
		                  monthset = ((d.getMonth()+1) < 10) ? "0"+(d.getMonth()+1) : (d.getMonth()+1);
		                  dayset = (d.getDate() < 10) ? "0"+d.getDate() : d.getDate();
		                  $("#data_do").val(d.getFullYear()+"-"+monthset+"-"+dayset);
					
					     
						 
				    }
					
				});
				
                $('#data_do,#d2print').datepicker({
			
					dateFormat: "yy-mm-dd",
					monthNames: ['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec',
			        'Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'],
					dayNamesMin: ['Nie', 'Pon', 'Wto', 'Sro', 'Czw', 'Pia', 'Sob'],
					firstDay: 1,
					showAnim: 'slide',
					showButtonPanel: false,
					
					onSelect: function(){

                            today = $("#data_do").val().split("-");
		                  var d = new Date(today[0]+"/"+today[1]+"/"+today[2]);
                          d.setDate(d.getDate()-30);
		                  monthset = ((d.getMonth()+1) < 10) ? "0"+(d.getMonth()+1) : (d.getMonth()+1);
		                  dayset = (d.getDate() < 10) ? "0"+d.getDate() : d.getDate();
		                  $("#data_od").val(d.getFullYear()+"-"+monthset+"-"+dayset);
						 
				    }
					
				});
				
//OFERTA HOTELU
 
 //domyslnie
 
 $('#tabs a[name="terminy"]').css("background","url(/images/rightbluetabon.png) right top no-repeat");
 $('#tabs a[name="terminy"]').parent().css("background","url(/images/leftbluetabon.png) left top no-repeat");
 $('#tabs a[name="terminy"] span').css("background","url(/images/middlebluetabon.png)");
 
 
 //po kliknieciu tabu
 
 $('#tabs a').click(function(){
 
  $('#tabs a').each(function(){
  
  $(this).parent().css("background","url(/images/leftbluetaboff.png) left top no-repeat");
  $(this).css("background","url(/images/rightbluetaboff.png) right top no-repeat");
  $("span",this).css("background","url(/images/middlebluetaboff.png)");
  
  });
  
 
  $(this).parent().css("background","url(/images/leftbluetabon.png) left top no-repeat");
  $(this).css("background","url(/images/rightbluetabon.png) right top no-repeat");
  $("span",this).css("background","url(/images/middlebluetabon.png)");
  
  attr = $(this).attr("name");
  $("#terminy").css("display","none");
  $("#dsp").css("display","none");
  $("#poradnik").css("display","none");
  $("#dokumenty").css("display","none");
  $("#geo").css("display","none");
  $("#opinie").css("display","none");
  $("#pogoda").css("display","none");
  $("#hotel").css("display","none");
  $("#komunikaty").css("display","none");
  $("#payments").css("display","none");
  $("#"+attr).css("display","block");
 
 });
 
  /*FLY PROMO */
  
  czas = "";
  
  loopFly();

 mega_menu_time = 0;
 mega_menu_item = 0;
 mega_menu_total_item = $(".baner_controls img").length;
 stop_mega_menu = 0;
 
 $(".mainbanermenu").mouseover(function(){
 
   stop_mega_menu = 1;
 
   clearTimeout("mega_menu_time");
 
 });

 top_hotel_time = 0;
 top_hotel_item = 0;
 top_hotel_total_item = $(".control_th li").length;
 stop_top_hotel = 0;

 $(".index_tophotels_layout").mouseover(function(){
 
   stop_top_hotel = 1;
 
   clearTimeout("top_hotel_time");
 
 });
 

 run_top_hotel(0);
 
 //run_mega_menu(0);

//FOOTER

 $("#certyfikaty").mouseenter(function(){
 
  $(this).animate({
    opacity: 1
  }, 500, function() {
    // Animation complete.
  });
  
 
 
 });
 
 $("#certyfikaty").mouseleave(function(){

  $(this).stop(true, true);
 
  $(this).animate({
    opacity: 0.3
  }, 500, function() {
    // Animation complete.
  });
 
 });
 
 $("#nagrody").mouseenter(function(){
 
 
 
  $(this).animate({
    opacity: 1
  }, 500, function() {
    // Animation complete.
  });
  
  
 
 });
 
 $("#nagrody").mouseleave(function(){

  $(this).stop(true, true);
 
  $(this).animate({
    opacity: 0.3
  }, 500, function() {
    // Animation complete.
  });
 
 });
 
  $("#platnosci").mouseenter(function(){
 
 
 
  $(this).animate({
    opacity: 1
  }, 500, function() {
    // Animation complete.
  });
  
 
 });
 
 $("#platnosci").mouseleave(function(){

  $(this).stop(true, true);
 
  $(this).animate({
    opacity: 0.3
  }, 500, function() {
    // Animation complete.
  });
 
 });

 $(".baner_controls img").click(function(event){

  n = $(this).attr("name");

  $(".mainbanermenu ul li").each(function(){
	  
	  $("a:eq(0)",this).css("color","#1e3c72");
	  $(this).css("background-color","")

	  if($("a:eq(0)",this).text() == n){
		
		  $("a:eq(0)",this).css("color","#fff");
		  $(this).css("background-color","#f47a20")
		  
	  }
	  
  });
 
  event.stopPropagation();
 
 });

 $(".control_th li a").click(function(event){
 
  event.stopPropagation();
 
 });

 //WYCIECZKI
 
 $('a[name*="wycieczka"]').click(function(){
 
  $('a[name*="wycieczka"]').each(function(){
  
   $(this).parent().css("background-color","").find("a").css("color","#000");
   $("#w"+$(this).attr("name").replace("wycieczka_","")).css("display","none");
  
  });
  
  $(this).parent().css("background-color","#f47a20").find("a").css("color","#fff");
  
  $("#w"+$(this).attr("name").replace("wycieczka_","")).fadeIn();
 
 });

 //punkty sprzedazy
 
 $("#AgentFullList_voivodeship").change(function(){
 
  $.post("/punktysprzedazy/city",{v:$(this).val()},function(html,stat){
   
    $("#AgentFullList_city").remove("option").resetSS();
    $("#AgentFullList_city").html(html).resetSS();
  
  });
 
 });
 
 //boxes
 
 $("#emp_regions_map area").mouseover(function(){
  $("#lokmap").html($(this).attr("title"));
  $("#mapw").attr("src","/images/"+$(this).attr("id")+".png");
 });
 
 $("#emp_regions_map area").mouseout(function(){
  //$("#mapw").attr("src","/images/mapaw.png");
 });
 
  $('#box_c,#box_p').click(function(){
	$(this).animate({marginRight: "0px"}, {queue:false,duration:500,complete:function(){$("#mapw").css("visibility","visible");}} );
  });

  $('#box_c,#box_p').mouseleave(function(e){

     $(this).animate({marginRight: "-310px"}, {queue:false,duration:500,complete:function(){$("#mapw").css("visibility","hidden");}} );
	
	return false;
  });

 //WYSZUKIWARKA HOTELI
 
 keyups = 0;
 
$('#ihotelsearch').live("keyup",function() {

 keyups = 1;

  //setTimeout("hotelsearchresults()",1000);

 hotelsearchresults();
  
});

$('li[name="tiphotelchoosed"]').live("click",function(){

 rep = $(this).html().replace("&amp;","&");
 //reps = rep.replace("<img style=\"vertical-align:middle;margin-right:10px;\" src=\"/images/hotel_icon.jpg\" height=\"20\" width=\"20\">","");
 reps = rep.substring(rep.lastIndexOf(">")+1,rep.length);

 $("#ihotelsearch").val(reps);

});

 
 });
 
 iPos = 450;
 
 function loopFly(){
 
  czas = setInterval("runfly()",40);
  $("#p1f").css("display","none");
  $("#p2f").css("display","none");
 
 }
 
 function runfly(){
 
  $("#headerfly").css("margin-left",iPos+"px");
  
  iPos -= 15;
  
  if(iPos <= -10){
  
   clearInterval(czas);
   
   setTimeout("fadeFly()",500);
   
  
  }
 
 }
 
 function fadeFly(){
 
  $("#p1f").fadeIn();
  $("#p2f").fadeIn();
  
   iPos = 450;
   setTimeout("loopFly()",3000);
 
 }

 function run_mega_menu(item){
 
  if(stop_mega_menu == 1) return;
 
  $(".baner_controls img:eq("+item+")").trigger("click",function(){
  
  });
  
  if(item < mega_menu_total_item){
  
  item++;
 
  }else{
  
   item = 0;
  
  }
 
    mega_menu_time = setTimeout("run_mega_menu("+item+")",9000);

 
 }

 function run_top_hotel(item){

  if(stop_top_hotel == 1) return;
 
  $(".control_th li a:eq("+item+")").trigger("click");
  
  if(item < top_hotel_total_item){
  
  item++;
 
  }else{
  
   item = 0;
  
  }
 
    top_hotel_time = setTimeout("run_top_hotel("+item+")",6000);

 
 }

function hotelsearchresults(){
 
    $("#searchajaxhotel").css("visibility","visible");
         
         $.post("/ajax/wyszukiwarka_hoteli.php",{hotel:$("#ihotelsearch").val()},function(htmlr,stat){
  

		   res = htmlr.split("::");
		   
		   if(res[0] == $("#ihotelsearch").val()){
  
             $("#tipshotelssearch").html(res[1]);
			 
			 $("#searchajaxhotel").css("visibility","hidden");
		   
		   }

  
         });
 
 }
 
			function openhotelprompt(){
			
				var temp = {
					state0: {
						html:"<table style='font-size:12px;text-align:center;'><tr><td rowspan='2'><img width='150' height='100' src='/images/searchhotel.jpg'/></td><td style='text-align:left;'><div style='border:1px solid #dddcda;width:240px;height:25px;-moz-border-radius-bottomleft:10px;-moz-border-radius-topright:10px;-moz-border-radius-bottomright:10px;-moz-border-radius-topleft:10px;-webkit-border-top-right-radius:10px;-webkit-border-top-left-radius:10px;-webkit-border-bottom-left-radius:10px;-webkit-border-bottom-right-radius:10px;'><input type='text' onclick='this.value=\"\"' id='ihotelsearch' style='font-size:12px;font-family:Arial;width:220px;border:0px;margin:5px 0px 5px 10px;' value='nazwa hotelu'/></div></td><td><img id='searchajaxhotel' style='vertical-align:middle;visibility:hidden;' width='30' height='30' src='/images/searching.gif'/></td></tr><tr><td colspan='2'><div style='border:1px solid #dddcda;-moz-border-radius-bottomleft:10px;-moz-border-radius-topright:10px;-moz-border-radius-bottomright:10px;-moz-border-radius-topleft:10px;-webkit-border-top-right-radius:10px;-webkit-border-top-left-radius:10px;-webkit-border-bottom-left-radius:10px;-webkit-border-bottom-right-radius:10px;'><div style='overflow-y:scroll;width:300px;height:150px;text-align:left;margin:4px 5px 4px 0px;font-size:12px;font-family:Arial;'><ul id='tipshotelssearch' style='margin:10px 0px 0px 10px;padding:0px;list-style:none;'></ul></div></div></td></tr></table>",
					    buttons: { OK: true,Anuluj: false },
						submit:function(v,m,f){ 
							if(!v){
								
								$(".katcc:checked").each(function(){
								
								 document.location.href = $(this).val();
								
								});
								
								return true;
								
							}else{
							
							 document.location.href="/search?id=3&filtr=data_asc&kraj=null&data_od=null&data_do=null&hotel=like_"+encodeURIComponent($("#ihotelsearch").val())+"&pokoj=null&wyzywienie=null&wylot=null&dni=null&cena=null&dorosli=1&ch1=null&ch2=null&standard=null&oferta=all&udogodnienia=&seasonid=";
							
							return false; 
							
							}
						}
					}
				}
				
				$.prompt(temp);
			}


			function openmap(latitude,longitude){
				var temp = {
					state0: {
						html:'<iframe style="height:400px;width:650px;border:0px;" src="/punktysprzedazy/mapa?gtype=1&lat='+latitude+'&long='+longitude+'"></iframe>',
					    buttons: { OK: true,Anuluj: false },
						submit:function(v,m,f){ }
					}
				}
				
				$.prompt(temp);
				$(".jqi").css("width","700px");
			}
