$(document).ready(function() {

	// BEGIN MAIN DROP DOWN NAVIGATION
	// documentation - flowplayer.org/tools/tooltip.html

	$("#nav_1").tooltip({
		relative: true,
		position: 'bottom right',
		offset: [0, -133],
		effect: 'slidedownup',
		onBeforeShow: function() {
			$('#nav_1').addClass('navActive');
		},
		onHide: function() {
			$('#nav_1').removeClass('navActive');
		}
	});

	$("#nav_2").tooltip({
		relative: true,
		position: 'bottom right',
		offset: [0, -149],
		effect: 'slidedownup',
		onBeforeShow: function() {
			$('#nav_2').addClass('navActive');
		},
		onHide: function() {
			$('#nav_2').removeClass('navActive');
		}
	});

	$("#nav_3").tooltip({
		relative: true,
		position: 'bottom right',
		offset: [0, -156],
		effect: 'slidedownup',
		onBeforeShow: function() {
			$('#nav_3').addClass('navActive');
		},
		onHide: function() {
			$('#nav_3').removeClass('navActive');
		}
	});

	$("#nav_4").tooltip({
		relative: true,
		position: 'bottom right',
		offset: [0, -208],
		effect: 'slidedownup',
		onBeforeShow: function() {
			$('#nav_4').addClass('navActive');
		},
		onHide: function() {
			$('#nav_4').removeClass('navActive');
		}
	});

	$("#nav_5").tooltip({
		relative: true,
		position: 'bottom right',
		offset: [0, -110],
		effect: 'slidedownup',
		onBeforeShow: function() {
			$('#nav_5').addClass('navActive');
		},
		onHide: function() {
			$('#nav_5').removeClass('navActive');
		}
	});

	// create custom tooltip effect for jQuery Tooltip 
	$.tools.tooltip.addEffect("slidedownup",
	// opening animation 
	    function(done) {
	    	this.getTip().slideDown().show();
	    },
	// closing animation 
	    function(done) {
	    	this.getTip().slideUp(function() {
	    		$(this).hide();
	    		done.call();
	    	});
	    }
	);

	// END MAIN DROP DOWN NAVIGATION



	// showhide home page booking form
	$('#book_home').showhide({
		target_obj: $('#boxBookForm'),
		default_open: false,
		plus_class: 'plus',
		minus_class: 'minus',
		plus_text: '',
		minus_text: ''
	});

	// show search - hide email and cookie as search
	$('.showSearch').click(function() {
		$('#formHeadEmail').css("display", "none");
		$('#formHeadSearch').css("display", "block");
		$.cookie('headerForm', 'search');
	});
	// show email - hide search and cookie as email
	$('.showEmail').click(function() {
		$('#formHeadEmail').css("display", "block");
		$('#formHeadSearch').css("display", "none");
		$.cookie('headerForm', 'email');
	});

	//COOKIE for header email - search tabs
	//header form state
	var headerForm = $.cookie('headerForm');
	//if headerForm cookie is set to email then show email and hide search
	if (headerForm == 'email') {
		$('#formHeadEmail').css("display", "block");
		$('#formHeadSearch').css("display", "none");
	};
	//if headerForm cookie is set to search then show search and hide email
	if (headerForm == 'search') {
		$('#formHeadEmail').css("display", "none");
		$('#formHeadSearch').css("display", "block");
	};

	/* toggle between two maps in map overlay */
	$('.toggleMaps').click(function() {
		$('#boxMap1').toggle();
		$('#boxMap2').toggle();
	});

	/* show-hide more info for search form */
	$('#toggleHeaderFormMoreInfo1').click(function() {
		$('#targetHeaderFormMoreInfo1').toggle();
		$('#toggleHeaderFormMoreInfo1').toggleClass('on');
	});

	/* use the class .draggable to make items draggable */
	$(function() {
		$(".draggable").draggable();
	});


	// BEGIN MODULES

	//WRAPPER RIGHT COLUMN ACCORDION
	$("#accordion").tabs("#accordion div.pane", { tabs: 'h2', effect: 'slide', initialIndex: null });

	//MEDIA GALLERY: TABS
	// setup ul.tabsModMediaGallery to work as tabs for each div directly under div.panesModMediaGallery
	$("ul.tabsModMediaGallery").tabs("div.panesModMediaGallery > div");

	//MEDIA GALLERY - PHOTOS: SCROLLABLE
	// initialize scrollable together with the circular plugin
	//$("#modGalleryPhotos").scrollable({ 
	$('.scrollableGalleryPhotos').scrollable({
		size: 1,
		clickable: true,
		onSeek: function(event) {
			event.preventDefault();
			//$('div.pageindex').text(this.getPageIndex()+1);
			//$('div.pageamount').text(this.getPageAmount());
			event.target.getRoot().parent().find('div.pageindex').text(this.getPageIndex() + 1);
			event.target.getRoot().parent().find('div.pageamount').text(this.getPageAmount());
		}
	}).circular();
	// generate values for initial load: 1 of X
	//$('div.pageindex').text(1);
	//$('div.pageamount').text($(".modItemGalleryPhotos").length - $("#modGalleryPhotos .cloned").length);

	$('.scrollableGalleryPhotos').each(function() {
		$(this).parent().find('div.pageindex').text(1);
		$(this).parent().find('div.pageamount').text($(this).find('.modItemGalleryPhotos').length - $(this).find('.cloned').length);
	});

	//SPECIALS: SCROLLABLE
	// initialize scrollable together with the circular, autoscroll & navigator plugins
	//$("#modSpecials").scrollable({ 
	$('.scrollableSpecials').scrollable({
		size: 1,
		clickable: true,
		loop: true
		//}).circular().navigator({navi:'.naviSpec' }).autoscroll({interval: 7000});
	}).navigator({ navi: '.naviSpec' }).autoscroll({ interval: 7000 });

	//ITINERARY: SCROLLABLE
	// initialize scrollable together with the circular, autoscroll & navigator plugins
	$("#modItinerary").scrollable({
		size: 1,
		clickable: true
	}).circular().navigator({ navi: '.naviItin' }).autoscroll({ interval: 7000 });

	//END ACCORDION MODS


	// show the multimedia tabs only if there are > 1 tabs to show
	$('.tabsModMediaGallery').each(function() {
		if ($(this).find('li').length > 1) {
			$(this).show();
		}
	});




	// overlay
	$("img[rel]").overlay().addClass("pointer");
	//$("a[rel]").overlay().addClass("pointer");

	$("a[rel]").each(function() {
		var el = $(this);
		var target = el.attr("rel");
		$(target).appendTo("body");
		el.overlay({ target: target });
		el.addClass("pointer");
	});

	// row striping for content tables
	$('.tblContent tr:odd').addClass('tblAltRow');


	// uber map
	$('#boxContentMap, #homeMap').click(function() {
		popWindow('/map.aspx', 'map', 1024, 725, false);
	});
});

function popWindow(url, popname, popwidth, popheight, scrolling) {

	window.name = "daddy";
	var scrollBoolean = "yes";
	if (scrolling) {
		scrollBoolean = scrolling;
	}
	var newWidth = popwidth;
	var newHeight = popheight;
	var newTop = 0, newLeft = 0;
	if (window.outerHeight) {
		newTop = window.screenY + ((window.outerHeight - newHeight) / 2);
	}
	else {
		newTop = window.screenTop + ((document.body.offsetHeight - newHeight) / 2);
	}
	if (window.outerWidth) {
		newLeft = window.screenX + ((window.outerWidth - newWidth) / 2);
	}
	else {
		newLeft = window.screenLeft + ((document.body.offsetWidth - newWidth) / 2);
	}
	var popupWin = window.open(url, popname,
		'screenX=' + newLeft +
		',screenY=' + newTop +
		',left=' + newLeft +
		',top=' + newTop +
		',width=' + newWidth +
		',height=' + newHeight +
		',menubar=no' +
		',toolbar=no' +
		',location=no' +
		',status=no' +
		',resizable=yes' +
		',scrollbars=' + scrollBoolean);
}
