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() {
				// Omniture tracking
				s=s_gi(s_account);
				omn_charSet="UTF-8";
				omn_pagename='GCDLearnMore';  
				omn_hierarchy='US|Amex|Loy|GCD';
				omn_language="en";
				omn_newpagename="yes";
				s.t();
				// Animate
				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
			});	
			
			// get date
			var date = new Date();
			var d  = date.getDate();
			var day = (d < 10) ? '0' + d : d;
			var m = date.getMonth() + 1;
			var month = (m < 10) ? '0' + m : m;
			var yy = date.getYear();
			var year = (yy < 1000) ? yy + 1900 : yy;
			var datestring = year+'-'+month+'-'+day;

			// remove expired offers 
			var offers = $("#panes div.offer");
			offers.filter(function(index) {
				var expires = $(this).attr('id');
				return (expires<('expires-'+datestring));
			}).hide();
			
			// sort offers by expire date
			// offers.tsort({order:"asc",attr:"id"});
			
		} // init
	}, // home
	
	benefits :
	{
		init : function()
		{
			// Benefits page specific jQuery functions
			$(".vacations .showhide, .cruises .showhide").toggle(
				function () {
					$(this).addClass('show');					
					$(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()
		{
			
			// bind ajax link to hotel menu items if is inital first pass or screen reader cookie is set false
			if ($.cookie('screenreader')==null | $.cookie('screenreader')==false){
				$(".areas ul.hotels a").click(function(){
					var url = $(this).attr('href');
					var pagename = $(this).attr('rel');
					// Omniture tracking
					if(pagename) {
						s=s_gi(s_account);
						omn_charSet="UTF-8";
						omn_pagename=pagename;  
						omn_hierarchy='US|Amex|Loy|GCD|DestinationGuide';
						omn_language="en";
						omn_newpagename="yes";
						s.t();
					}
					// Open layer
					$.get(url, function(data) { $.facybox(data); });
					return false;
				});
			};
			
			// call screenreader check if no screenreader session cookie set
			if ($.cookie('screenreader')==null) {
				// load flashAid screenreader check - calls successHandler javascript function which loads facybox popups if no screenreader present
				var flashvars = {};
				flashvars.callback = "tools.guide.successHandler";
				var params = {};
				params.quality = "low";
				params.allowscriptaccess = "always";
				var attributes = {};
				swfobject.embedSWF("/assets/swf/flashAid.swf", "screenreader_check", "1", "1", "8.0.0", false, flashvars, params, attributes, tools.guide.swfcomplete);
			}
			
			// 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>');
			
		}, //init
		
		// function for flashAid swf file to call
		successHandler : function(accessibilityIsActive){
			
			var isActiveStr = accessibilityIsActive ? "Yes" : "No";
			
			if (accessibilityIsActive) {
				
				$(".areas ul.hotels a").unbind("click"); 
				$.cookie('screenreader', accessibilityIsActive, { expires: 0 });
				
			}
			
		},
		
		swfcomplete: function(e){
			
			// add focus to flash embed so screenreader notices it
			if (e.success==true) { 
				$("object#screenreader_check").focus();
			}
		}
		
	}, //guide
	
	offers :
	{
		init: function(){
			
			// get date
			var date = new Date();
			var d  = date.getDate();
			var day = (d < 10) ? '0' + d : d;
			var m = date.getMonth() + 1;
			var month = (m < 10) ? '0' + m : m;
			var yy = date.getYear();
			var year = (yy < 1000) ? yy + 1900 : yy;
			var datestring = year+'-'+month+'-'+day;

			// sort offers by expiration date
			// $("div.offer").tsort({order:"asc",attr:"id"});
			
			// remove expired offers 
			$("div.offer").filter(function(index) {
				var expires = $(this).attr('id');
			  	return (expires<('expires-'+datestring));
			}).hide();
			
		}
		
	},
	
	offer_details :
	{
		
		init: function()
		{
			// Offers detail page specific jQuery functions
		
			var isIE6 = typeof document.body.style.maxHeight === "undefined";

			$('#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);
			});
	
			var terms_wrapper = $('#terms');
			var terms_innerwrapper = $('#terms div');

			$('#gcd_guide_inner a.showhide').toggle(
				function() {
					$(this).addClass('show'); // toggle the + - image

					var terms_height = terms_innerwrapper.height()+12; // get height of terms div

					terms_innerwrapper.css({'position':'relative','visibility':'visible'});
					if (!isIE6) { terms_innerwrapper.animate({opacity: 1}, 50); } // don't fade in with ie6 'cos it is awful.

					terms_wrapper.stop().animate({height: terms_height+'px'}, 'fast'); // slide down the terms div
					return false; 
				},
				function() {
					
					$(this).removeClass('show'); // toggle the + - image
					
					terms_wrapper.stop().animate({height: '0px'}, 'fast');
					if (!isIE6) { terms_innerwrapper.animate({opacity: 0}, 150); }
					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


};

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

// tinysort plugin http://www.sjeiti.com/?page_id=321
(function(b){b.tinysort={id:"TinySort",version:"1.0.4",defaults:{order:"asc",attr:"",place:"start",returns:false}};b.fn.extend({tinysort:function(h,j){if(h&&typeof(h)!="string"){j=h;h=null}var e=b.extend({},b.tinysort.defaults,j);var p={};this.each(function(t){var v=(!h||h=="")?b(this):b(this).find(h);var u=e.order=="rand"?""+Math.random():(e.attr==""?v.text():v.attr(e.attr));var s=b(this).parent();if(!p[s]){p[s]={s:[],n:[]}}if(v.length>0){p[s].s.push({s:u,e:b(this),n:t})}else{p[s].n.push({e:b(this),n:t})}});for(var g in p){var d=p[g];d.s.sort(function k(t,s){var i=t.s.toLowerCase?t.s.toLowerCase():t.s;var u=s.s.toLowerCase?s.s.toLowerCase():s.s;if(c(t.s)&&c(s.s)){i=parseFloat(t.s);u=parseFloat(s.s)}return(e.order=="asc"?1:-1)*(i<u?-1:(i>u?1:0))})}var m=[];for(var g in p){var d=p[g];var n=[];var f=b(this).length;switch(e.place){case"first":b.each(d.s,function(s,t){f=Math.min(f,t.n)});break;case"org":b.each(d.s,function(s,t){n.push(t.n)});break;case"end":f=d.n.length;break;default:f=0}var q=[0,0];for(var l=0;l<b(this).length;l++){var o=l>=f&&l<f+d.s.length;if(a(n,l)){o=true}var r=(o?d.s:d.n)[q[o?0:1]].e;r.parent().append(r);if(o||!e.returns){m.push(r.get(0))}q[o?0:1]++}}return this.pushStack(m)}});function c(e){var d=/^\s*?[\+-]?(\d*\.?\d*?)\s*?$/.exec(e);return d&&d.length>0?d[1]:false}function a(e,f){var d=false;b.each(e,function(h,g){if(!d){d=g==f}});return d}b.fn.TinySort=b.fn.Tinysort=b.fn.tsort=b.fn.tinysort})(jQuery);