$(function() {

	$('html').addClass('js');
	
	if ($('#home').length > 0) {
		$('body').css('overflow', 'hidden');
	}
	
	$(window).resize(function () {
		
		var ox = $(document).width() - $('header').width();
		var oy = $('header').outerHeight();
		
		$('#home #rotate img').each(function () {

			var self = this;
			var img = new Image();
			img.onload = function () {
				var cx = this.width;
				var cy = this.height;

				$(self).parent().css({
					'width': ox,
					'height': oy
				});

				$(self).parent().parent().css({
					'width': ox,
					'height': oy
				});

				if (ox / oy > cx / cy) {
					$(self).css({
						'width': ox,
						'height': (ox * cy / cx),
						'left': 0,
						'top': 0.5 * (oy - (ox * cy / cx)),
						'position': 'relative'
					});

				} else {
					$(self).css({
						'width': oy * cx / cy,
						'height': oy,
						'top': 0,
						'left': 0.5 * (ox - (oy * cx / cy)),
						'position': 'relative'
					});
				}
			}
			img.src = $(self).attr('src');
		});

		if($(document).width() < '951' || $(window).height() < '650') {
			$('body').addClass('small');
		} else {
			$('body').removeClass('small');
		}
	}).trigger('resize');
	
	var current = 0;
	var slide_len = $('#home #rotate li').length;
	$('#home #rotate li').css({
		'position': 'absolute',
		'display': 'none'
	}).each(function (i) {
		$(this).css('z-index', 10 + slide_len - i);
	});
	
	$('#home #rotate li:first').css('display', 'list-item');
	
	function slide (next) {
		$('#home #rotate li').eq(current).fadeOut(2000);
		$('#home #rotate li').eq(next).fadeIn(2000);
		$('#nav a').eq(next).addClass('activeSlide').siblings().removeClass('activeSlide');
		current = next;
		
		slideTimeout = setTimeout(function () {
			slide((current + 1) % slide_len);
		}, 6000);
	};
	
	var slideTimeout = setTimeout(function () {
		slide(1);
	}, 6000);
	
	$('#nav a').each(function (i) {
		$(this).click(function () {
			clearTimeout(slideTimeout);
			slide(i);
		});
	});

	if ($('#main .banner .cycle img').length > 1) {
		$('#main .banner').prepend('<div id="cycle-nav"><a id="cycle-prev"></a><a id="cycle-next"></a></div>');
		$('#main #cycle-nav a').hide();
		$('#main .banner').mouseenter(function() {
			$('#main #cycle-nav a').stop(true, true).fadeIn();
		}).mouseleave(function() {
			$('#main #cycle-nav a').stop(true, true).fadeOut();
		});
		$('#main .banner .cycle').cycle({ 
			fx:		'fade',
			speed:	1500,
			next:	'#cycle-next', 
			prev:	'#cycle-prev' 
		});
	}
	

	$('.listing-scroll ul').jcarousel({
		'visible':		4,
		'scroll':		1
	});
	
	$('.book-online .date').datepicker({
		minDate: 0,
		dateFormat: 'mm/dd/yy',
		showOn: 'button',
		buttonImage: '/skin/1/img/calendar.png',
		buttonImageOnly: true
	});
	
	
});
