document.documentElement.className = 'js';

var tools =
{
	generic :
	{
		init : function()
		{
			// Generic page specific jQuery functions.

			// tooltip
			$("sup a, a[rel=terms]").tooltip({ 
				delay: 300,
				track: false, 
				fade: 50,
				id: 'tooltip',
				left: 0,
				top: 20,
				showURL: false
			});
			
			// terms pop up
			$('sup a, a[rel=terms]').click(function() {    
				var width=465; 
				if ($.browser.msie) { var width=466;}  
				window.open($(this).attr('href'),'','width='+width+',height=500,scrollbars=yes');
				return false;
			});
			
			// popup
			if (jQuery.isFunction(jQuery.fn.facybox)) { $('a[rel=popup]').facybox(); }
	
			// print
			$('a.print').click(function(){ print(); });
			
			// guide details --> location selected
			var url = String(window.location).split('guide')[1];
			$('ul#cities li a[href*='+url+']').addClass('selected');
			
		} //init
	}, //generic

	home :
	{
		
		init : function()
		{
			// Home page specific jQuery functions
			
			

			$('#toggle').fadeTo(0,0);
	
			// set ctabox to closed position - if javascript is off then box is already in open position
			// $('#gcd_ctabox').css('height','205px');
			$('#gcd_ctabox').addClass('initial_open');

			$('#gcd_ctabox').hover(function() {
				$('#toggle').fadeTo(350,1);
			}, function() {
				var cta_height = $('#gcd_ctabox').height();
				if (cta_height< 206) $('#toggle').fadeTo(350,0);
				
			});
			
			$('#toggle').toggle(function() {
				var text_height = $('#gcd_ctabox .content').height();
				var ems = (text_height/100)*6.25-5;
				var initial = (243/100)*6.25;
				initial+=ems;
				
				$(this).parent()
					.animate({height: initial+'em'}, { queue:false, duration:500 })
					.fadeTo(450,1,function(){ 
						// pauses then callback to toggle close button image
						$(this).find('span').addClass('close');
						
					});
			}, function() {
				$('#toggle').fadeTo(350,0);
				$(this).parent()
					.animate({height: 205}, { queue:false, duration:500 })
					.fadeTo(450,1,function(){ 
						$(this).find('img.toggle').attr('src','/assets/img/GCD_icon_expandtolearnmore.png').attr('width','186');
						$(this).find('span').removeClass('close');

					});
			});
			
			// tabs
			// $("#tabs").tabs("#panes > div"); 
			
			// ie check -- :hover support & rounded corners in ctabox & min offer tab size in ie6
			if (!jQuery.support.opacity) {
				
				$('#gcd_ctabox').append('<img src="/assets/img/GCD_cta_ie_roundedcorners.png" alt="" class="br_ie_corners">');
				$('#toggle:hover').css('cursor','pointer');

				// offer tab min sizing... in ie6 only
				if(typeof document.body.style.maxHeight === "undefined") {
					var countoffers = $('body#home .offer').size();
					if (countoffers<2) { $('#panes').css('padding-bottom','120px'); }
				}
			}
			
			// Move the position to where we want it.
			// If this doesnt execute all 4 logos are shown by default.
			$('#logo-rotator,#logo-rotator li').addClass('activate');

			$('#logo-rotator').cycle({ 
				timeout: 3000, 
				speed:   750
			});	
			
			
		} // init
	}, // home
	
	benefits :
	{
		init : function()
		{
			// Benefits page specific jQuery functions

			$(".vacations .showhide, .cruises .showhide").toggle(
				function () {
					$(this).addClass('show');
					// var height = $(this).closest('.text').height();
					// var readmore_height = $(this).parent().find('.readmore').height();
					// var total_height = height+readmore_height-15;
					// $(this).data("height", total_height);
					
					$(this).parent().next('.extra').stop().animate({ height: '100%' }, 0); 
					return false;
				},
				function () {
					$(this).removeClass('show');
					// var height = $(this).data('height');
					$(this).parent().next('.extra').stop().animate({ height: '0' }, 0);
					return false;
				}
			);
			
		} // init
	}, // benefits
		
	guide :
	{
		init : function()
		{
		
		// Guide page specific jQuery functions.
		
			// set hoverintent defaults
			$.event.special.hover.delay = 50; 
			$.event.special.hover.speed = 100;
			
			// activate accordion
			$('.areas').kwicks({
				max: 396,
				spacing:  4
			});
			
			// rounded corners in accordion first and last section
			// $('#area1, #area5').wrapInner('<div class="inner unitPng"></div>');
			
			if (jQuery.isFunction(jQuery.fn.facybox)) { $(".areas ul.hotels a").facybox();  }
			
			


		} //init
	}, //guide
	
	offer_details :
	{
		
		init: function()
		{
			// Offers detail page specific jQuery functions
	
			$('#thumbs li').hover(function(){
				$(this).css('cursor','pointer');
				$('#thumbs li img').removeClass('selected');
				$(this).find('img').addClass('selected');
				
				var photo_src = $(this).find('img').attr('src');
				var photo_desc = $(this).find('img').attr('title');
				
				$('img.offer_photo').attr('src',photo_src).attr('title',photo_desc);
				$('#photoLarge #caption').html(photo_desc);
			});
	
			// terms slide for offers
			
			var initial_height = $('.offer_details').height();
			$('#terms').data("height", initial_height);
			
			$('#gcd_guide_inner a.showhide').toggle(
				function() {
    		
					$(this).addClass('show');
    		
					var height = $('#terms').height();
					$('#terms').css('margin-bottom','-'+(height)+'px').show();
					$('.offer_details').stop().animate({height: initial_height+height+'px'}, 'fast');
					return false; 
				},
				function() {
					
					$(this).removeClass('show');
					$('.offer_details').stop().animate({height: ($('#terms').data('height')-2)+'px'}, 'fast');
					return false; 
				}
			);
			// end terms slide for offers
			
    	}	
	},

	ie_generic :
	{
		init : function()
		{
			// Generic IE specific jQuery functions.
			
			// ie shim for bottom rounded corners
			$('.gcd_aside_offer').append('<div></div>');

			// make cursor link for showhide when not an <a>
			$('.showhide, a.close').hover(
				function() {
					$(this).css('cursor','pointer').css('text-decoration','underline');
				},
				function(){
					$(this).css('text-decoration','none');
				});
	
		
		} //init
	}, //generic


	ie6_alpha_hacks :
	{
		
		init: function()
		{
			
			
			// alpha for ie6
			if (typeof DD_roundies.addRule == 'function') {
				
				DD_roundies.addRule('div.link, .br_ie_corners, .container h2, .sidebar li, img.button, #gcd_wheretogo h3, .sidebar h3, a.readmore, .inner, #gcd_staywithus h3, img.hotels, .gcd_aside_offer h3, #gcd_travel_accordion h3');
			
			}
			
			else
			
			{
				
				DD_belatedPNG.fix('.br_ie_corners, .container h2, .sidebar li, img.button, #gcd_wheretogo h3, .sidebar h3, a.readmore, .inner, #gcd_staywithus h3, img.hotels, .gcd_aside_offer h3, #gcd_travel_accordion h3');
			}
		
		} // init
	}, // ie6_alpha_hacks
	
	ie7_guide_alpha :
	{
		
		init: function()
		{	

			if (typeof DD_roundies.addRule == 'function') {
				DD_roundies.addRule('#gcd_travel_accordion h3');
			}
			else
			{
				DD_belatedPNG.fix('#gcd_travel_accordion h3');
			}
			
			
		} // init
	}, // ie7_guide_alpha
	
	ie6_benefits :
	{
		init : function()
		{
			
		// Guide specific jQuery functions.
		
			// set equal height columns on benefit features columns
			var highestCol = Math.max($('#feature_planning').height(),$('#feature_protections').height(),$('#feature_opportunities').height());
			$('#features div').height(highestCol);

		} //init
	}, //benefits_ie6
		
	ie_guide :
	{
		init : function()
		{
			
		// Guide specific jQuery functions.
			
			// rounded corners
			DD_roundies.addRule('.sidebar', '6px'); // rounded GOLD CARD MEMBERS FAVORITES BOX


		} //init
	}, //guide
	
	ie7_recommendations_details:
	{
		init : function()
		{
			
		// Guide specific jQuery functions.
		
			// fix for amex javascript screwing with ie7
			var aside_element = $('#gcd_detail .aside');
			
			if (aside_element.length >0) {
				var width = aside_element.position().left;
				if (width==303) {  
						aside_element.wrap('<div class="ie7fix"></div>');
				}
			}


		} //init
	} //guide_ie7


};