﻿// var photoscounter=0;
var currentphoto=0;
var currentcurrency=3; // 0-RUR 1-USD 2-EUR 3-UAH


// Показываем блымалку над телефонами
function phonesHint() {
	$('#phones-hint').css('display','block'); 
	$('#phones-hint').animate({ opacity: 1 }, 250); 
	$('#phones-hint').animate({ marginTop: -40 }, 250);
	$('#phones-hint').animate({ marginTop: -45 }, 250);
	$('#phones-hint').animate({ marginTop: -40 }, 250);
	$('#phones-hint').animate({ marginTop: -45 }, 250);
	$('#phones-hint').animate({ marginTop: -40 }, 250);
	$('#phones-hint').animate({ marginTop: -45 }, 250);
	$('#phones-hint').animate({ marginTop: -40 }, 250);
	$('#phones-hint').animate({ marginTop: -45 }, 250);
	$('#phones-hint').animate({ opacity: 0}, 250); 

	setTimeout("$('#phones-hint').css('display','none'); " ,2500);


}


$(document).ready(function() {


jQuery("#slider").slider({
	min: 0,
	max: 200,
	values: [0],
	range: false,
	step: 40,
	stop: function(event, ui) {
		value01 = jQuery("#slider").slider("values",0);
		
		if(value01 == 0){
			vL1 = '_all_';
			jQuery("input#mcost").val('Любая');
			jQuery("input#price_filter").val('0');
			ChPriceFilter();
		}
		else
		if(value01 <= 40){
			vL1 = 0;
			if (global_valuta=="rur") jQuery("input#mcost").val('до 1900'); else
			if (global_valuta=="usd") jQuery("input#mcost").val('до 65'); else
			if (global_valuta=="eur") jQuery("input#mcost").val('до 50'); else
			jQuery("input#mcost").val('до 500'); 
			jQuery("input#price_filter").val('104');
			ChPriceFilter();
		}
		else
		if((value01 > 40)&&(value01<=80)){
			vL1 = 500;
			if (global_valuta=="rur") jQuery("input#mcost").val('от 1900 до 2700'); else
			if (global_valuta=="usd") jQuery("input#mcost").val('от 65 до 90'); else
			if (global_valuta=="eur") jQuery("input#mcost").val('от 50 до 70'); else
			jQuery("input#mcost").val('от 500 до 700');
			jQuery("input#price_filter").val('105');
			ChPriceFilter();
		}
		else
		if((value01 > 80)&&(value01<=120)){
			vL1 = 700;
			if (global_valuta=="rur") jQuery("input#mcost").val('от 2700 до 3900'); else
			if (global_valuta=="usd") jQuery("input#mcost").val('от 90 до 130'); else
			if (global_valuta=="eur") jQuery("input#mcost").val('от 70 до 100'); else
			jQuery("input#mcost").val('от 700 до 1000');
			jQuery("input#price_filter").val('106');
			ChPriceFilter();
		}
		else
		if((value01 > 120)&&(value01<=160)){
			vL1 = 1000;
			if (global_valuta=="rur") jQuery("input#mcost").val('от 3900 до 5800'); else
			if (global_valuta=="usd") jQuery("input#mcost").val('от 130 до 190'); else
			if (global_valuta=="eur") jQuery("input#mcost").val('от 100 до 150'); else
			jQuery("input#mcost").val('от 1000 до 1500');
			jQuery("input#price_filter").val('107');
			ChPriceFilter();
		}
		else
		{
			vL1 = 1500;
			if (global_valuta=="rur") jQuery("input#mcost").val('от 5800 и выше'); else
			if (global_valuta=="usd") jQuery("input#mcost").val('от 190 и выше'); else
			if (global_valuta=="eur") jQuery("input#mcost").val('от 150 и выше'); else
			jQuery("input#mcost").val('от 1500 и выше');
			jQuery("input#price_filter").val('108');
			ChPriceFilter();
		};
		
		
	
    }
});
/*
var to;
if (global_valuta=="rur") to = 160000; else 
if (global_valuta=="usd") to = 5000; else 
if (global_valuta=="eur") to = 4000; else 
to = 40000;
jQuery("#sliderm").slider({
	min: 0,
	max: to,
	values: [0, to],
	range: true,
	step: 100,
	stop: function(event, ui) {
		value0 = jQuery("#sliderm").slider("values",0);
		value1 = jQuery("#sliderm").slider("values",1);
		jQuery("input#pricem").val(value0 + "-" + value1);
		jQuery("input#pricem1").val(value0+'');	
		jQuery("input#pricem2").val(value1+'');		
    }
});
	var value0 = jQuery("#sliderm").slider("values",0);
	var value1 = jQuery("#sliderm").slider("values",1);
	jQuery("input#pricem").val(value0 + "-" + value1);
	jQuery("input#pricem1").val(value0+'');	
	jQuery("input#pricem2").val(value1+'');	
*/

// Вызываем блымалку над телефонами
	setTimeout("phonesHint();" ,1000);   
	setTimeout("phonesHint();" ,7000);

// Устанавливаем ширину контейнера с баннерами
	$('#slider-container-inner').css("width", photoscounter*460+'px');

// Назначем кнопочки слайдера лево и право для баннера
	$("#slider-right").click( function () {
		sliderclickright()
	});


	$("#slider-left").click( function () {
		sliderclickleft();
	});


// Назначаем действие при наведении на телефоны
	$("#phones-t-title").hover(
	  function () { 
		$('#phones-a').animate({ width: 31 }, 350);  
		$('#phones-a-title').animate({ backgroundPosition: '-31px' }, 0);  
		$('#phones-t').animate({ width: 248 }, 350);  
		$('#phones-t-title').animate({ backgroundPosition: '-31px' }, 0);  
	  });

	$("#phones-a-title").hover(
	  function () { 
		$('#phones-t').animate({ width: 31 }, 350);  
		$('#phones-t-title').animate({ backgroundPosition: '0px' }, 0);    

		$('#phones-a').animate({ width: 248 }, 350);  
		$('#phones-a-title').animate({ backgroundPosition: '0px' }, 0);    

	  });


// Инициализируем выпадающее меню
   $('#nav li').hover(
        function () {
            //show its submenu
            $('ul', this).slideDown(100);
 
        },
        function () {
            //hide its submenu
            $('ul', this).slideUp(100);        
        }
    );


// Наведение на звездочку в шапке для показа блока

   $('#nyan-button').click(
        function () {
	  $('#nyan').animate({marginTop: 0}, 450); 
        }
    );

   $('#nyan').mouseout(function() {
      $('#nyan').animate({marginTop: -200}, 450); 
   });

// Инициализируем тултипы
$('.tooltip').tooltip({
	track: true,
	delay: 0,
	showURL: false,
	showBody: " - ",
	fade: 250
});

// Разворачивалка валюты
   $('.currency-selector .current').hover(
        function () {
	 if (!jQuery.browser.msie) {
	  	$('.currency-selector #selector-list').css('display','block');
	        $('.currency-selector #selector-list').animate({height: 80}, 250);        
	 } else {
	  	$('.currency-selector #selector-list').css('display','block');
	 }
   	},
        function() {

	 if (!jQuery.browser.msie) {
	  	$('.currency-selector #selector-list').animate({height: 0 }, 150);        
	  	setTimeout("$('.currency-selector #selector-list').css('display','none');",150);
	 } else {
	  	$('.currency-selector #selector-list').css('display','none');
	 }

	  
   	});



// Выбор региона
   dropdown('#tl-region');
   dropdown('#tl-region2');
   dropdown('#tl-regionm');
   dropdown('#tl-resortm');
   dropdown('#tl-hotelm');




// Включаем скроллбары
   $(".jScrollbar").jScrollbar({ allowMouseWheel : true });     
   $(".jScrollbar2").jScrollbar({ allowMouseWheel : true });     



// Работа с типами отеля

   settltype(0);
   settltype(1);
   settltype(2);
   settltype(3);
   settltype(4);
   settltype(5);
   settltype(6);



// Назначем время листания слайдера

setInterval("sliderclickright()",10000);



});



function dropdown(a) {
	
   $(a).click(
        function () {	
	 if ( $(a+' .tl-result-null').css('display')=='none' ) {
                closedropdown();
		$(a).css('z-index','3000');

	 	if (!jQuery.browser.msie) {
	  		$(a+' .tl-result-null').css('display','block');
	        	$(a+' .tl-result-null').animate({height: 120}, 250);        
	  		$(a).css('background-color','#e7eaec');	
	 	} else {
	  		$(a+' .tl-result-null').css('display','block');
	  		$(a).css('background-color','#e7eaec');
	 	}
	
		$(".jScrollbar2").jScrollbar({ allowMouseWheel : false });
	 } else {
 		if (!jQuery.browser.msie) {
	  		$(a+' .tl-result-null').animate({height: 0 }, 150);
			var b="$('"+a+" .tl-result-null').css('display','none');";
	  		setTimeout(b,150);	
  			$(a).css('background-color','#f3f3f3');
 		} else {
		  	$(a+' .tl-result-null').css('display','none');
		  	$(a).css('background-color','#f3f3f3');
	 	}
		
		$(a).css('z-index','0');



		
		}

});}


function closedropdown() {

js_mask = $('.jScrollbar_mask');
js_drag = $('.jScrollbar_draggable a.draggable');
js_mask.css({top:0});
js_drag.css({top:0});

var arr=['#tl-region', '#tl-region2', '#tl-regionm', '#tl-resortm', '#tl-hotelm', '#tl-rcname'];

for (var i=0; i<arr.length; i++) {
	var a=arr[i];

      	 if ( $(a+' .tl-result-null').css('display')=='block' ) { 

      		if (!jQuery.browser.msie) {
	  		$(a+' .tl-result-null').animate({height: 0 }, 150);
			var b="$('"+a+" .tl-result-null').css('display','none');";
	  		setTimeout(b,150);	
  			$(a).css('background-color','#f3f3f3');
 		} else {
		  	$(a+' .tl-result-null').css('display','none');
		  	$(a).css('background-color','#f3f3f3');
	 	}
		
		$(a).css('z-index','0');


	 };
}
}


function closecurrency() {
	if (!jQuery.browser.msie) {
	  	$('.currency-selector #selector-list').animate({height: 0 }, 150);        
	  	setTimeout("$('.currency-selector #selector-list').css('display','none');",150);
	 } else {
	  	$('.currency-selector #selector-list').css('display','none');
	 }
}

function settltype(i) {
	var rest_type = '_all_';
	$('#tl-t'+i).click( function () {

	  if (i==1) rest_type='rest_san'; else
	  if (i==2) rest_type='rest_beach'; else
  	  if (i==3) rest_type='rest_spa'; else
	  if (i==4) rest_type='rest_conf'; else
	  if (i==5) rest_type='rest_excur'; else
	  if (i==6) rest_type='rest_molod'; else rest_type='_all_';


	   for (var a = 0; a <=6; a++) { 
		$('#tl-t'+a).css('background-color','#f3f3f3');
	   }
	   $('#tl-t'+i).css('background-color','#ff8e31');


//	document.getElementById("res_type").value = rest_type;
	ChRestTypes(rest_type,1);
//alert('a='+rest_type);


	if (i==1) {
		$('#tl-typecheck').css('display','block');
	} else {
		$('#tl-typecheck').css('display','none');
	}

   	});


}

function sliderclickright() {
		if (currentphoto>=photoscounter-1) {  
            		$('#slider-container-inner').animate({marginLeft: 0}, 550);
			currentphoto=0;
		} else {
 		$('#slider-container-inner').animate({marginLeft: -(currentphoto*460)-460}, 550);
		currentphoto++; 
		if (currentphoto==0) { currentphoto=1;}
}

	 	if (jQuery.browser.msie) { 
			$("#slider-left").css('marginLeft',(currentphoto)*460+418+'px');
			$("#slider-right").css('marginLeft',(currentphoto)*460+438+'px');
		}


}


function sliderclickleft() {
		if (currentphoto<=1) {  
            		$('#slider-container-inner').animate({marginLeft: -(photoscounter-1)*460}, 550);
			currentphoto=photoscounter;
		} else {
 		$('#slider-container-inner').animate({marginLeft: -((currentphoto-1)*460)+460}, 550);
		currentphoto--; }
		
	 	if (jQuery.browser.msie) { 	
			$("#slider-left").css('marginLeft',(currentphoto-1)*460+418+'px');
			$("#slider-right").css('marginLeft',(currentphoto-1)*460+438+'px');
		}
}


function ct1(i,ct_key) {
   $('#tl-title').html( $(i).html() );  
//   set_resorts(ct_key);
   $('#tl-title2').html( 'Все курорты' );  
   ChCity(ct_key);
}

function ct2(i,rs_key,ct_key) {
   $('#tl-title2').html( $(i).html() );  
   ChResorts(rs_key,ct_key);
}

