jQuery(function($){
	var frontend = 
	{
		init:function()
		{
			//this.langSelector();
			this.bookingForm();
			this.accommodationBox();
			this.lightBox();
			this.FAQ();
			this.accommodationGallery();
			this.IE();
			this.toolTipInit();
			this.descriptionToolTip();
		},
		
		langSelector:function()
		{
			if($('#LanguageSwitcher').length)
			{
				$('#LangTrigger').click(function(){
					var top = $('#SwitchInner').css('top');
					if(top == '0px')
					{
						$('#SwitchInner').animate({ top: '-26px' }, 'fast');	
					}
					else
					{
						$('#SwitchInner').animate({ top: 0 }, 'fast');	
					}
					
					return false;
				});
			}
		},
		
		bookingForm:function()
		{
			$('<div id="AccommodationType"><ul><li><a href="#ShortTermForm" title="Short Term" id="Short">Short Term (4 days or more)</a></li><li><a href="#LongTermForm" title="Long Term" id="Long">Long Term (3 to 12 months)</a></li></ul></div>').insertAfter('#BookingForm h2');
			
			if($("#BookingForm").hasClass("short-tab"))
			{
				$('#LongTermForm').hide();
				$('#Short').addClass('selected');
			}
			else
			{
				$('#ShortTermForm').hide();
				$('#LongTermForm').show();
				$('#Long').addClass('selected');
			}
		
			if ($('#AccommodationType').length) {
					$('#AccommodationType a').click(function(){
						$('#AccommodationType a').removeClass('selected');
						$(this).addClass('selected');
						if ($(this).attr('id') == 'Short') {
							$('#ShortTermForm').show();
							$('#LongTermForm').hide();
						}
						else {
							$('#LongTermForm').show();
							$('#ShortTermForm').hide();
						}
						
						return false;
					});
					
				}	
		},
		
		accommodationBox:function()
		{
			$('div.accommodation-box').hover(function()
			{
				$(this).css('cursor', 'pointer');
				$(this).find('a').css('color', '#ff0000');
				
			},
			function()
			{
				$(this).find('a').css('color', '#fff');
			}
			).click(function()
			{
				var href = $(this).find('a').attr('href');
				window.location = href;
				return false;
			});
		},
		
		lightBox:function()
		{
			if($('#Photos').length || $('#AccommodationGallery').length)
			{
				$("a[rel='lightbox']").lightBox({
		        	imageLoading: 'mysite/javascript/lightbox/images/lightbox-ico-loading.gif', // (string) Path and the name of the loading icon
		        	imageBtnPrev: 'mysite/javascript/lightbox/images/lightbox-btn-prev.gif', // (string) Path and the name of the prev button image
		        	imageBtnNext: 'mysite/javascript/lightbox/images/lightbox-btn-next.gif', // (string) Path and the name of the next button image
		        	imageBtnClose: 'mysite/javascript/lightbox/images/lightbox-btn-close.gif', // (string) Path and the name of the close btn
		        	imageBlank: 'mysite/javascript/lightbox/images/lightbox-blank.gif'
	    		});
			}
		},
		
		FAQ: function(){
			if ($('#Questions').length) 
			{
				$('dt:even').css('background', '#edf2f8').next('dd').css('background', '#edf2f8');
				$('dl').hide();
				$('#MainContent h3').css('cursor', 'pointer').hover(
				function(){
					$(this).addClass('hover');
				},
				function(){
					$(this).removeClass('hover');
				})
				.click(function(){
					if($(this).hasClass('active'))
					{
						$(this).removeClass('active');
						$(this).next('dl').slideUp();
					}
					else{
						$('#MainContent h3').removeClass('active');
						$('dl').slideUp();
						$(this).toggleClass('active').next('dl').slideToggle();
					}
					
				});	
			}
		},
		
		accommodationGallery:function()
		{
			if ($('#AccommodationGallery').length) 
			{
				$('#Mediums li').css('visibility', 'hidden').eq(0).css('visibility', 'visible');
				$('#Thumbs a').hover(function(){
					$("#Mediums li").css("visibility", "hidden");
					$("#Mediums li a[href='" + $(this).attr("href") + "']").parent().css("visibility", "visible");
				}).click(function(){
					return false;
				});
			}
		},
		
		IE:function()
		{
			if (!$.support.opacity) 
			{
				$("ul#Sub > li").hover(function(e){
					$(this).addClass("hover");
				}, function(e){
					$(this).removeClass("hover");
				});
				$('#BookingForm').corner('5px');
				$('#ShortTermForm').corner('5px');
				$('#LongTermForm').corner('5px');
				$('.box').corner('5px');
				$('#LangTrigger').corner('3px br cc:#3c669e').corner('3px bl cc:#3c669e');
			}
		},
		
		toolTipInit:function()
		{
			if($('#CardSecurityNum').length > 0)
			{
				var src = $('base')[0].href;
				src = src + "themes/default/images/security-code.jpg";
				var c = "<p>The card security code is a three- or four-digit value found mostly on the back of the card, unembossed, as the final group of numbers on the back signature panel.</p><p>American Express usually has four numbers on the front side.</p><img src='"+src+"' alt='security code' width='300' height='79'>";
				$('#CardSecurityNum a').tooltip({
					showURL:false,
					bodyHandler:function(){ return c;},
					delay:0					
				}).click(function(){ return false; }).css('cursor', 'default');
			}
		},
		
		descriptionToolTip:function()
		{
			if ($('.description').length)
			{
				$('.ShorttermSearchPage table.booklist tr').each(function(){
					var $desc = $(this).find('.description');
					if ($desc.length) {
						$(this).tooltip({
							showURL: false,
							bodyHandler: function(){
								var c = $desc.html();
								return c;
							},
							delay: 0
						});
					}
				});
			}
		}
	}
	frontend.init();
	
	$("a[rel*='external']").click(function(){
	  	this.target = "_blank";
	});
});



