if (location.pathname.match( /[(^\/)](.*?)[\/]menu[\/]/ )) {
	$.fn.fadeSliderToggle = function(settings) {
		 	settings = jQuery.extend({
		 		speed: 500,
		 		easing: "swing"
		 	}, settings);
	
		 	caller = this;
		 	
		 	if ($(caller).css("display") == "none") {
		 		$(caller).animate({
		 			opacity: 1,
		 			height: 'toggle'
		 		}, settings.speed, settings.easing);
		 	} else {
		 		$(caller).animate({
		 			opacity: 0,
		 			height: 'toggle'
	 			}, settings.speed, settings.easing);
			}
	}

	$.fn.setAllToMaxHeight = function(){
		return this.height( Math.max.apply(this, $.map( this , function(e){ return $(e).height() }) ) );
	}
}

function bbtfColumnize() {
	var colWrap, colNum, colFixed;
	var colMain = jQuery('.blog .inner-content, .search .inner-content');
	var colChild = jQuery('.blog .inner-content article, .search .inner-content article');
	var colPad;

	if( navigator.userAgent.match(/safari/i) ) {
		colPad = 30;
	} else {
		colPad = 32;
	}

	colMain.css({
		'width': "100%"
	});

	colWrap = colMain.width() - colPad;
	colNum = Math.floor(colWrap / 274);
	colFixed = Math.floor(colWrap / colNum);

	colMain.css({
		'width': colWrap
	});
	colChild.css({
		'width': colFixed
	});
}

jQuery(function($) {
	if( ! location.pathname.match( /[(^\/)](.*?)[\/]preorder[\/]/ )) {
		window.location.hash = ''; // cross browser solution to scrollTop(0)
	}

	// bind fancy box to href's with fancy box class
	$("a[class$=fancybox]").fancybox({
		overlayOpacity: 0.9,
		overlayColor: '#000',
		margin: '30px',
		padding: 0
	});

	// only utilize this function on the root of the domain
	if (location.pathname.match( /(^\/[^\/]*[\/]$)|(^\/$)/ ) ) {
		$('.slide-sidebar-home').nivoSlider({
			effect: 'fade',
			directionNav: false,
			pauseTime: 5000
		});
		
		offset = $(window).height() + 310 + $('.inner-content').innerHeight(); // height of entire footer incl expanded events
		$("html, body").css({
			height: offset
		});
	}

	
	if (location.pathname.match( /(^\/[^\/]*[\/]$)/ ) ) {
		$(".footer-events").animate({
			height: '205px'
		}, {
			queue: false,
			duration: 500,
			easing: 'easeInSine'
		});
	} else {
		$(".footer-events-expand a img").attr("src", "/img/events/events_arrow_up.png");
	}

	// expandable footer
	$(".footer-inner .footer-events-text span a, .footer-events-expand a").toggle(function () {
		if ($(".footer-events").css("height") == "123px") {
			$(".footer-events").animate({
				'height': "205px"
			}, {
				queue: false,
				duration: 500,
				easing: 'easeInSine'
			});
			$(".footer-events-expand a img").attr("src", "/img/events/events_arrow_down.png");
		} else {
			$(".footer-events").animate({
				'height': "123px"
			}, {
				queue: false,
				duration: 500,
				easing: 'easeInSine'
			});
			$(".footer-events-expand a img").attr("src", "/img/events/events_arrow_up.png");
		}
	}, function () {
		if ($(".footer-events").css("height") == "123px") {
			$(".footer-events").animate({
				'height': "205px"
			}, {
				queue: false,
				duration: 500,
				easing: 'easeInSine'
			});
			$(".footer-events-expand a img").attr("src", "/img/events/events_arrow_down.png");
		} else {
			$(".footer-events").animate({
				'height': "123px"
			}, {
				queue: false,
				duration: 500,
				easing: 'easeInSine'
			});
			$(".footer-events-expand a img").attr("src", "/img/events/events_arrow_up.png");
		}
	});

	// position content & right sidebar based on navigation offset
	$(function () {
		if ( ! location.pathname.match( /(^\/[^\/]*[\/]$)|(^\/$)/ ) ) {
			var offset = $("#navigation .container").offset().top - 46;
			$("#content, #sidebar").css({
				top: offset
			});
		}
	});

	$(window).bind('resize', function () {
		if( ! location.pathname.match( /[(^\/)](.*?)[\/]preorder[\/]/ )) {
			window.location.hash = '';
		}
		if ( ! location.pathname.match( /(^\/[^\/]*[\/]$)|(^\/$)/ ) ) {
			offset = $("#navigation .container").offset().top - 46;
			$("#content, #sidebar").css({
				top: offset
			});
		}
	});

	// bind & re-position footer with resize/scroll
	$(function () {
		offset = $(window).height() + 310 + $('.inner-content').innerHeight(); // height of entire footer incl expanded events
		$("html, body").css({
			//height: offset
		});
		/*$("footer#content-info").css({
			bottom: '-109px'
		});*/
	});

	$(window).bind('resize', function () {
		offset = $(window).height() + 310 + $('.inner-content').innerHeight(); // height of entire footer incl expanded events
		$("html, body").css({
			//height: offset
		});
		/*$("footer#content-info, .footer-events").css({
			bottom: '-109px'
		});*/
	});

	// initiate the slide if scrollTop is at 80% from the height of document
	/*$(window).bind('scroll', function () {
		if (((document.documentElement.scrollTop + document.body.scrollTop) / (document.documentElement.scrollHeight - document.documentElement.clientHeight) * 100) > 70) {
			$("footer#content-info").stop(true, false).animate({
				bottom: '0px'
			});
			$(".footer-events").stop(true, false).animate({
				bottom: '0px'
			});
		} else {
			$("footer#content-info").stop(true, false).animate({
				bottom: '0px'
			});
			$(".footer-events").stop(true, false).animate({
				bottom: '0px'
			});
		}
	});*/

	// smart columns
	$(function () {
		bbtfColumnize();
	});

	$(window).bind('resize', function () {
		bbtfColumnize();
	});

	// rotating wallpaper for homepage

	$("body").prepend('<div id="wallpapers"></div><div id="wallpapers-vignette"></div>');
	
	if (location.pathname.match( /(^\/[^\/]*[\/]$)|(^\/$)/ ) ) {
		$("body").prepend('<div id="wallpapers-nav">' +
		'<div class="wallpapers-inner">' +
		'<div id="next"><a href="javascript:;"><img src="/img/background/right.png"></a></div>' +
		'<div id="prev"><a href="javascript:;"><img src="/img/background/left.png"></a></div>' +
		'<div class="clearfix"></div>' +
		'</div>' +
		'</div>');
	}

	$("#wallpapers").append('<div class="one"></div><div class="two"></div><div class="three"></div>');
	$("#wallpapers").append('<div class="four"></div><div class="five"></div><div class="six"></div>');

	var timeout;
	if (location.pathname.match( /(^\/[^\/]*[\/]$)|(^\/$)/ ) ) {
		timeout = 10000;
	} else {
		timeout = 0;
	}

	$(function () {
		$('#wallpapers').cycle({
			fx: 'fade',
			speed: 1000,
			delay: 0,
			timeout: timeout,
			next: '#wallpapers-nav #next a',
			prev: '#wallpapers-nav #prev a'
		});
	});
	
	// virtual tour page
	
	if (location.pathname.match( /[(^\/)](.*?)[\/]virtual-tour[\/]/ )) {
		$(function () {
			$('.virtual-tour-bar-inner-slide').cycle({
				fx: 'scrollLeft',
				speed: 1000,
				timeout: 0,
				next: '#virtual-tour-page-right',
				prev: '#virtual-tour-page-left'
			});
		});
	}
	
	// fluxar food menu
	
	if (location.pathname.match( /[(^\/)](.*?)[\/]menu[\/]/ )) {
		$(function () {
			$('ul#fl_food_menu_sub:first, ul#fl_food_menu_items:first').fadeSliderToggle();
			$('h3.fl_food_menu_title').delegate("a", "click", function () {
				if( $(this).parent().next().is(':visible') ) {
					return false;
				}
				window.location.hash = ''; // cross browser solution to scrollTop(0)
				$(this).parent().parent().find('ul').css({ display: 'none' });
				$(this).parent().next().fadeSliderToggle();
				$(this).parent().next().next().fadeSliderToggle();
				$( $(this).parent().next(), $(this).parent().next().next() ).setAllToMaxHeight();
				Cufon.refresh();
				return false;
			});
		});
	}
	
	// homepage arrows
	var footer_size      = $('.footer-events').height() + $('.content-info').height();
	var nav_position     = $("#navigation .container").offset().top + 296; // very bottom of menu nav
	var window_height    = $(window).height();
	var window_height_c;
	var starting_height  = window_height - ( nav_position + footer_size );

/*
	$(function () {
		$(window).mousemove(function (e) {
			$('body').css("cursor","crosshair");
			$('.position').html('e.pageX = ' + e.pageX + ', e.pageY = ' + e.pageY);
		});
	});
*/

	$(window).bind('resize', function () {
		//nav_position     = $("#navigation .container").offset().top + 296; // very bottom of menu nav
		//starting_height  = window_height - ( nav_position - footer_size );
		
		//if( window_height < $(window).height() ) {
		//	$('#wallpapers-nav').css({ height:  });
		//} else {
		//	$('#wallpapers-nav').css({ height:  });
		//}
	});

	$(function() {
		$('#wallpapers-nav').css({ height: starting_height });
	});
	
	$(document).ajaxSuccess(function() {
		Cufon.refresh();
	});
	
	// packages extras page
	
	$(function() {
		var pa   = $('.extras .packages-extra p a');
		var ca   = $('.extras .packages-extra-content div');
		var hash;
		var offset;
		
		pa.first().addClass('active');
		ca.first().fadeIn('slow');

		pa.click(function(e) {
			e.preventDefault();
			
			$('.sub-head-img').find('img').attr('src','/img/reservations/' + $(this).attr('rel') + '.png');

			pa.each(function() {
				$(this).removeClass('active');
			});
			
			ca.each(function() {
				if( $(this).is(':visible') ) $(this).hide();
			});
			
			hash = '.extras .packages-extra-content #' + $(this).attr('rel');
			$(this).addClass('active');

			Cufon.refresh();
			
			$(hash).fadeIn('slow');

			$('#content .container').height( $('.inner-content').height() + ca.height() + 500 );
		});
	});
	
	// reservations
	
	$(function() {
		var element = $('.gform_body li.bbtf_datepicker .ginput_container input, .gform_body li .ginput_container input.bbtf_datepicker');
		var format  = "mm/dd/yy";
		var image = "/wp-content/plugins/gravityforms/images/calendar.png";
		var showOn = "both";
		
		$(element).addClass('datepicker datepicker_with_icon');

		element.datetimepicker({ ampm: true, showMinute: false, yearRange: '-100:+10', showOn: showOn, buttonImage: image, buttonImageOnly: true, dateFormat: format });
	});
	
	$(function() {
		var match = '';

		$('body').delegate('.navigation-logo', 'hover', function() {
			$(this).css( 'cursor', 'pointer' );
		});
		
		$('body').delegate('.navigation-logo', 'click', function() {
			match = location.pathname.match( /(^\/[^\/]*[\/])/ );
			console.log( match );
			window.location = match[1];
		});
	});
	
	
	var ismobile   = navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)/i);
	var iosversion = navigator.userAgent.match(/OS (\d)/i);

	if( ismobile ) {
		if( iosversion[1] <= 4 ) {
			$(function () {
				$.fancybox('<div style="background-color:black; padding: 20px; color: #FFF; font-size: 11px; color: #ECD6A8;"><span style="color:red; font-weight: bold;">NOTICE:</span> The 40/40 Club is unfortunately not optimized for your Apple product\'s iOS version. Please upgrade to iOS 5 or later for a better experience. To learn more, <a href="http://www.apple.com/ios/" target="_blank" style="text-decoration: underline;">click here</a>.</div>', {padding: 0, margin: 0});
			});
		}
	}

});
