$(document).ready(function(){

$("a[rel=group_photos]").fancybox({
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});

$("a.one_photo").fancybox({'overlayShow':true, 'transitionIn':'elastic', 'transitionOut':'elastic'});

$(".galery_show").click(function(){
var pic=$(this).attr("rel");
	$(".main_galery .pict img").attr("src",pic);
	$(".main_galery .pict a").attr("href","main_galery/big/"+pic.substr(18));
});

$(".dialog_show").click(function(){
var link=$(this).attr("rel");
$.ajax(
  	{
  		url:"ajax/"+link+".php",
  		type: "POST",
  		cache: false,
  		success: function(data){
			$(".dialog").html(data).dialog({modal: true, resizable: false, width: "370px",position: 'center'});
		}
	});
});

jQuery.fn.input_tip = function(){
$('input[type=text],input[type=password]').each(function(){
var show_text=null;
var inp=0;
	show_text=$(this).attr("rel");
	if(show_text!=null){
		if($(this).val().length==0)$(this).val(show_text);
		$(this).focus(function(){
			if($(this).val()==show_text && inp==0)$(this).val('');
		}).focusout(function(){
			if($(this).val().length==0){$(this).val(show_text);inp=0;}
		}).keydown(function(){
			inp++;
		});
	}
});}
$().input_tip();

$(".hotel_room_div").click(function(){
$(".hotel_room_div").each(function(){
$("#addit_info"+$(this).attr('rel')).fadeOut(0);
});
var out_id=$(this).attr('rel');

$("#addit_info"+out_id).toggle();
});
	
var dates = $( "#from, #to" ).datepicker({
			changeMonth: true,
			numberOfMonths: 2,
			onSelect: function( selectedDate ) {
				var option = this.id == "from" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
				
			}
});


$("#search_form").submit(function(){
	
	 var ret_value=0;

	$.ajax(
		{
			url:"ajax/check_date.php",
			type: "POST",
			cache: false,
			async: false,
			data:({"start_date":$("#from").val(),"end_date":$("#to").val()}),
			success: function(data){
				if(data.length>0){alert(data);}else ret_value=1;
			}
		});
		if(ret_value==1)return true;
		
return false;
});

$(".change_prices").click(function(){
var link=$(this).attr("rel");
 link=link.split('|');

$.ajax(
  	{
  		url:"ajax/"+link[0]+".php",
  		type: "POST",
  		cache: false,
		data:({"var_1":link[1],"var_2":link[2],"var_3":link[3],"var_4":link[4]}),
  		success: function(data){
			$(".dialog").html(data).dialog({modal: true, resizable: false, width: "570px",position: 'center'});
		}
	});
});
});
