/*///////////////////
/////////////////////
/////////////////////
/////////////////////
/////////////////////


NOTE: the jQuery $ function is not in use as it conflicts with uCodes $ function, we now use the j$ instead!!!


/////////////////////
/////////////////////
/////////////////////
/////////////////////
/////////////////////*/

$j(document).ready(function(){

	var months = {
		'01':'January',
		'02':'February',
		'03':'March',
		'04':'April',
		'05':'May',
		'06':'June',
		'07':'July',
		'08':'August',
		'09':'September',
		'10':'October',
		'11':'November',
		'12':'December'
	};
	
	$j('ul#photoDisplay').cycle({
		fx: 'wipe',
		clip: 'l2r',
		autostop: 1,
		timeout: 3000
	});

	//get the initial sizes of the two boxes
	var initialStaffStoryHeight = $j('#staffStory').height();
	var initialStaffStoryContainerHeight = $j('#staffStoryContainer').height();
	//resize the boxes on click
	$j('.fullArticle').click(function(){
		if($j('#staffStory').height() != initialStaffStoryHeight){
			$j('#staffStory').animate({
				height: initialStaffStoryHeight
			}, 300);
			$j('#staffStoryContainer').animate({
				height: initialStaffStoryContainerHeight
			}, 300);
		} else {
			//$j(this) refers the the thing that was clicked
			$j('#staffStory').animate({
				height: $j('#'+$j(this).attr("title")).height() + 10
			}, 300);
			$j('#staffStoryContainer').animate({
				height: $j('#'+$j(this).attr("title")).height()
			}, 300);
		}
		return false;
	});
	
	$j('#staffContainer').cycle({
		fx:     'scrollLeft',
		speed:    'fast',
		timeout: 0,
		delay: 400,
		next:   '#next',
		prev:   '#prev',
		prevNextClick: shrinkStaffStory
	});
	
	$j('#staffStoryContainer').cycle({
		fx:     'scrollLeft',
		speed:    'fast',
		timeout: 0,
		delay: 400,
		next:   '#next',
		prev:   '#prev',
		prevNextClick: shrinkStaffStory
	});

	function shrinkStaffStory(){
		//resize the staff story boxes when you click previous
		$j('#staffStory').animate({
			height: initialStaffStoryHeight
		}, 300);
		$j('#staffStoryContainer').animate({
			height: initialStaffStoryContainerHeight
		}, 300);
	}

	$j('ul#historyPhotos').cycle({
		fx: 'fade',
		autostop:0,
		timeout: 3000
	});
		 
	$j('ul#diningPhotos').cycle({
		fx: 'fade',
		autostop:0,
		timeout: 3000
	});

	$j('ul#staffPhotos').cycle({
		fx: 'fade',
		autostop:0,
		timeout: 3000
	});
		 
	$j('ul#amenities').cycle({
		fx: 'fade',
		autostop:0,
		timeout: 3000
	});
		 
	$j('#suitePhotos').cycle({
		fx:     'scrollLeft',
		speed:  'fast',
		timeout: 0,
		pager:  '#suiteNav',
		pagerAnchorBuilder: function(idx, slide1) {
			return '<a href="#"><img src="' + slide1.src + '" width="50" height="50" /></a>';
		}
	});
	$j('a.moreInfo').click(function(){
		var expandId = "packageDetails"+$j(this).attr('id').charAt(8);
		//so it doesn't open and close the box, check if we have clicked on the expanded one
		if($j('.marker').attr('id') != expandId){
			$j(".marker").animate({
				height: '0px'
			}, 300);
			$j(".marker").removeClass('marker');
			$j("#"+expandId).addClass('marker');
			$j("#"+expandId).animate({
				height: '135px'
			}, 300);
		}
		return false;
	})

	$j('#bookingForm').submit(function(){
		//set the arrival time
		var arrival = $j('#arrival').val().split('-');
		$j('#arrival').attr('name', '');
		if(arrival[0]){
			$j('#inyear').val(arrival[0]);
		}
		if(arrival[1]){
			$j('#inmonth').val(months[arrival[1]]);
		}
		if(arrival[2]){
			$j('#inday').val(arrival[2]);
		}
		//set the departure time
		var departure = $j('#departure').val().split('-');
		$j('#arrival').attr('name', '');
		if(departure[0]){
			$j('#outyear').val(departure[0]);
		}
		if(departure[1]){
			$j('#outmonth').val(months[departure[1]]);
		}
		if(departure[2]){
			$j('#outday').val(departure[2]);
		}
		return true;
	});
	

	
	$j('#calendar').show();
	//so that the new hidden inputs do not get overwritten on submit
	$j('#dropDowns').remove();
/*
$j('ul#photoDisplay').cycle({
			fx:      'custom', 
			cssBefore: {
				clip: 0, 0 , 0  		
				}, 
			animOut: {  
				clip: 0,200,200,0
				}, 
			animIn: {  
				opacity: 1,
				clip: 0, 0 , 0
				}, 
			cssAfter: {  
				opacity: 1 
				}, 
			delay: -3000,
			sync: 0
		});

*/
});