$(document).ready(function(){
	
	// metrics graphs
	if($('a.destinations_metrics_nav_link').length > 0){
		var href = $('a.destinations_metrics_selected').attr('href');
		var id = href.substr(1);
		var img = $('div.destinations_metrics_img');
		$('div#' + id).removeClass('hide');
		var dest_link = $('a.destinations_metrics_nav_link');
		
		dest_link.click(function(){
			dest_link.removeClass('destinations_metrics_selected');
			$(this).addClass('destinations_metrics_selected');
			var href = $('a.destinations_metrics_selected').attr('href');
			var id = href.substr(1);
			var img = $('div.destinations_metrics_img');
			img.addClass('hide');
			$('div#' + id).removeClass('hide');
			return false;
		});
	}
	
	// fancybox
	if($('a.fancybox').length > 0){
		$('a.fancybox').fancybox({
			frameWidth : 600,
			//frameHeight : 400,
			frameHeight : 475,
			hideOnContentClick : false,
			callbackOnStart : function () { fancybox_display() },
			callbackOnClose : function () { fancybox_close() }
		});
	}
	
	// fancybox
	if($('a.media_overlay_launch').length > 0){
		$('a.media_overlay_launch').fancybox({
			frameWidth : 800,
			frameHeight : 570,
			hideOnContentClick : false
		});
	}
	
	/*
	$('#party_package_action_get_yours').fancybox({
		frameWidth : 600,
		frameHeight : 475,
		hideOnContentClick : false
	});
	*/
	
	//go back party package page
	$('#party_package_action_go_back').click(function()
	{
		window.history.back();
		return false;
	});
	
	// media block
	if($('a.media_module_launch').length > 0){
		$('a.media_module_launch').click(function(){
			var rel = $(this).attr('rel');
			$('#' + rel).fadeIn('500');
			$(this).parents('div.destination_section').fadeOut('500');
			return false;
		});
		
		$('a.media_module_close').click(function(){
			var rel = $(this).attr('rel');
			$('#' + rel).fadeIn('500');
			$(this).parents('div.media_module').fadeOut('500');
			return false;
		});
	}
	
	
	
	// day parties table
	if($('#day_party_inclusions_by_destination').length > 0){
	
		$('#day_party_inclusions_by_destination td').hover(function(){
			$(this).parents('tr').addClass('hover');
		},function(){
			$(this).parents('tr').removeClass('hover');
		});

		/*
		$('#day_party_inclusions_by_destination td').click(function(){
			$(this).parent('tr').children('td.data_day_party_destination').children('a.data_day_party_destination_title').fancybox({
				frameWidth : 600,
				//frameHeight : 400,
				frameHeight : 475,
				hideOnContentClick : false
			});
		});
		*/
	}
	
	
	/*
	// party package video
	if($('video.media_module_player').length > 0){
		$('video.media_module_player').jwplayer({
			flashplayer:'/lib/js/longtail-html5-beta/longtail-html5-player.swf',
			skin:'/lib/js/longtail-html5-beta/theme/five.xml'
		});
	}
	*/
	

	// maps
	$('#destination_browser_nav_link_maps').click(function(){
		$.ajax({
			url:'/2011/maps/index.html',
			data:{},
			success:function(data){
				$('#empty_div').html(data);
				$('#empty_div').dialog();
			},
			error:function(){}
		});
		return false;
	});
	
	
	// qtip
	$('a.destination_switcher_item_link').each(function(){
		var content = $(this).siblings('div.destination_switcher_tip_wrap').html();
		$(this).qtip({
			content:content,
			position:{
				corner:{
					target:'topMiddle',
					tooltip:'bottomMiddle'
				}
			},
			show:'mouseover',
			hide:'mouseout',
			style:{
				width:300,
				height:85,
				border:{
					width:2,
					radius:6,
					color:'#000'
				},
				padding:10, 
				textAlign:'left',
				//name:'dark',
				tip:true
			},
			prerender:true
		});
	});

	
	// tabs
	if($('div.destination_browser_content_tabs').length > 0){
		var tab_sections = $('div.destination_browser_content_tabs');
		var tab_links = $('#destination_browser_content_subnav li a');
		tab_sections.children('div').each(function(){
			$(this).addClass('tab');
		});
		$('div.tab').hide();
		$('div.tab:first-child').show();
		tab_links.click(function(){
			tab_sections.children('div.tab').hide();
			var href = $(this).attr('href');
			$(href).show();
			return false;
		});
	}

	
	// FAQ
	if($('ul.faq_question_list').length > 0){
		var question = $('a.question');
		var question_li = $('li.faq_question_li');
		question_li.removeClass('answer_expanded').addClass('answer_collapsed');
		question.click(function(){
			var this_question_li = $(this).parents('li.faq_question_li');
			if(this_question_li.hasClass('answer_collapsed')){
				this_question_li.removeClass('answer_collapsed').addClass('answer_expanded');
			} else {
				this_question_li.removeClass('answer_expanded').addClass('answer_collapsed');
			}
			return false;
		});
	}
	
	// this switches which room tab has the active class
	$('.destination_browser_content_subnav_link').click(function()
	{
		$('.destination_browser_content_subnav_link').removeClass('active');
		$(this).addClass('active');
	})
	
	/*
	$('a.show_deals').click(function(){
		$('ul.deals_details').slideDown();
		return false;
	});
	*/

});
