String.prototype.trim = function () {return this.replace(/^\s*/, "").replace(/\s*$/, "");}

var timeoutObjectsKey = 1;
var timeoutObjects = new Array();
var timeoutInit = function(ob){if(!ob.timeoutObjects)ob.timeoutObjects=timeoutObjectsKey++;timeoutObjects[ob.timeoutObjects]=ob;clearTimeout(ob.timeOut);}
var slideChildren = function(ob, slideRotateSpeed){
	if(!ob) return;
	ob=timeoutObjects[ob];
	if($('.to-slide:visible', $(ob)).size()==1) $('.to-slide:last', $(ob)).fadeIn(slideRotateSpeed, function(){$('.to-slide', $(this).parents('.slides-container')).show();});
	else $('.to-slide:visible:last', $(ob)).fadeOut(slideRotateSpeed);
}
var slideChildrens = function(ob, slideRotateTimeOut, slideRotateSpeed){
	$(ob).each(function(){
		if ($('.to-slide',this).size() > 1){
			$(this).addClass('slides-container');
			$($.makeArray($('.to-slide:hidden', $(ob))).reverse()).each(function(){$(this).show()});//.show();
			$(this).css('height',$(this).height()+'px');
			$('.to-slide',this).css('position','absolute');
			timeoutInit(this);
			setInterval("slideChildren("+this.timeoutObjects+","+slideRotateSpeed+")",slideRotateTimeOut);
		}
	});
}
var mousestopScroll = function(ob){if(!ob)return;ob=timeoutObjects[ob];$('.scroll-trigger',$(ob)).fadeIn().stop();}
var mouseoverScroll = function(ob){if(!ob || !(ob=timeoutObjects[ob]) || ($('.to-slide',$(ob)).height()<=$(ob).height()))return;$('.scroll-trigger',$(ob)).fadeIn().fadeTo('fast',0.9);}
var mouseoutScroll = function(ob){if(!ob)return;ob=timeoutObjects[ob];$('.scroll-trigger',$(ob)).fadeOut();}
var scrollScroll = function(ob,m,s){if(!ob.m) ob.m=0;ob.min = $(ob.parentNode).height()-$(ob).height();if((ob.m==0 && ob.m+m>0)||(ob.min>ob.m+m && ob.m==ob.min))return;if(ob.m+m>0||ob.min>ob.m+m)ob.m=(ob.m+m>0)?0:ob.min;else ob.m+=m;$(ob).stop().animate({top:ob.m},(s?s:'slow'));}

var mouseblockAreaBox = 0;
var mouseblockArea = 0;
var mousestopAreaBox = function(ob){if(!ob || mouseblockArea)return;ob=timeoutObjects[ob];$(ob).stop();}
var mouseoverAreaBox = function(ob){if(!ob || mouseblockArea || !(ob=timeoutObjects[ob]))return;$('.FindAHotel-absolute').show();$(ob).animate({left:0});}
var mouseoutAreaBox = function(ob){if(!ob || mouseblockArea)return;ob=timeoutObjects[ob];$(ob).animate({left:361},function(){if(!mouseblockArea && !mouseblockAreaBox)$('.FindAHotel-absolute').hide();});}
var mousestopArea = function(ob){if(!ob || mouseblockAreaBox)return;ob=timeoutObjects[ob];if(!$(ob).attr('class'))return;$('.'+$(ob).attr('class'),$(ob.parentNode.parentNode.parentNode.parentNode)).stop();}
var mouseoverArea = function(ob){if(!ob || mouseblockAreaBox || !(ob=timeoutObjects[ob]))return;$('.FindAHotel-absolute').show();if(!$(ob).attr('class'))return;$('.'+$(ob).attr('class'),$(ob.parentNode.parentNode.parentNode.parentNode)).css('z-index',1).animate({left:0});}
var mouseoutArea = function(ob){if(!ob || mouseblockAreaBox)return;ob=timeoutObjects[ob];if(!$(ob).attr('class'))return;$('.'+$(ob).attr('class'),$(ob.parentNode.parentNode.parentNode.parentNode)).css('z-index',0).animate({left:361},function(){if(!mouseblockArea && !mouseblockAreaBox)$('.FindAHotel-absolute').hide();});}

var i=0;
var mouseblockDropDownHotelsDD = false;
var mouseblockDropDownHotels = false;
var mousestopDropDownHotelsDD;
var mouseoverDropDownHotelsDD; 
var mouseoutDropDownHotelsDD;
var mousestopDropDownHotels;
var mouseoverDropDownHotels; 
var mouseoutDropDownHotels;

$(document).ready(function(){
	$('form.ajax-js').ajaxForm({url:$(this).attr('action'),success:function(responseText, statusText, xhr, $form){eval(responseText);}}).removeClass('ajax-js').removeClass('ajax');
	$('form.ajax').ajaxForm({url:$(this).attr('action')});

	$('.fb').each(function(){
		//$(this).html('<fb:fan profile_id="93162827921" stream="" connections="" width="'+$(this).width()+'" height="'+$(this).height()+'"></fb:fan>');
		$(this).html('<iframe src="http://www.facebook.com/plugins/fan.php?id=93162827921&amp;width=278&amp;connections=0&amp;stream=false&amp;header=false&amp;height=60" scrolling="no" frameborder="0" style="border:none;overflow:hidden;width:278px;height:60px;" allowTransparency="true"></iframe>');
	});
	$('.autocomplete-off').each(function(){$(this).attr('autocomplete','off')});

	if($.browser.msie){
		$('.dropdown-hotels').css('height','0').css('display','block');
		mousestopDropDownHotelsDD = function(ob){if(!ob || mouseblockDropDownHotels)return;mouseblockDropDownHotelsDD=false;ob=timeoutObjects[ob];$(ob).stop();}
		mouseoverDropDownHotelsDD = function(ob){if(!ob || mouseblockDropDownHotelsDD || mouseblockDropDownHotels || !(ob=timeoutObjects[ob]))return;mouseblockDropDownHotelsDD=true;$(ob).animate({height:'260px'});} 
		mouseoutDropDownHotelsDD = function(ob){if(!ob || mouseblockDropDownHotels)return;mouseblockDropDownHotelsDD=false;ob=timeoutObjects[ob];$(ob).animate({height:'0'});}
		mousestopDropDownHotels = function(ob){if(!ob || mouseblockDropDownHotelsDD)return;mouseblockDropDownHotels=false;ob=timeoutObjects[ob];$('.dropdown-hotels',$(ob)).stop();}
		mouseoverDropDownHotels = function(ob){if(!ob || mouseblockDropDownHotels || mouseblockDropDownHotelsDD || !(ob=timeoutObjects[ob]))return;mouseblockDropDownHotels=true;$('.dropdown-hotels',$(ob)).animate({height:'260px'});} 
		mouseoutDropDownHotels = function(ob){if(!ob || mouseblockDropDownHotelsDD)return;mouseblockDropDownHotels=false;ob=timeoutObjects[ob];$('.dropdown-hotels',$(ob)).animate({height:'0'});}
	}else{
//		$('.dropdown-hotels').fadeOut(0).css('height','auto').css('display','block');
		$('.dropdown-hotels').fadeTo(0,0).css('height','auto').css('display','none');
		//.fadeTo(500,0,function(){$(this).css('display','none')}) -> .fadeOut()
		//.css('display','block').fadeTo(500,1) -> .fadeIn()
		mousestopDropDownHotelsDD = function(ob){if(!ob || mouseblockDropDownHotels)return;mouseblockDropDownHotelsDD=false;ob=timeoutObjects[ob];$(ob).stop();}
		mouseoverDropDownHotelsDD = function(ob){if(!ob || mouseblockDropDownHotelsDD || mouseblockDropDownHotels || !(ob=timeoutObjects[ob]))return;mouseblockDropDownHotelsDD=true;$(ob).css('display','block').fadeTo('normal',1);} 
		mouseoutDropDownHotelsDD = function(ob){if(!ob || mouseblockDropDownHotels)return;mouseblockDropDownHotelsDD=false;ob=timeoutObjects[ob];$(ob).fadeTo('normal',0,function(){$(this).css('display','none')});}
		mousestopDropDownHotels = function(ob){if(!ob || mouseblockDropDownHotelsDD)return;mouseblockDropDownHotels=false;ob=timeoutObjects[ob];$('.dropdown-hotels',$(ob)).stop();}
		mouseoverDropDownHotels = function(ob){if(!ob || mouseblockDropDownHotels || mouseblockDropDownHotelsDD || !(ob=timeoutObjects[ob]))return;mouseblockDropDownHotels=true;$('.dropdown-hotels',$(ob)).css('display','block').fadeTo('normal',1);} 
		mouseoutDropDownHotels = function(ob){if(!ob || mouseblockDropDownHotelsDD)return;mouseblockDropDownHotels=false;ob=timeoutObjects[ob];$('.dropdown-hotels',$(ob)).fadeTo('normal',0,function(){$(this).css('display','none')});}
	}
	if($('.dropdown-hotels-trigger').size()){
		$('.dropdown-hotels-trigger-dd').
			live('mouseover', function(e){timeoutInit(this);setTimeout('mousestopDropDownHotelsDD('+this.timeoutObjects+')',1);this.timeOut=setTimeout('mouseoverDropDownHotelsDD('+this.timeoutObjects+')',5);}).
			live('mouseout', function(e){timeoutInit(this);setTimeout('mousestopDropDownHotelsDD('+this.timeoutObjects+')',1);this.timeOut=setTimeout('mouseoutDropDownHotelsDD('+this.timeoutObjects+')',200);});
		$('.dropdown-hotels-trigger').
			live('mouseover', function(e){timeoutInit(this);setTimeout('mousestopDropDownHotels('+this.timeoutObjects+')',1);this.timeOut=setTimeout('mouseoverDropDownHotels('+this.timeoutObjects+')',5);}).
			live('mouseout', function(e){setTimeout('mousestopDropDownHotels('+this.timeoutObjects+')',1);this.timeOut=setTimeout('mouseoutDropDownHotels('+this.timeoutObjects+')',200);});
	}
	$('.review-description-rm').live('click',function(){$(this).css('display','none').next().css('display','inline');});
	$('.review-description-rl').live('click',function(){$(this.parentNode).css('display','none').prev().css('display','inline');});


	$("select[name=doa_dd]").change(function(){$('#doa_linked',$(this).parents('form')).val($(this).next().val()+'-'+$(this).val());});
	$("select[name=doa_mm]").change(function(){$('#doa_linked',$(this).parents('form')).val($(this).val()+'-'+$(this).prev().val());});
	$("input[name=InDate]").change(function(){$("input[name=InDate]").val($(this).val());updateLinked($(this).val());});
	var maxDate=((new Date(1900+new Date().getYear(),new Date().getMonth()+$("select[name=doa_mm]:first option").size(),0))-(new Date(1900+new Date().getYear(),new Date().getMonth(),new Date().getDate())))/(24*60*60*1000);
	$("input#doa_linked").datepicker({
		dateFormat:'yy-mm-dd',
		navigationAsDateFormat: true,
		showOn: "both",
		minDate: '0',
		maxDate: maxDate,
		onSelect: function(date){$("select[name=doa_dd]").val(date.substring(8,10));$("select[name=doa_mm]").val(date.substring(0,7));},
		buttonImage: "/files/images/a/callendar-trigger.png",
		buttonImageOnly: true,
		firstDay: 1
	});
	
	if($('.FindAHotel').size() && $('map[name=locations] area').size()){
		$('.FindAHotel').
			bind('mouseover', function(){mouseblockAreaBox++;timeoutInit(this);setTimeout('mousestopAreaBox('+this.timeoutObjects+')',1);this.timeOut=setTimeout('mouseoverAreaBox('+this.timeoutObjects+')',5);}).
			bind('mouseout', function(){mouseblockAreaBox--;timeoutInit(this);setTimeout('mousestopAreaBox('+this.timeoutObjects+')',1);this.timeOut=setTimeout('mouseoutAreaBox('+this.timeoutObjects+')',300);});
		$('map[name=locations] area').
			bind('mouseover', function(){mouseblockArea++;timeoutInit(this);setTimeout('mousestopArea('+this.timeoutObjects+')',1);this.timeOut=setTimeout('mouseoverArea('+this.timeoutObjects+')',5);}).
			bind('mouseout', function(){mouseblockArea--;timeoutInit(this);setTimeout('mousestopArea('+this.timeoutObjects+')',1);this.timeOut=setTimeout('mouseoutArea('+this.timeoutObjects+')',300);});
	}
	
	$('.scroll-childrens-topright').
		bind('mouseover', function(){timeoutInit(this);setTimeout('mousestopScroll('+this.timeoutObjects+')',1);this.timeOut=setTimeout('mouseoverScroll('+this.timeoutObjects+')',5);}).
		bind('mouseout', function(){timeoutInit(this);setTimeout('mousestopScroll('+this.timeoutObjects+')',1);this.timeOut=setTimeout('mouseoutScroll('+this.timeoutObjects+')',5);});

	$('.scroll-trigger-99').
		click(function(){scrollScroll($('.to-slide',$(this.parentNode)).get(0),($(this).hasClass('scroll-trigger-bottom')? -99:99));}).
		dblclick(function(){scrollScroll($('.to-slide',$(this.parentNode)).get(0),2*($(this).hasClass('scroll-trigger-bottom')? -99:99));});

	$('.scroll-trigger-139').
		click(function(){scrollScroll($('.to-slide',$(this.parentNode)).get(0),($(this).hasClass('scroll-trigger-bottom')? -139:139));}).
		dblclick(function(){scrollScroll($('.to-slide',$(this.parentNode)).get(0),2*($(this).hasClass('scroll-trigger-bottom')? -139:139));});

	$('input.text[type=text],textarea.text').
		focus(function(){$(this).removeClass($(this).attr('alt')+'-filled');if($(this).val().trim()==$(this).attr('title').trim()) $(this).val('');}).
		blur(function(){if(!$(this).val().trim()){$(this).val($(this).attr('title').trim());$(this).removeClass($(this).attr('alt')+'-filled');}}).
		change(
			function(){
				$(this).val($(this).val().trim());
				if($(this).val() && $(this).val()!=$(this).attr('title').trim()) $(this).addClass($(this).attr('alt')+'-filled');
				else $(this).removeClass($(this).attr('alt')+'-filled');
			}
		);

	slideChildrens($('.slide-childrens-topimages'),4000,1000);
	slideChildrens($('.slide-childrens-topright'),8000,500);

	if($.browser.msie){
		$('select').
			hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover');}).
			focus(function(){$(this).addClass('focus');}).
			blur(function(){$(this).removeClass('focus');});
		if($.browser.version < 8){
			$('input.text[type=text]').
				hover(function(){$(this).addClass($(this).attr('alt')+'-hover');},function(){$(this).removeClass($(this).attr('alt')+'-hover');}).
				focus(function(){$(this).addClass($(this).attr('alt')+'-focus');}).
				blur(function(){$(this).removeClass($(this).attr('alt')+'-focus');});
		}else if($.browser.version < 7){
			$('.dropdown-hotels-trigger').addClass('dropdown-hotels-trigger-ie6');
		}
	}
})