$(function(){
	
	$('#page').addClass('js');
	
	$('#ads .flowpanes')
		.scrollable({
			items:'#ads .panes',
			prev:'#ads .prev',
			next:'#ads .next',
			keyboard:false,
			circular: true
		});
		
	$('#featured .flowpanes')
		.scrollable({
			items:'#featured .panes',
			prev:'#featured .prev',
			next:'#featured .next',
			keyboard:false
		});
	
	$('#nav > ul > li').hover(function(){
		$('.sub',$(this)).stop(false,true).fadeIn('medium');
	},function(){
		$('.sub',$(this)).stop(false,true).fadeOut('fast');
	});
	  
	$("#slider .nav, #collage .nav")
		.tabs("#slider .pane, #collage .pane",{
			current:'sel',
			effect:'fade',
			fadeOutSpeed:"slow",
			rotate:true
		}) 
		.slideshow({
			autoplay:true,
			//interval:5000,
			interval:interval,     
			clickable:false
		});
		
	$('.pane .more','#slider').hover(function(){
		$('.summary',this).stop(false,true).fadeIn('medium');
	},function(){
		$('.summary',this).stop(false,true).fadeOut('fast');
	});

	$('#get-reservation-date','#book')
		.focus(function(){
			$('.frm-add','#book').slideDown('fast');
		})
		.dateinput({
			format: 'mm/dd/yyyy',
			selectors: true,
			offset: [-19,-218]
		});
	$(document).click(function(e){
		if($('.frm-add','#book').is(":visible")){
			var target = $(e.target).closest('#book, #calroot, #page');
			if(target.is('#page')){
				$('.frm-add','#book').slideUp('fast');
			}
		}
	});
	
	$('ul.accordion .title').click(function(){
		if($(this).closest('li').hasClass('expanded'))
			$(this).siblings('.data').slideUp('fast').closest('li').removeClass('expanded');
		else
			$(this).siblings('.data').slideDown('fast').closest('li').addClass('expanded')
				.siblings('li.expanded').removeClass('expanded').children('.data').slideUp('fast');
	});
	
	$('.news-item','ul.news').click(function(){
		if(!$(this).hasClass('expanded'))
			$(this).closest('.news-item').addClass('expanded').animate({'width':'772px'},'fast').children('.cover').animate({'width':'320px'},'fast');
	});
	$('.close','ul.news').click(function(){
		$(this).closest('.news-item').animate({'width':'384px'},'fast', function(){$(this).removeClass('expanded');}).children('.cover').animate({'width':'150px'},'fast');
	});
	
	$("#ipad .tabs")
		.tabs("#ipad .pane",{
			current:'sel'
		});
		
	if($.browser.msie){
		$(".two-cols").columnize({columns: 2});
		$(".three-cols").columnize({columns: 3});
	}
	
	$.simpleWeather({
		location: 'miami, usa',
		unit: 'c',
		success: function(weather) {
			var faren = Math.round(weather.high*(9/5)+32);
			$('em','#weather').html(faren+'&#176;');
		},
		error: function(message){
			$('em','#weather').html(message);
		}
	});
	
	animateReservationItems('#reservations .item:first');
	
	function animateReservationItems(obj) {
		$(obj).find('h4').css("marginLeft", "0px");
		$(obj).fadeIn(1000, function(){
			var current = $(this);
			var index = $('#reservations .item').index(current);
		    var total = $('#reservations .item').length;
		    var image_width;
		    if ($(this).find('img').width() > 0){
		    	image_width = $(this).find('img').width() + 10;
		    }else{
		    	image_width = 0;
		    }
		    if ($(this).find('h4').width() + image_width + 12 > $(this).parents('#reservations').width()) {
		    	$(this).find('h4').delay(3000).animate({marginLeft : "-" + ($(this).find('h4').width() - $(this).parents('#reservations').width() + image_width + 12) + "px"}, ($(this).find('h4').width() - $(this).parents('#reservations').width() + image_width + 12)/0.0387, function(){
		    		if (total != 1){
		    		    current.delay(3000).fadeOut(1000, function(){
		    			    if (index != total-1){
		    				    current = current.next();
		    			    }else{
		    				    current = $('#reservations .item:first'); //current = $('#reservations .item').first();
		    			    }
		    			    animateReservationItems(current);
		    		    });
		    		}
		    	});
		    }else{
		    	if (total != 1){
		    		    current.delay(9000).fadeOut(1000, function(){
		    			    if (index != total-1){
		    				    current = current.next();
		    			    }else{
		    				    current = $('#reservations .item:first'); //current = $('#reservations .item').first();
		    			    }
		    			    animateReservationItems(current);
		    		    });
		    		}
		    }
	    });
	}
	
});
