$(document).ready(function() {

	// BEGIN MAIN DROP DOWN NAVIGATION
	// documentation - flowplayer.org/tools/tooltip.html

	$("#nav_1").tooltip({
		relative: true,
		position: 'bottom right',
		offset: [0, -149],
		effect: 'slidedownup',
		onBeforeShow: function() {
			$('#nav_1').addClass('navActive');
		},
		onHide: function() {
			$('#nav_1').removeClass('navActive');
		}
	});

	$("#nav_2").tooltip({
		relative: true,
		position: 'bottom right',
		offset: [0, -104],
		effect: 'slidedownup',
		onBeforeShow: function() {
			$('#nav_2').addClass('navActive');
		},
		onHide: function() {
			$('#nav_2').removeClass('navActive');
		}
	});

	$("#nav_3").tooltip({
		relative: true,
		position: 'bottom right',
		offset: [0, -105],
		effect: 'slidedownup',
		onBeforeShow: function() {
			$('#nav_3').addClass('navActive');
		},
		onHide: function() {
			$('#nav_3').removeClass('navActive');
		}
	});

	$("#nav_4").tooltip({
		relative: true,
		position: 'bottom right',
		offset: [0, -105],
		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();
		}
	});



	
	// qtvr
	$("a.qtvr").each(function() {

		var el = $(this);
		var target = $('#qtvr');

		$(target).appendTo("body");
		el.overlay({
			target: target
		});
		el.addClass("pointer");

		$(this).click(function() {
			$('#qtvrContainer').html("");

			var embedCode = '<object classid="clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b" width="450" height="316" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0">';
			embedCode += '<param name="src" value="' + $(this).attr("rel") + '" />';
			embedCode += '<param name="qtsrc" value="' + $(this).attr("rel") + '" />';
			embedCode += '<param name="autoplay" value="true" />';
			embedCode += '<param name="loop" value="false" />';
			embedCode += '<param name="controller" value="true" />';
			embedCode += '<embed type="video/quicktime" width="450" height="316" src="' + $(this).attr("rel") + '" controller="true" loop="false" autoplay="true" qtsrc="' + $(this).attr("rel") + '"></embed>';
			embedCode += '</object>';

			$('#qtvrContainer').html(embedCode);
			$('#qtvrCaption').html($(this).attr('title'));
		});
	});



	// overlay
	//$("a[rel]").not("a.qtvr").overlay().addClass("pointer");


	// 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');


});