$(document).ready(
	function() {
		sidebarInfo.init();
		newsTicker.init();
	}
);


tab = {
	init : function(){  },
	vacationSearch : function(elementToOpen,caller){
		$('.packageWrap:not('+elementToOpen+')').hide();
		$(elementToOpen).show();

		$(caller).parent().parent().find('li').removeClass("current");
		$(caller).parent().addClass("current");
		vacationSearch.updateDaysLeft();
	}
}

newsTicker = {
	init : function(){
		newsTicker.currentItem = 0;
		newsTicker.newsItems = $("#topmenu div.newsTicker ul li").size();
		newsTicker.rightPull = $("#topmenu div.newsTicker ul li:eq(0)").width();

		$("#topmenu div.newsTicker ul li:eq(0)").css({'right':0, opacity: 1});
		$("#topmenu div.newsTicker ul li:gt(0)").css({'right':-newsTicker.rightPull, opacity: 0});

		setInterval(newsTicker.tickNews,2500); //time in milliseconds
	},
	tickNews : function(){
		$("#topmenu div.newsTicker ul li:eq("+newsTicker.currentItem+")").animate({ opacity: 0 }, 1000, "" ,function(){ $(this).css('right',-newsTicker.rightPull) } );
		newsTicker.currentItem = ++ newsTicker.currentItem % newsTicker.newsItems;
		$("#topmenu div.newsTicker ul li:eq("+newsTicker.currentItem+")").animate({ right:0, opacity: 1 }, 1000 );
	}
}

overlay = {
	open : function(pageToOpen,caller){
		overlay.displayLoader();

		overlay.buildOverlay();

		var currentTime = new Date();

		$('div#overlayContainer div.overlayContentContainer div.overlayContent').load(pageToOpen + "?=" + currentTime.getMilliseconds(),'',function(){
			// Position the overlay div according to thew buttons position
			$('div.overlayContainer').css({
				'top': $(caller).offset().top + $(caller).height() + 2,
				'left': $(caller).offset().left - 20
			});

			// Add the close button
			$(closeButton).attr('id','btnClose');
			$(closeButton).text('Close');
			$(closeButton).bind('click',function(){
				overlay.close('overlayContainer');
				return false;
			});
			$(this).append(closeButton);

			$('div#overlayContainer').animate({opacity:'show'},'fast');

			// Check if the overlay div appears outsite the body, if so, bring it back in
			if(($(caller).offset().left + $('div.overlayContainer').width()) > $('body').width()){
				$('div#overlayContainer').css({
					'left': 'auto',
					'right': 0
				});
			}
			//Once the page is loaded, we need to run ARC in case there are some forms
			$('div#overlayContainer div.overlayContentContainer div.overlayContent form').each(function(){
				initARC($(this).attr('id'), 'radioOn', 'radioOff', 'checkboxOn', 'checkboxOff');
			});

			$('#bigAjaxLoader').remove();
		});
	},
	close : function(which){
		$('div#'+ which).fadeOut('fast',function(){
			if(which != "passengerContainer" && which != "passengerContainerCustom" && which != "searchLoaderContainer"){$(this).remove();}
			$('div.overlay').fadeOut('fast',function(){
				$(this).remove();
				if(which == 'searchLoaderContainer'){
					location.href = overlay.cancelURL;
				}
			});
		});
	},
	buildOverlay : function(){
		// Build the background overlay div
		backgroundDiv = document.createElement('div');
		$(backgroundDiv).addClass('overlay');
		$(backgroundDiv).css({ 'height':$('body').height() });
		$(backgroundDiv).bind('click',function(){
			overlay.close('overlayContainer');
		});

		// Build the content overlay divs
		overlayContainer = document.createElement('div');
		$(overlayContainer).attr({'id':'overlayContainer'});
		$(overlayContainer).addClass('overlayContainer');

		overlayContentContainer = document.createElement('div');
		$(overlayContentContainer).addClass('overlayContentContainer');

		overlayContent = document.createElement('div');
		$(overlayContent).addClass('overlayContent').addClass('clearfix');

		closeButton = document.createElement('a')
		$(closeButton).attr({
			'id':'btnClose',
			'href':'#'
		});
		$(closeButton).text('Close');
		$(closeButton).bind('click',function(){ return false; });

		// Append the content
		$('body').append(backgroundDiv);
		$(overlayContentContainer).append(overlayContent);
		$(overlayContainer).append(overlayContentContainer);
		$('body').append(overlayContainer);

		// Then fade it in
		$('div.overlay').css('opacity',0);
		$('div.overlay').show();
		$('body').append(ajaxLoader);
		$('div.overlay').animate({opacity: 0.35}, 300, "");
	},
	displayLoader : function(){
		ajaxLoader = document.createElement('img')
		$(ajaxLoader).attr({
			'id':'bigAjaxLoader',
			'src':'/media/images/common/web/placeholders/ajax-loader.gif'
		});
		$(ajaxLoader).css({
			'position':'absolute',
			'top':'50%',
			'left':'50%'
		});
	},
	openPassenger : function(caller, which){
		if(which == 'custom'){
			divToOpen = $('div#passengerContainerCustom');
		}else{
			divToOpen = $('div#passengerContainer');
		}

		overlay.displayLoader();

		// Build the background overlay div
		backgroundDiv = document.createElement('div');
		$(backgroundDiv).addClass('overlay');
		$(backgroundDiv).css({'height':$(document).height()});
		$(backgroundDiv).bind('click',function(){
			overlay.close($(divToOpen).attr('id'));
		});

		$('body').append(backgroundDiv);
		$('div.overlay').css('opacity',0);
		$('div.overlay').show();
		$('div.overlay').animate({opacity: 0.35}, 300, "");

		divToOpen.animate({opacity:'show'},'fast');

		// Position the overlay div according to thew buttons position
		divToOpen.css({
			'z-index':10000,
			'top': $(caller).offset().top + $(caller).height() + 2,
			'left': $(caller).offset().left - 20
		});

		// Check if the overlay div appears outsite the body, if so, bring it back in
		if(($(caller).offset().left + divToOpen.width()) > $('body').width()){
			divToOpen.css({
				'left': 'auto',
				'right': 0
			});
		}

		$('#bigAjaxLoader').remove();
	},
	openHome : function(callingDiv) {
		$('div#' + callingDiv + ' div.overlayContainer').show();
		$('#homeContainer').css('overflow','visible');
	},
	openInsurance : function(divToOpen) {
		$('div#insuranceContainer' + divToOpen).css({
			'z-index':10000,
			'top': 2,
			'left': 80
		});

		$('div#insuranceContainer' + divToOpen).show();

	},
	closeInsurance : function(divToClose) {
		$('div#insuranceContainer' + divToClose).css({
				'display': 'none'
			});
	}
}


booking = {
	modify : function(caller) {
		// Open the modify div
		$('#passengersModify').animate({'height':'show'}, 'fast');
	},
	toggleChildren : function(caller,roomNumber){
		booking.callingDiv = $(caller).parents('div.overlayContainer');

		booking.desiredNumberOfChildren = $(caller).attr('value');
		booking.actualNumberOfChildren = $(booking.callingDiv).find('.withChildren table.bookingPassengersChildren tr.room-'+roomNumber+'.child').size();

		if(booking.desiredNumberOfChildren > booking.actualNumberOfChildren){
			// Want to ADD a room
			booking.addChildren(booking.actualNumberOfChildren + 1,roomNumber);
		}else{
			// Want to REMOVE a room
			$(booking.callingDiv).find('.withChildren table.bookingPassengersChildren tr.room-'+roomNumber+':gt('+(booking.desiredNumberOfChildren - 1)+')').remove();
			if($(booking.callingDiv).find('.withChildren table.bookingPassengersChildren tr.child').size() == 0){
				$(booking.callingDiv).find('.withChildren').hide();
			}
		}
	},
	addChildren : function(childrenNumber,roomNumber){
		var buttonValue = $("input[name=seRequestObj.searchType]:checked").val();
		if(booking.desiredNumberOfChildren >= booking.actualNumberOfChildren){
			booking.actualNumberOfChildren = childrenNumber + 1;

			$.get('/tips/addChildren.jsp?roomNumber='+roomNumber+'&childrenNumber='+childrenNumber,function(newChildMarkup){
				if($(booking.callingDiv).find('.withChildren table.bookingPassengersChildren tbody tr.room-'+roomNumber).size() > 0){
					$(booking.callingDiv).find('.withChildren table.bookingPassengersChildren tbody tr.room-'+roomNumber+':last').after(newChildMarkup);
				}else{
					// Find the previous room number then add the row at the right position
					roomBefore = 0;

					for(i=roomNumber;i>0;i--){
						if($(booking.callingDiv).find('.withChildren table.bookingPassengersChildren tbody tr.room-'+i).size() > 0){
							roomBefore = i;
							break;
						}
					}
					if(roomBefore != 0){
						// There's a row, add it after
						$(booking.callingDiv).find('.withChildren table.bookingPassengersChildren tbody tr.room-'+roomBefore+':last').after(newChildMarkup);
					}else{
						// There are no row, append it to the table
						$(booking.callingDiv).find('.withChildren table.bookingPassengersChildren tbody').prepend(newChildMarkup);
					}
				}

				$(booking.callingDiv).find('.withChildren table.bookingPassengersChildren tbody tr.room-'+roomNumber+':last td:eq(0) span:eq(0)').text(childrenNumber);
				if(buttonValue != 0 && buttonValue != 4) {
					$(booking.callingDiv).find('.withChildren table.bookingPassengersChildren tbody tr.room-'+roomNumber+':last td:eq(0) span:eq(2)').text(roomNumber);
				} else {
					$(booking.callingDiv).find('.withChildren table.bookingPassengersChildren tbody tr.room-'+roomNumber+':last td:eq(0) span:eq(1)').addClass('hide');
					$(booking.callingDiv).find('.withChildren table.bookingPassengersChildren tbody tr.room-'+roomNumber+':last td:eq(0) span:eq(2)').addClass('hide');
					$(booking.callingDiv).find('.withChildren table.bookingPassengersChildren tbody tr.room-'+roomNumber+':last td:eq(0) span:eq(3)').addClass('hide');
				}
				$(booking.callingDiv).find('.withChildren table.bookingPassengersChildren tbody tr.room-'+roomNumber+':last td:eq(1) select').attr('name','seRequestObj.roomSettingList['+(roomNumber-1)+'].ageOfChildList['+(childrenNumber-1)+']');

				$.call(booking.addChildren(booking.actualNumberOfChildren,roomNumber));
			});
		}else{
			$(booking.callingDiv).find('.withChildren').slideDown();
		}
	},
	toggleSenior : function(caller,roomNumber){
		booking.callingDiv = $(caller).parents('div.overlayContainer');

		booking.desiredNumberOfSenior = $(caller).attr('value');
		booking.actualNumberOfSenior = $(booking.callingDiv).find('.withSeniors table.bookingPassengersSeniors tr.room-'+roomNumber+'.senior').size();

		if(booking.desiredNumberOfSenior > booking.actualNumberOfSenior){
			// Want to ADD a room
			booking.addSenior(booking.actualNumberOfSenior + 1,roomNumber);
		}else{
			// Want to REMOVE a room
			$(booking.callingDiv).find('.withSeniors table.bookingPassengersSeniors tr.room-'+roomNumber+':gt('+(booking.desiredNumberOfSenior - 1)+')').remove();
			if($(booking.callingDiv).find('.withSeniors table.bookingPassengersSeniors tr.senior').size() == 0){
				$(booking.callingDiv).find('.withSeniors').hide();
			}
		}
	},
	addSenior : function(seniorNumber,roomNumber){
		var buttonValue = $("input[name=seRequestObj.searchType]:checked").val();
		if(booking.desiredNumberOfSenior >= booking.actualNumberOfSenior){
			booking.actualNumberOfSenior = seniorNumber + 1;

			$.get('/tips/addSenior.jsp?roomNumber='+roomNumber+'&seniorNumber='+seniorNumber,function(newSeniorMarkup){
				if($(booking.callingDiv).find('.withSeniors table.bookingPassengersSeniors tbody tr.room-'+roomNumber).size() > 0){
					$(booking.callingDiv).find('.withSeniors table.bookingPassengersSeniors tbody tr.room-'+roomNumber+':last').after(newSeniorMarkup)
				}else{
					// Find the previous room number then add the row at the right position
					roomBefore = 0;

					for(i=roomNumber;i>0;i--){
						if($(booking.callingDiv).find('.withSeniors table.bookingPassengersSeniors tbody tr.room-'+i).size() > 0){
							roomBefore = i;
							break;
						}
					}
					if(roomBefore != 0){
						// There's a row, add it after
						$(booking.callingDiv).find('.withSeniors table.bookingPassengersSeniors tbody tr.room-'+roomBefore+':last').after(newSeniorMarkup);
					}else{
						// There are no row, append it to the table
						$(booking.callingDiv).find('.withSeniors table.bookingPassengersSeniors tbody').prepend(newSeniorMarkup);
					}
				}

				$(booking.callingDiv).find('.withSeniors table.bookingPassengersSeniors tbody tr.room-'+roomNumber+':last td:eq(0) span:eq(0)').text(seniorNumber);
				if(buttonValue != 0 && buttonValue != 4) {
					$(booking.callingDiv).find('.withSeniors table.bookingPassengersSeniors tbody tr.room-'+roomNumber+':last td:eq(0) span:eq(2)').text(roomNumber);
				} else {
					$(booking.callingDiv).find('.withSeniors table.bookingPassengersSeniors tbody tr.room-'+roomNumber+':last td:eq(0) span:eq(1)').addClass('hide');
					$(booking.callingDiv).find('.withSeniors table.bookingPassengersSeniors tbody tr.room-'+roomNumber+':last td:eq(0) span:eq(2)').addClass('hide');
					$(booking.callingDiv).find('.withSeniors table.bookingPassengersSeniors tbody tr.room-'+roomNumber+':last td:eq(0) span:eq(3)').addClass('hide');
				}
				$(booking.callingDiv).find('.withSeniors table.bookingPassengersSeniors tbody tr.room-'+roomNumber+':last td:eq(1) select').attr('name','seRequestObj.roomSettingList['+(roomNumber-1)+'].ageOfSeniorList['+(seniorNumber-1)+']');

				$.call(booking.addSenior(booking.actualNumberOfSenior,roomNumber));
			});
		}else{
			$(booking.callingDiv).find('.withSeniors').slideDown();
		}
	},
	toggleRooms : function(caller, type) {
		booking.callingDiv = $(caller).parents('div.overlayContainer');

		booking.desiredNumberOfRooms = $(caller).attr('value');
		booking.actualNumberOfRooms = $(booking.callingDiv).find('table.bookingPassengers tr.room').size();

		if(booking.desiredNumberOfRooms > booking.actualNumberOfRooms){
			// Want to ADD a room
			booking.addRoomRow(booking.actualNumberOfRooms + 1, type);
		}else{

			// Remove the children linked to this room
			numberOfTrs = 0;
			for(i=1;i<=booking.desiredNumberOfRooms;i++){
				numberOfTrs += $(booking.callingDiv).find('.withChildren table.bookingPassengers tr.room-'+i).size();
			}
			if(numberOfTrs != 0){
				$(booking.callingDiv).find('.withChildren table.bookingPassengers tr:gt('+parseFloat(numberOfTrs-1)+')').remove();
			}else{
				$(booking.callingDiv).find('.withChildren').hide();
			}

			// Remove the seniors linked to this room
			numberOfTrs = 0;
			for(i=1;i<=booking.desiredNumberOfRooms;i++){
				numberOfTrs += $(booking.callingDiv).find('.withSeniors table.bookingPassengers tr.room-'+i).size();
			}
			if(numberOfTrs != 0){
				$(booking.callingDiv).find('.withSeniors table.bookingPassengers tr:gt('+parseFloat(numberOfTrs-1)+')').remove();
			}else{
				$(booking.callingDiv).find('.withSeniors').hide();
			}

			// Want to REMOVE a room
			$(booking.callingDiv).find('table.bookingPassengers:first tr:gt('+booking.desiredNumberOfRooms+')').remove();


		}
	},
	addRoomRow : function(roomNumber, type){
		if(booking.desiredNumberOfRooms >= booking.actualNumberOfRooms){
			booking.actualNumberOfRooms = roomNumber + 1;

			$.get('/tips/addRoomRow.jsp?roomNumber='+roomNumber+'&type='+type,function(newRoomMarkup){

				// Set the room values
				$(booking.callingDiv).find('table.bookingPassengers tr.room:last').after(newRoomMarkup);
				$(booking.callingDiv).find('table.bookingPassengers tr.room:last td:eq(0) span').text(roomNumber);

				// Needed to define which room we are in
				$(booking.callingDiv).find('table.bookingPassengers tr.room:last').removeClass('room-1');
				$(booking.callingDiv).find('table.bookingPassengers tr.room:last').addClass('room-' + roomNumber);

				$(booking.callingDiv).find('table.bookingPassengers tr.room:last td:eq(1) select option:eq(2)').attr('selected','selected');
				$(booking.callingDiv).find('table.bookingPassengers tr.room:last td:eq(2) select').attr('name','seRequestObj.roomSettingList['+(roomNumber-1)+'].seniorsNum');
				$(booking.callingDiv).find('table.bookingPassengers tr.room:last td:eq(2) select').bind('change',function(){
					booking.toggleSenior(this,roomNumber);
				});
				$(booking.callingDiv).find('table.bookingPassengers tr.room:last td:eq(3) select').attr('name','seRequestObj.roomSettingList['+(roomNumber-1)+'].childrenNum');
				$(booking.callingDiv).find('table.bookingPassengers tr.room:last td:eq(3) select').bind('change',function(){
					booking.toggleChildren(this,roomNumber);
				});
				$(booking.callingDiv).find('table.bookingPassengers tr.room:last td:eq(4) select').attr('name','seRequestObj.roomSettingList['+(roomNumber-1)+'].infantsNum');

				$.call(booking.addRoomRow(booking.actualNumberOfRooms, type));
			});
		}
	},
	showSearchLoader : function() {
		overlay.cancelURL = location.href;

		// Build the background overlay div
		backgroundDiv = document.createElement('div');
		$(backgroundDiv).addClass('overlay');
		$(backgroundDiv).css({'height':$(document).height()});

		$('body').append(backgroundDiv);
		$('div.overlay').css('opacity',0);
		$('div.overlay').show();
		$('div.overlay').animate({opacity: 0.35}, 300, "");

		booking.updateSearchContent();
		$('#searchLoaderContainer').show();

		var scrollTop = window.pageYOffset || document.documentElement.scrollTop || 0;

		$('#searchLoaderContainer').css({
			'margin' : (-$('#searchLoaderContainer').height()/2) + scrollTop + "px 0 0 " + (-$('#searchLoaderContainer').width()/2) + "px"
		});

		booking.seconds = 0;
		timerID = setTimeout("booking.updateTimer()", 1000);
	},
	cancelLoader : function(){
		overlay.close('searchLoaderContainer');
	},
	updateSearchContent : function(){
		// Get the div from which the search is done
		searchingDiv = $('div.packageWrap:visible');
		departingCity = $(searchingDiv).find('select.leaving-list option:selected').text();
		arrivingCity = $(searchingDiv).find('select.going-list option:selected').text();
		startingDate = $(searchingDiv).find('input.departing-date').attr('value');
		arrivingDate = $(searchingDiv).find('input.returning-date').attr('value');
		numberRoom = $(searchingDiv).find('div.overlayContainer div.colLeft select option:selected').text();

		numberAdults = 0;
		$(searchingDiv).find('table.bookingPassengersNumbers tr:gt(0)').each(function(){
			numberAdults += parseFloat($(this).find('td:eq(1) select').attr('value'));
		});

		numberSeniors = 0;
		$(searchingDiv).find('table.bookingPassengersNumbers tr:gt(0)').each(function(){
			numberSeniors += parseFloat($(this).find('td:eq(2) select').attr('value'));
		});

		numberChilds = 0;
		$(searchingDiv).find('table.bookingPassengersNumbers tr:gt(0)').each(function(){
			numberChilds += parseFloat($(this).find('td:eq(3) select').attr('value'));
		});

		numberInfants = 0;
		$(searchingDiv).find('table.bookingPassengersNumbers tr:gt(0)').each(function(){
			numberInfants += parseFloat($(this).find('td:eq(4) select').attr('value'));
		});

		// Build the string with the right numbers
		$('#searchLoaderContainer ul.hide li:eq(0) span').text(numberAdults);
		$('#searchLoaderContainer ul.hide li:eq(1) span').text(numberSeniors);
		$('#searchLoaderContainer ul.hide li:eq(2) span').text(numberChilds);
		$('#searchLoaderContainer ul.hide li:eq(3) span').text(numberInfants);

		$('#searchLoaderContainer #departing-city').text(departingCity);
		$('#searchLoaderContainer #arriving-city').text(arrivingCity);
		$('#searchLoaderContainer #starting-date').text(startingDate);
		$('#searchLoaderContainer #arriving-date').text(arrivingDate);
		$('#searchLoaderContainer #number-room').text(numberRoom);

		$('#searchLoaderContainer #passengers').html('');

		if(numberAdults > 0){
			$('#searchLoaderContainer #passengers').append($('#searchLoaderContainer ul.hide li:eq(0)').html());
		}

		if(numberSeniors > 0){
			$('#searchLoaderContainer #passengers').append(', ');
			$('#searchLoaderContainer #passengers').append($('#searchLoaderContainer ul.hide li:eq(1)').html());
		}

		if(numberChilds > 0){
			$('#searchLoaderContainer #passengers').append(', ');
			$('#searchLoaderContainer #passengers').append($('#searchLoaderContainer ul.hide li:eq(2)').html());
		}

		if(numberInfants > 0){
			$('#searchLoaderContainer #passengers').append(', ');
			$('#searchLoaderContainer #passengers').append($('#searchLoaderContainer ul.hide li:eq(3)').html());
		}

		if ($(searchingDiv).attr('id') == 'customDiv') {
			// do sth
			var buttonValue = $("input[name=seRequestObj.searchType]:checked").val();
			// flight only and flight + car -> no room information is to be displayed
			if (buttonValue == '0' || buttonValue == '4') {
				$('#searchLoader').find('span.in').addClass('hide');
				$('#searchLoader').find('span.room').addClass('hide');
				$('#searchLoader').find('span.numberroom').addClass('hide');
			}
			// hotel only and hotel + car -> no flight information is to be displayed
			if (buttonValue == '1' || buttonValue == '5') {
				$('#searchLoader').find('span.depart-city').addClass('hide');
				$('#searchLoader').find('span.to').addClass('hide');
			}
		}
	},
	updateSearchPassengerInfo : function(){
		// Get the div from which the search is done
		searchingDiv = $('div.packageWrap:visible');
		numberRoom = $(searchingDiv).find('div.overlayContainer div.colLeft select option:selected').text();

		numberAdults = 0;
		$(searchingDiv).find('table.bookingPassengersNumbers tr:gt(0)').each(function(){
			numberAdults += parseFloat($(this).find('td:eq(1) select').attr('value'));
		});

		numberSeniors = 0;
		$(searchingDiv).find('table.bookingPassengersNumbers tr:gt(0)').each(function(){
			numberSeniors += parseFloat($(this).find('td:eq(2) select').attr('value'));
		});

		numberChilds = 0;
		$(searchingDiv).find('table.bookingPassengersNumbers tr:gt(0)').each(function(){
			numberChilds += parseFloat($(this).find('td:eq(3) select').attr('value'));
		});

		numberInfants = 0;
		$(searchingDiv).find('table.bookingPassengersNumbers tr:gt(0)').each(function(){
			numberInfants += parseFloat($(this).find('td:eq(4) select').attr('value'));
		});

		// Set the values
		booking.updateSearchPassengerInfoText(numberAdults, numberSeniors, numberChilds, numberInfants, numberRoom);
	},
	updateSearchPassengerInfoText : function(numberAdults, numberSeniors, numberChilds, numberInfants, numberRoom){
		searchingDiv = $('div.packageWrap:visible');
		if(numberAdults >= 1) {
			$(searchingDiv).find('a.passengerInfos span.adults-number').removeClass('hide');
			$(searchingDiv).find('a.passengerInfos span.adults-number span.number').removeClass('hide');
			$(searchingDiv).find('a.passengerInfos span.adults-number span.number').text(numberAdults);
			if(numberAdults == 1) {
				$(searchingDiv).find('a.passengerInfos span.adults-number span.text').removeClass('hide');
				$(searchingDiv).find('a.passengerInfos span.adults-number span.texts').addClass('hide');
			} else if(numberAdults > 1) {
				$(searchingDiv).find('a.passengerInfos span.adults-number span.texts').removeClass('hide');
				$(searchingDiv).find('a.passengerInfos span.adults-number span.text').addClass('hide');
			}
		} else {
			$(searchingDiv).find('a.passengerInfos span.adults-number').addClass('hide');
		}

		if(numberSeniors >= 1){
			$(searchingDiv).find('a.passengerInfos span.senior-number').removeClass('hide');
			$(searchingDiv).find('a.passengerInfos span.senior-number span.number').removeClass('hide');
			$(searchingDiv).find('a.passengerInfos span.senior-number span.number').text(numberSeniors);
			if(numberSeniors == 1) {
				$(searchingDiv).find('a.passengerInfos span.senior-number span.text').removeClass('hide');
				$(searchingDiv).find('a.passengerInfos span.senior-number span.texts').addClass('hide');
			} else if(numberSeniors > 1) {
				$(searchingDiv).find('a.passengerInfos span.senior-number span.texts').removeClass('hide');
				$(searchingDiv).find('a.passengerInfos span.senior-number span.text').addClass('hide');
			}
		} else {
			$(searchingDiv).find('a.passengerInfos span.senior-number').addClass('hide');
		}
		if(numberChilds >= 1){
			$(searchingDiv).find('a.passengerInfos span.children-number').removeClass('hide');
			$(searchingDiv).find('a.passengerInfos span.children-number span.number').removeClass('hide');
			$(searchingDiv).find('a.passengerInfos span.children-number span.number').text(numberChilds);
			if(numberChilds == 1) {
				$(searchingDiv).find('a.passengerInfos span.children-number span.text').removeClass('hide');
				$(searchingDiv).find('a.passengerInfos span.children-number span.texts').addClass('hide');
			} else if(numberChilds > 1) {
				$(searchingDiv).find('a.passengerInfos span.children-number span.texts').removeClass('hide');
				$(searchingDiv).find('a.passengerInfos span.children-number span.text').addClass('hide');
			}
		} else {
			$(searchingDiv).find('a.passengerInfos span.children-number').addClass('hide')
		}
		if(numberInfants >= 1){
			$(searchingDiv).find('a.passengerInfos span.infants-number').removeClass('hide');
			$(searchingDiv).find('a.passengerInfos span.infants-number span.number').removeClass('hide');
			$(searchingDiv).find('a.passengerInfos span.infants-number span.number').text(numberInfants);
			if(numberInfants == 1) {
				$(searchingDiv).find('a.passengerInfos span.infants-number span.text').removeClass('hide');
				$(searchingDiv).find('a.passengerInfos span.infants-number span.texts').addClass('hide');
			} else if(numberInfants > 1) {
				$(searchingDiv).find('a.passengerInfos span.infants-number span.texts').removeClass('hide');
				$(searchingDiv).find('a.passengerInfos span.infants-number span.text').addClass('hide');
			}
		} else {
			$(searchingDiv).find('a.passengerInfos span.infants-number').addClass('hide');
		}
		if(numberRoom >= 1) {
			$(searchingDiv).find('a.roomInfos span.room-number').removeClass('hide');
			$(searchingDiv).find('a.roomInfos span.room-number span.number').removeClass('hide');
			$(searchingDiv).find('a.roomInfos span.room-number span.number').text(numberRoom);
			if(numberRoom == 1) {
				$(searchingDiv).find('a.roomInfos span.room-number span.text').removeClass('hide');
				$(searchingDiv).find('a.roomInfos span.room-number span.texts').addClass('hide');
			} else if (numberRoom > 1) {
				$(searchingDiv).find('a.roomInfos span.room-number span.texts').removeClass('hide');
				$(searchingDiv).find('a.roomInfos span.room-number span.text').addClass('hide');
			}
		} else {
			$(searchingDiv).find('a.roomInfos span.room-number').addClass('hide');
		}
	},
	updateTimer : function(){
		booking.seconds += 1;
		searchingDiv = $('#searchLoaderContainer #elapsed-time').text(booking.seconds);

		timerID = setTimeout("booking.updateTimer()", 1000);
	},
	buildNewPassengerPickerTable : function() {
		// remove all the age lists
		$(booking.callingDiv).find('.withSeniors table.bookingPassengers tr').remove();
		$(booking.callingDiv).find('.withChildren table.bookingPassengers tr').remove();
		// set number of room to 1
		$('#roomNumSelection select option:eq(0)').attr('selected','selected');
		// reset all the selections to 2-0-0-0
		$(booking.callingDiv).find('table.bookingPassengers tr.room.room-1 td:eq(1) select option:eq(2)').attr('selected','selected');
		$(booking.callingDiv).find('table.bookingPassengers tr.room.room-1 td:eq(2) select option:eq(0)').attr('selected','selected');
		$(booking.callingDiv).find('table.bookingPassengers tr.room.room-1 td:eq(3) select option:eq(0)').attr('selected','selected');
		$(booking.callingDiv).find('table.bookingPassengers tr.room.room-1 td:eq(4) select option:eq(0)').attr('selected','selected');
		// with number of room 1, toggle unnecessary room rows
		booking.toggleRooms($('#roomNumSelection select'), 'custom');

	},
	hideDepartingCityList : function() {
		searchingDiv = $('#customDiv');
		$("label[for='packageFormCustom_seRequestObj_departureAirportCode']").addClass('hide');
		$('#packageFormCustom_seRequestObj_departureAirportCode ').addClass('hide');
		$(searchingDiv).find('span.departureDate').addClass('hide');
		$(searchingDiv).find('span.departureDateHotelOnly').removeClass('hide');
		$(searchingDiv).find('span.returnDate').addClass('hide');
		$(searchingDiv).find('span.returnDateHotelOnly').removeClass('hide');
	},
	displayDepartingCityList : function() {
		searchingDiv = $('#customDiv');
		$("label[for='packageFormCustom_seRequestObj_departureAirportCode']").removeClass('hide');
		$('#packageFormCustom_seRequestObj_departureAirportCode').removeClass('hide');
		$(searchingDiv).find('span.departureDate').removeClass('hide');
		$(searchingDiv).find('span.departureDateHotelOnly').addClass('hide');
		$(searchingDiv).find('span.returnDate').removeClass('hide');
		$(searchingDiv).find('span.returnDateHotelOnly').addClass('hide');
	},
	updatePassengerPopupForFlightOnly : function() {
		var buttonValue = $("input[name=seRequestObj.searchType]:checked").val();
		searchingDiv = $('#customDiv');
		if (buttonValue == '0' || buttonValue == '4') {
			booking.displayDepartingCityList();
			// Step-1 Clean the whole passenger table.
			//        Initialize a new passenger picker table.
			//        Adults - 2, Seniors - 0, Children - 0 and Infants - 0.
			booking.buildNewPassengerPickerTable();

			// Step-2 The passenger information area is set to default information as
			// "2 Adults".
			booking.updateSearchPassengerInfoText('2', '0', '0', '0', '0');

			// Step-3 Hide all room related information:
			// "Room occupancy" picture
			// "Number of rooms" drop down list
			// "SPACE - empty <th></th>" left to the Adult age label
			// "room 1" left to the first room option select row
			// "(1 room)" after the passenger information
			$('#t_passengers_c').addClass('hide');
			$('#roomNumSelection').removeClass('colLeft clearfix');
			$('#roomNumSelection').addClass('hide');
			$(searchingDiv).find('table.bookingPassengersNumbers th.empty').addClass('hide');
			$(searchingDiv).find('table.bookingPassengersNumbers tr.room td.roomLabel').addClass('hide');
			booking.updateSearchPassengerInfo();
			$(searchingDiv).find('a.roomInfos span.room-number').addClass('hide');
			// Update Search Loader Info
		} else {
			if (buttonValue == '1' || buttonValue == '5') {
				booking.hideDepartingCityList();
			} else {
				booking.displayDepartingCityList();
			}
			booking.buildNewPassengerPickerTable();
			// show all room related information
			$('#t_passengers_c').removeClass('hide');
			$('#roomNumSelection').addClass('colLeft clearfix');
			$('#roomNumSelection').removeClass('hide');
			$(searchingDiv).find('table.bookingPassengersNumbers th.empty').removeClass('hide');
			$(searchingDiv).find('table.bookingPassengersNumbers tr.room td.roomLabel').removeClass('hide');
			$(searchingDiv).find('a.roomInfos span.room-number').removeClass('hide');
			booking.updateSearchPassengerInfo();
		}
	},
	addCalendarValueToUrl : function(url) {
		searchingDiv = $('div.packageWrap:visible');
		var departingdate = 'bookDeparture='+ $(searchingDiv).find('input.departing-date').attr('value');
		var returningdate = 'bookArrival='+ $(searchingDiv).find('input.returning-date').attr('value');
		var departingcity = 'bookDepartureAirportCode='+ $(searchingDiv).find('select.leaving-list option:selected').attr('value');
		var booktype = 'bookType=';
		var flexible = 'bookFlexible='
		var flexibleButtonValue = $(searchingDiv).find("input[name=seRequestObj.flexibility]:checked").val();
		if (flexibleButtonValue == 'true') {
			flexible+='true';
		} else {
			flexible+='false';
	}
		if ($(searchingDiv).attr('id') == 'packageDiv') {
			booktype += 0;
		}
		if ($(searchingDiv).attr('id') == 'customDiv') {
			var buttonValue = $("input[name=seRequestObj.searchType]:checked").val();
			if (buttonValue == '3') {
				booktype += 3;
			} else if (buttonValue == '5') {
				booktype += 5;
			} else if (buttonValue == '6' || buttonValue == '4') {
				booktype += 6;
			} else {
				booktype += 3;
			}
		}
		url = url + '&' + departingdate + '&' + returningdate + '&' + flexible + '&' + departingcity + '&' + booktype + '&end=';
		return url;
	}
}

PriceView = {
	togglePriceView : function(caller) {
		PriceView.callingDiv = $(caller).parents('div.priceView');
		var buttonPriceViewValue = $("input[name=priceView]:checked").val();
		if (buttonPriceViewValue == 'service') {
			$(PriceView.callingDiv).find('table.priceViewByService').removeClass('hide');
			$(PriceView.callingDiv).find('table.priceViewByPassenger').addClass('hide');
		} else {
			$(PriceView.callingDiv).find('table.priceViewByService').addClass('hide');
			$(PriceView.callingDiv).find('table.priceViewByPassenger').removeClass('hide');
		}
	},
	addPriceView : function(url) {
		var buttonValue = $("input[name=priceView]:checked").val();
		url = url + "&priceViewType=" + buttonValue;
		return url;

	}
}

sidebarInfo = {
	init : function(){ },
	toggle : function(caller){
		if ($(caller).parent().parent().next().css("display") == "none"){
			// show the content
			$(caller).parent().parent().next().slideDown("fast");
			$(caller).addClass("open");
		}else{
			// hide the content
			$(caller).parent().parent().next().slideUp("fast");
			$(caller).removeClass("open");
		}
	}
}

notice = {
	close : function(which){
		$(which).parent().animate({opacity: 'hide'}, 500);
	}
}

dropDown = {
	toggle : function(caller){
		$(caller).next().animate({ 'height' : 'show' }, 300, function(){
			// When the user clicks on the body, we need to close the dropdown
			$(document).bind('click', function(){
				dropDown.close();
			});
		});

		// Bind the click event on every a in the list so it acts like a select
		$(caller).next().find('a').bind('click', function(){
			dropDown.select(this);
			return false;
		})
	},
	close : function(){
		$('div.dropDown').find('ul').slideUp();

		// Remove the click event on the document
		$(document).unbind('click');
	},
	select : function(caller){
		// Set the dropdown text to the selected on as well as the go link
		$(caller).parent().parent().parent().children('a').text($(caller).text());
		$(caller).parent().parent().parent().children('a').attr('href',$(caller).attr('href'));

		dropDown.close();
	},
	goToPage : function(caller){
		// Set the button href to the selected href
		$(caller).attr('href', $(caller).parent().prev().children('a').attr('href'));

		// Go to the page if something has been selected
		if($(caller).attr('href') != "#"){
			$(document).attr('location', $(caller).attr('href'));
		}
	}
}


imageBrowser = {
	init : function(){
		imageBrowser.inAnimation = false;
		imageBrowser.currentItem2 = parseFloat(0);
		imageBrowser.currentItem = parseFloat(0);
		imageBrowser.itemsCount = $('div.imageBrowser ul li').size();

		// Set the counter
		$('div.imageBrowser span.counter').text('1/' + $('div.imageBrowser ul li').length);
		$('div.fullscreenText span.counter').text('1/' + $('div.imageBrowser ul li').length);
		imageBrowser.galleryWidth = parseFloat($('div.imageBrowser ul li img').width());

		// If there's only one picture, remove the previous/newxt links
		if($('div.imageBrowser ul li').length == 1){
			$('div.imageBrowser span.photoBrowser a.photoArrowLeft').remove();
			$('div.imageBrowser span.photoBrowser a.photoArrowRight').remove();
			$('div.imageBrowser span.photoBrowser span.fRight').css({'margin-left':5})
		}

		$('div.imageBrowser ul li:eq(0)').css({position: 'absolute', left: '0px'});

		$('div.imageBrowser ul li:gt(0)').each(function(){
			$(this).css({
				position : 'absolute',
				right : imageBrowser.galleryWidth
			});
		});
	},

	previous : function(){
		if(!imageBrowser.inAnimation){
			imageBrowser.inAnimation = true;

			$('div.imageBrowser ul li:eq('+imageBrowser.currentItem +')').animate({ 'left': imageBrowser.galleryWidth }, 500 );

			imageBrowser.currentItem = (imageBrowser.currentItem - 1) % imageBrowser.itemsCount;
			if(imageBrowser.currentItem < 0){ imageBrowser.currentItem = imageBrowser.itemsCount - 1; }

			$('div.imageBrowser ul li:eq('+imageBrowser.currentItem+')').css('left',-imageBrowser.galleryWidth);
			$('div.imageBrowser ul li:eq('+imageBrowser.currentItem+')').animate({ 'left': 0 }, 500, function(){ imageBrowser.inAnimation = false; } );

			$('div.imageBrowser span.counter').text(imageBrowser.currentItem + 1 + '/' + $('div.imageBrowser ul li').length);
			imageBrowser.currentItem2 = imageBrowser.currentItem;
			$('div.fullscreenText span.counter').text(imageBrowser.currentItem + 1 + '/' + $('div.imageBrowser ul li').length);

			$("#fullscreenPhoto").width(parseFloat($('#fullPhoto img').width()));

		}
	},
	next : function(){
		if(!imageBrowser.inAnimation){
			imageBrowser.inAnimation = true;

			$('div.imageBrowser ul li:eq('+imageBrowser.currentItem +')').animate({ 'left': -imageBrowser.galleryWidth }, 500 );

			imageBrowser.currentItem = ++ imageBrowser.currentItem % imageBrowser.itemsCount;

			$('div.imageBrowser ul li:eq('+imageBrowser.currentItem+')').css('left',imageBrowser.galleryWidth);
			$('div.imageBrowser ul li:eq('+imageBrowser.currentItem+')').animate({ 'left': 0 }, 500, function(){ imageBrowser.inAnimation = false; } );

			$('div.imageBrowser span.counter').text(imageBrowser.currentItem + 1 + '/' + $('div.imageBrowser ul li').length);
			imageBrowser.currentItem2 = imageBrowser.currentItem;
			$('div.fullscreenText span.counter').text(imageBrowser.currentItem + 1 + '/' + $('div.imageBrowser ul li').length);

			$("#fullscreenPhoto").width(parseFloat($('#fullPhoto img').width()));
		}
	},


	nextFull : function(){
			imageBrowser.fullscreenCurrentItem = ++ imageBrowser.fullscreenCurrentItem % imageBrowser.itemsCount;

			browserDetailsLocation = $('div.imageBrowser li:eq('+imageBrowser.fullscreenCurrentItem+') div.liFullPhoto');

			$("#fullPhoto").fadeOut('fast',function(){
				$("#fullPhoto").html($(browserDetailsLocation).find('img').clone());

				// Put the title and content
				$('#fullscreenPhoto .fullscreenText p:eq(0)').html('<strong>' + $(browserDetailsLocation).find('span.title').text() + '</strong> ( photo '+ (parseFloat(imageBrowser.fullscreenCurrentItem) + 1) +' of '+ imageBrowser.itemsCount +' )');
				var txtP = $('#fullscreenPhoto .fullscreenText p:eq(1)');
				txtP.text($(browserDetailsLocation).find('span.content').text());
				if (txtP.height() < 30) txtP.height(30);

				$("#fullPhoto").fadeIn('fast');
			});

	},

	previousFull : function(){
			imageBrowser.fullscreenCurrentItem = (imageBrowser.fullscreenCurrentItem - 1) % imageBrowser.itemsCount;
			if(imageBrowser.fullscreenCurrentItem < 0){ imageBrowser.fullscreenCurrentItem = imageBrowser.itemsCount - 1; }

			browserDetailsLocation = $('div.imageBrowser li:eq('+imageBrowser.fullscreenCurrentItem+') div.liFullPhoto');

			$("#fullPhoto").fadeOut('fast',function(){
				$("#fullPhoto").html($(browserDetailsLocation).find('img').clone());

				// Put the title and content
				$('#fullscreenPhoto .fullscreenText p:eq(0)').html('<strong>' + $(browserDetailsLocation).find('span.title').text() + '</strong> ( photo '+ (parseFloat(imageBrowser.fullscreenCurrentItem) + 1) +' of '+ imageBrowser.itemsCount +' )');
				var txtP = $('#fullscreenPhoto .fullscreenText p:eq(1)');
				txtP.text($(browserDetailsLocation).find('span.content').text());
				if (txtP.height() < 30) txtP.height(30);

				$("#fullPhoto").fadeIn('fast');
			});
	},
	openPicture : function(caller){
		imageBrowser.createFullscreen();

		imageBrowser.loadPicture(caller);
	},
	loadPicture : function(caller){
		// Put the photo in the container
		$("#fullPhoto").html($(caller).next().find('img').clone());

		// Put the title and content
		$('#fullscreenPhoto .fullscreenText p:eq(0)').html('<strong>' + $(caller).next().find('span.title').text() + '</strong> ( photo '+ (parseFloat(imageBrowser.fullscreenCurrentItem) + 1) +' of '+ imageBrowser.itemsCount +' )');
		var txtP = $('#fullscreenPhoto .fullscreenText p:eq(1)');
		txtP.text($(caller).next().find('span.content').text());
		if (txtP.height() < 30) txtP.height(30);

		// Find the largest image, then set it as the default width
		imageBrowser.fullScreenWidth = 300;
		imageBrowser.fullScreenHeight = 300;

		$('div.imageBrowser li div.liFullPhoto img').each(function(){
			imageWidth = parseFloat($(this).css('width'));
			imageHeight = parseFloat($(this).css('height'));
			if(imageWidth >= imageBrowser.fullScreenWidth){ imageBrowser.fullScreenWidth = imageWidth; }
			if(imageHeight >= imageBrowser.fullScreenHeight){ imageBrowser.fullScreenHeight = imageHeight; }
		})

		var scrollTop = window.pageYOffset || document.documentElement.scrollTop || 0;

		// Set the image browser width to the image width
		$('#fullscreenPhoto').css({
			'width': parseFloat(imageBrowser.fullScreenWidth) + 12,
			'margin-top': -(imageBrowser.fullScreenHeight/2) + scrollTop - 30,
			'margin-left': -imageBrowser.fullScreenWidth/2
		});

		// Then fade it in
		if(jQuery.browser.msie && jQuery.browser.version < 7.0){ $('select').hide(); }
		$('div.overlay').css('opacity',0);
		$('div.overlay').show();
		$('div.overlay').animate({opacity: 0.35}, 300, function(){
			$('div#fullscreenPhoto').fadeIn();
		});
	},
	createFullscreen : function(){
		imageBrowser.fullscreenCurrentItem = imageBrowser.currentItem;

		// Build the background overlay div
		backgroundDiv = document.createElement('div');
		$(backgroundDiv).addClass('overlay');
		$(backgroundDiv).css({ 'height':$('body').height() });
		$(backgroundDiv).bind('click',function(){
			imageBrowser.closeFullScreen();
		});

		// Containers
		fullScreenPhotoContainer = document.createElement("div");
		$(fullScreenPhotoContainer).attr({'id':'fullscreenPhoto','class':'clearfix'});

		fullScreenPhotoInside = document.createElement("div");
		$(fullScreenPhotoInside).attr('class','fullscreenPhotoInside');

		// Close link
		fullScreenPhotoClose = document.createElement("a");
		$(fullScreenPhotoClose).attr({
			'href':'#',
			'class':'closeWindow'
		});
			$(fullScreenPhotoClose).bind('click',function(){
				imageBrowser.closeFullScreen();
				return false;
			});
			fullScreenCloseImage = document.createElement('img');
			$(fullScreenCloseImage).attr({
				'src':'/media/images/common/web/buttons/btn_X.gif',
				'width':'13',
				'height':'13',
				'alt':'Close'
			});
		$(fullScreenPhotoClose).append(fullScreenCloseImage);

		// Image Container
		imageContainer = document.createElement('div');
		$(imageContainer).attr('id','fullPhoto');

		// Previous link
		previousLink = document.createElement('a');
		$(previousLink).attr({
			'href':'#',
			'class':'arrow fLeft'
		});
			$(previousLink).bind('click',function(){
				imageBrowser.previousFull();
				return false;
			});
			previousLinkImage = document.createElement('img');
			$(previousLinkImage).attr({
				'src':'/media/images/common/web/buttons/fleche_left_Fullscreen.jpg',
				'width':'29',
				'height':'29'
			});
		$(previousLink).append(previousLinkImage);

		// Next link
		nextLink = document.createElement('a');
		$(nextLink).attr({
			'href':'#',
			'class':'arrow fRight'
		});
			$(nextLink).bind('click',function(){
				imageBrowser.nextFull();
				return false;
			});
			nextLinkImage = document.createElement('img');
			$(nextLinkImage).attr({
				'src':'/media/images/common/web/buttons/fleche_right_fullscreen.gif',
				'width':'29',
				'height':'29'
			});
		$(nextLink).append(nextLinkImage);

		// Text Container
		textContainer = document.createElement('div');
		$(textContainer).attr('class','fullscreenText');
			titleContainer = document.createElement('p');
			photoCounter = document.createElement('span');
			$(photoCounter).append(titleContainer);

			contentContainer = document.createElement('p');

		$(textContainer).append(titleContainer);
		$(textContainer).append(contentContainer);
		$(fullScreenPhotoInside).append(imageContainer).append(fullScreenPhotoClose);

		// Append the links only if there's more then 1 picture
		if(imageBrowser.itemsCount > 1){
			$(fullScreenPhotoInside).append(nextLink).append(previousLink);
		}

		$(fullScreenPhotoInside).append(textContainer);
		$(fullScreenPhotoContainer).append(fullScreenPhotoInside);

		// Append the content
		$('body').append(backgroundDiv);
		$('body').append(fullScreenPhotoContainer);
	},
	closeFullScreen : function(){
		$('div#fullscreenPhoto').animate({opacity: 0}, 300, function(){
			$('div.overlay').animate({opacity: 0}, 300, function(){
				$('div#fullscreenPhoto').remove();
				$('div.overlay').remove();
				if(jQuery.browser.msie && jQuery.browser.version < 7.0){ $('select').show(); }
			});
		});
	}
}

smallImageBrowser = {
	init : function(){
		smallImageBrowser.inAnimation = false;
		smallImageBrowser.currentItem = parseFloat(0);

		$('div.smallImageBrowser').each(function(){
			smallImageBrowser.itemsCount = $(this).find('ul li').size();
			$(this).find('span.counter').text('1/' + $(this).find('ul li').length);

			$(this).find('ul li:eq(0)').css({position: 'absolute', left: '0px'});

			// Set the counter
			smallImageBrowser.galleryWidth = parseFloat($(this).find('ul li img').width());

			$(this).find('ul li:gt(0)').each(function(){
				$(this).css({
					position : 'absolute',
					right : smallImageBrowser.galleryWidth
				});
			});
		});


	},

	previous : function(caller){
		if(!smallImageBrowser.inAnimation){
			tempItemsValue = $(caller).parent().parent().parent().find('span.counter').text();
			tempCurrentItem = tempItemsValue.substr(0,$(caller).parent().parent().parent().find('span.counter').text().indexOf('/'));
			smallImageBrowser.currentItem = parseFloat(tempCurrentItem - 1); // -1 is cause arrays always start at 0
			smallImageBrowser.itemsCount = parseFloat(tempItemsValue.substr($(caller).parent().parent().parent().find('span.counter').text().indexOf('/') + 1,$(caller).parent().parent().parent().find('span.counter').text().length));

			smallImageBrowser.inAnimation = true;

			$(caller).parent().parent().parent().find('ul li:eq('+smallImageBrowser.currentItem +')').animate({ 'left': smallImageBrowser.galleryWidth }, 500 );

			smallImageBrowser.currentItem = (smallImageBrowser.currentItem - 1) % smallImageBrowser.itemsCount;
			if(smallImageBrowser.currentItem < 0){ smallImageBrowser.currentItem = smallImageBrowser.itemsCount - 1; }

			$(caller).parent().parent().parent().find('ul li:eq('+smallImageBrowser.currentItem +')').css('left',-smallImageBrowser.galleryWidth);
			$(caller).parent().parent().parent().find('ul li:eq('+smallImageBrowser.currentItem +')').animate({ 'left': 0 }, 500, function(){ smallImageBrowser.inAnimation = false; } );

			$(caller).parent().parent().parent().find('span.counter').text(smallImageBrowser.currentItem + 1 + '/' + $(caller).parent().parent().parent().find('ul li').length);
		}
	},
	next : function(caller){
		if(!smallImageBrowser.inAnimation){
			tempItemsValue = $(caller).parent().parent().parent().find('span.counter').text();
			tempCurrentItem = tempItemsValue.substr(0,$(caller).parent().parent().parent().find('span.counter').text().indexOf('/'));
			smallImageBrowser.currentItem = parseFloat(tempCurrentItem - 1); // -1 is cause arrays always start at 0
			smallImageBrowser.itemsCount = parseFloat(tempItemsValue.substr($(caller).parent().parent().parent().find('span.counter').text().indexOf('/') + 1,$(caller).parent().parent().parent().find('span.counter').text().length));

			smallImageBrowser.inAnimation = true;

			$(caller).parent().parent().parent().find('ul li:eq('+smallImageBrowser.currentItem +')').animate({ 'left': -smallImageBrowser.galleryWidth }, 500 );

			smallImageBrowser.currentItem = ++ smallImageBrowser.currentItem % smallImageBrowser.itemsCount;

			$(caller).parent().parent().parent().find('ul li:eq('+smallImageBrowser.currentItem+')').css('left',smallImageBrowser.galleryWidth);
			$(caller).parent().parent().parent().find('ul li:eq('+smallImageBrowser.currentItem+')').animate({ 'left': 0 }, 500, function(){ smallImageBrowser.inAnimation = false; } );

			$(caller).parent().parent().parent().find('span.counter').text(smallImageBrowser.currentItem + 1 + '/' + $(caller).parent().parent().parent().find('ul li').length);
		}
	}
}

detailsContent = {
	show : function(caller){
		if($(caller).parent().parent().find('div.detailsContent').is(':visible')){
			$(caller).prev().show();
			$(caller).hide();
			$(caller).parent().parent().find('div.detailsContent').show();
			$(caller).parent().parent().find('div.detailsContent').slideUp();
		}else{
			$(caller).next().show();
			$(caller).hide();
			$(caller).parent().parent().find('div.detailsContent').hide();
			$(caller).parent().parent().find('div.detailsContent').slideDown();
		}
	}
}

cruiseDetailsContent = {
	show : function(caller){
		if($(caller).parent().find('div.detailsContent').is(':visible')){
			$(caller).prev().show();
			$(caller).hide();
			$(caller).parent().find('div.detailsContent').show();
			$(caller).parent().find('div.detailsContent').slideUp();
		}else{
			$(caller).next().show();
			$(caller).hide();
			$(caller).parent().find('div.detailsContent').hide();
			$(caller).parent().find('div.detailsContent').slideDown();
		}
	}
}

filter = {
	open : function(which, caller) {
		if($(which).is(':visible')){
			$(which).slideUp();
			$(caller).removeClass('filterOpen').addClass('filter');
		}else{
			$(which).slideDown();
			$(caller).removeClass('filter').addClass('filterOpen');
		}
	}
}

formCheckboxes = {
	init : function(){
		$('label.toggleContent').each(function(){
			if(! $(this).find('input[type=checkbox]').is(':checked')) $(this).next().hide();
			$(this).bind('click',function(){ $(this).next().slideToggle(); });
		});
	},
	open : function(which,caller){
		if($(caller).find('input[type=checkbox]:checked')){
		}
	}
}

vacationSearch  = {
	updateDaysLeft : function(){
		leavingDate = $('div.packageWrap:visible:last div.departureLeft input[type=text]:eq(0)').attr('value');
		if(leavingDate){
			leavingDate = leavingDate.split('/');
			leavingDay = leavingDate[0];
			leavingMonth = leavingDate[1];
			leavingYear = leavingDate[2];

			var leavingDate = new Date()

			leavingDate.setYear(leavingYear);
			leavingDate.setMonth(leavingMonth - 1);
			leavingDate.setDate(leavingDay);
		}

		arrivingDate = $('div.packageWrap:visible:last div.departureLeft input[type=text]:eq(1)').attr('value');
		if(arrivingDate){
			arrivingDate = arrivingDate.split('/');
			arrivingDay = arrivingDate[0];
			arrivingMonth = arrivingDate[1];
			arrivingYear = arrivingDate[2];

			var arrivingDate = new Date()

			arrivingDate.setYear(arrivingYear);
			arrivingDate.setMonth(arrivingMonth - 1);
			arrivingDate.setDate(arrivingDay);
		}

		if(leavingDate && arrivingDate){
			if((arrivingDate - leavingDate) > 0){
				$('div.packageWrap:visible:last div.departureRight span.numberNights').text(vacationSearch.days_between(leavingDate,arrivingDate));
			} else {
				$('div.packageWrap:visible:last div.departureRight span.numberNights').text('#');
			}
		} else {
			$('div.packageWrap:visible:last div.departureRight span.numberNights').text('#');
		}
	},
	days_between : function(date1, date2) {

	    // The number of milliseconds in one day
	    var ONE_DAY = 1000 * 60 * 60 * 24

	    // Convert both dates to milliseconds
	    var date1_ms = date1.getTime()
	    var date2_ms = date2.getTime()

	    // Calculate the difference in milliseconds
	    var difference_ms = Math.abs(date1_ms - date2_ms)

	    // Convert back to days and return
	    return Math.round(difference_ms/ONE_DAY)

	}
}

radioButtons = {
	toggle : function(which,value){
		if(value){
			$(which).slideDown();
		}else{
			$(which).slideUp();
		}
	}
}

locationChooser = {
	open : function(caller){
		largestA = 0;

		if(!$(caller).hasClass('selected')){
			$(caller).addClass('selected')
			$('#locationChoices').show();
			$('#locationChoices li a').each(function(){ if($(this).width() >largestA){ largestA = $(this).width() } });

			if(!jQuery.browser.msie || (jQuery.browser.msie && jQuery.browser.version == "7.0")){
				$(caller).css('width', largestA);
				$('#locationChoices').css('width', largestA - 2);
			}else{
				$(caller).css('width', $('#locationChoices').width());
				$(caller).addClass('selected')
			}
		}else{
			$(caller).removeClass('selected')
			$('#locationChoices').hide();
		}
	}
}

tabs = {
	init : function(){
		$('body,html').css({'height':'100%'});

		tabs.delay = 500; // in milliseconds
		tabs.timerRunning = false;
		tabs.previousSet = false;
		tabs.previousTab = "";
		tabs.toClose = "";

		tabs.containerHeight = parseFloat($("#homeContainer").height());
		$('#homeContainer').css('overflow','hidden');

		// Set the divs height in CSS, else the slider won't be able to recuperate it.
		$("#content").css({
			'top' : tabs.containerHeight,
			'height' : $("#content").height()
		});

		$("#goingTo").css({
			'top' : tabs.containerHeight,
			'height' : $("#goingTo").height()
		});

		$("#interrestedIn").css({
			'top' : tabs.containerHeight,
			'height' : $("#interrestedIn").height()
		});

		$("#suggest").css({
			'top' : tabs.containerHeight,
			'height' : $("#suggest").height()
		});
	},
	animate : function(which,caller){
		if(tabs.timerRunning){
			clearTimeout(myTimer);
		}
	 	myTimer = setTimeout('tabs.slideThem("'+which+'","'+$(caller).attr('id')+'");',tabs.delay);
		tabs.timerRunning = true;

		tabs.toBringDown = $(caller).parent();

		$(caller).parent().parent().bind('mouseout',function(){
			if(tabs.timerRunning){ clearTimeout(myTimer); }

			tabs.over = false;
			myTimer = setTimeout("tabs.checkOver()",150);
			tabs.timerRunning = true;
		});

		$(caller).parent().parent().bind('mouseover',function(){
			tabs.over = true;
		});
	},
	slideThem : function(which,caller){
		// Hide the hover that
		$('#'+ caller).parent().css({'visibility':'hidden'});

		if(tabs.toClose != "" && (tabs.toClose.attr('id') != $('#'+which).attr('id'))){
			$('#homeContainer').css('overflow','hidden');
			$('div#passengerContainer').hide();
			tabs.toClose.animate({top:tabs.containerHeight},function(){
				$(this).hide();
				overlay.close('passengerContainer'); /* Need to make sure the passenger container is closed */
				tabs.toShow.css({'visibility':'visible'});
			});
		}

		// Get the distance the tab needs to move
		var move = tabs.containerHeight - parseFloat($('#'+which).css('height'));

		tabs.toClose = $('#'+which);
		$('#'+which).show();
		$('#'+which).animate({top: move},function(){
			tabs.toShow = $("#"+ caller).parent();
		});
		$('#'+which).bind('mouseover',function(){
			if(tabs.timerRunning){
				clearTimeout(myTimer);
			}
			tabs.over = true;
			myTimer = setTimeout("tabs.checkOver()",150);
			tabs.timerRunning = true;
		});

		$('#'+which).bind('mouseout',function(){
			tabs.over = false;
		});
	},
	checkOver: function(){
		if(!tabs.over){
			$('#homeContainer').css('overflow','hidden');
			if(tabs.toClose != ""){
				$('div#passengerContainer').hide();
				tabs.toClose.animate({top:tabs.containerHeight},function(){
					$(this).hide();
					overlay.close('passengerContainer'); /* Need to make sure the passenger container is closed */
					tabs.toShow.css({'visibility':'visible'});
				});
			}
		}
	}
}
bookingsSearch = {
	toggleSearch : function(val) {
		radioButtons.toggle('#advancedSearch',val);
		if (val) {
			$('#advancedSearchToggle').hide();
			$('#basicSearchToggle').show();
		} else {
			$('#basicSearchToggle').hide();
			$('#advancedSearchToggle').show();
		}
		$('#advSrch').val(val ? 'true':'false');
		return false;
	},

	spreadBookingType : function(fromFormId, toFormId) {
		var from = document.getElementById(fromFormId);
		var to = document.getElementById(toFormId);
		if (to) {
			for (var i=0 ; i < from.pastBookingType.length ; i++) {
				to.pastBookingType[i].checked = from.pastBookingType[i].checked;
				to.pastBookingType[i].label.className = from.pastBookingType[i].label.className;
			}
		}
		return false;
	}
}
