/**
	Global JavaScript functions
**/


/* Google +1 button 
************************************/
(function() {
	var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
	po.src = 'https://apis.google.com/js/plusone.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();


/* jQuery DOM ready
************************************/
jQuery(document).ready(function(){
	
	/* footer toggle on home page */
	var h_callouts = jQuery('#home_callouts');
	var h_btn_toggle = jQuery('footer .btn_toggle');
	var h_footer = jQuery('footer');
	var h_container = jQuery('#container');
	var h_push = jQuery('.push');
	var h_bottom = jQuery('footer .bottom');
	
	jQuery('#home .btn_toggle a').click(function(){
		if (h_footer.height() != 285) { /* if footer is not expanded then do this */
			h_callouts.animate({bottom: '290px'});
			h_btn_toggle.css('background-position','center -30px');			
			h_footer.animate({height: '285px'});
			h_push.animate({height:'285px'});
			h_container.animate({marginBottom: '-285px'});
			h_bottom.slideDown('slow');
		} else {
			h_callouts.animate({bottom: '140px'});
			h_btn_toggle.css('background-position','center top');
			h_footer.animate({height:'95px'});
			h_push.animate({height:'95px'});
			h_container.animate({marginBottom:'-95px'});
			h_bottom.fadeOut('fast');				
		}
	});
	
	/* footer toggle on category pages */
	var c_callouts = jQuery('#callouts');
	var c_footer_cta = jQuery('#footer_cta');
	var c_btn_toggle = jQuery('footer .btn_toggle');
	var c_footer = jQuery('footer');
	var c_push = jQuery('.push');
	var c_container = jQuery('#container');
	var c_bottom = jQuery('footer .bottom');
	var c_btn_expand = jQuery('#btn_expand');

	jQuery('.category .btn_toggle a').click(function(){
		if (c_footer.height() != 285) {
			if (c_footer_cta.height() == 106) { /* check if footer cta is expanded - 106 pixels */
				c_callouts.animate({bottom: '366px'});
				c_btn_expand.animate({bottom: '366px'});
				c_footer_cta.animate({bottom: '285px'});
				c_btn_toggle.css('background-position','center -30px');			
				c_footer.animate({height: '285px'});
				c_push.animate({height:'285px'});
				c_container.animate({marginBottom: '-285px'});
				c_bottom.slideDown('slow');
			} else { 
				c_callouts.animate({bottom: '335px'});
				c_btn_expand.animate({bottom: '335px'});
				c_footer_cta.animate({bottom: '285px'});
				c_btn_toggle.css('background-position','center -30px');			
				c_footer.animate({height: '285px'});
				c_push.animate({height:'285px'});
				c_container.animate({marginBottom: '-285px'});
				c_bottom.slideDown('slow');
			}	
		} else {
			if (c_footer_cta.height() == 106) { /* check if footer cta is expanded - 106 pixels */
				c_callouts.animate({bottom: '250px'});
				c_btn_expand.animate({bottom: '250px'});
				c_footer_cta.animate({bottom: '95px'});
				c_btn_toggle.css('background-position','center top');
				c_footer.animate({height:'95px'});
				c_push.animate({height:'95px'});
				c_container.animate({marginBottom:'-95px'});
				c_bottom.fadeOut('fast');
			} else { 
				c_callouts.animate({bottom: '180px'});
				c_btn_expand.animate({bottom: '180px'});
				c_footer_cta.animate({bottom: '95px'});
				c_btn_toggle.css('background-position','center top');
				c_footer.animate({height:'95px'});
				c_push.animate({height:'95px'});
				c_container.animate({marginBottom:'-95px'});
				c_bottom.fadeOut('fast');
			}
		}
	});
	
	/* footer toggle on detail pages */
	var d_footer = jQuery('footer');
	var d_bottom = jQuery('footer .bottom');
	var d_btn_toggle = jQuery('footer .btn_toggle');
	var d_doc_height = jQuery(document).height();
	var d_window_height = jQuery(window).height();
	var d_html = jQuery('html, body');
	var d_scroll_pos = d_doc_height - d_window_height + 285;
	var d_scroll_pos_closed = d_doc_height - d_window_height - 285;
	
	jQuery('.detail .btn_toggle a').click(function(){		
		
		if (d_footer.height() != 285) {		
			d_footer.animate({height: '285px'});
			d_btn_toggle.css('background-position','center -30px');	
			d_bottom.slideDown('slow');
			d_html.animate({ scrollTop: d_scroll_pos }, 1000);
		} else {
			d_footer.animate({height:'95px'});
			d_btn_toggle.css('background-position','center top');
			d_bottom.fadeOut('fast');
			
			// hack for ie 7
			if (jQuery.browser.msie) {
				if (jQuery.browser.version<8) {
					d_html.animate({ scrollTop: d_scroll_pos_closed }, 1000);
				}
			}
			
		}
	});


	/* jcarousel */
	/*jQuery('#activities_carousel').jcarousel({
		scroll: 1	
	});*/
	
	/* primary nav semi-fisheye effect / show subnav */
	jQuery('#primary li').hoverIntent(
		function(){
			jQuery(this).children('.button-rollover').animate({fontSize: '17px'},400);
			jQuery(this).children('aside').fadeIn('slow');
		},
		function(){
			jQuery(this).children('.button-rollover').animate({fontSize: '11px'},400);
			jQuery(this).children('aside').fadeOut('slow');
		}
	);
	
	// close button on footer cta	
	var g_footer_cta = jQuery('#footer_cta');	
	
	jQuery('#fc_pack .btn_close a').click(function(){
		if (g_footer_cta.height() == 106) {
			g_footer_cta.animate({height: '32px'});
			jQuery(this).css('background-position','left top');
		} else {
			g_footer_cta.animate({height: '106px'});
			jQuery(this).css('background-position','left -8px');
		}
	});
	
});


/* show /hide CTA 
************************************/
function show_cta(id, button) {
	var any_cta = jQuery('.dialogue');
	var cta = jQuery('#'+id+'');
	var sel_button = jQuery('#'+button+'');
	var any_button = jQuery('#utility .cta a');
	
	if (any_cta.is(':visible')) { 
		if (cta.is(':visible')) { 
			cta.slideUp('fast');
			sel_button.removeClass('selected');
		} else { 
			any_cta.slideUp('slow');
			any_button.removeClass('selected');
			cta.slideDown('slow');
			sel_button.addClass('selected');
			jQuery('header#masthead').append(cta);
		}
	} else {	
		cta.slideDown('slow');
		sel_button.addClass('selected');
		jQuery('header#masthead').append(cta);
	}
}


/* hide cta - specific to CTA buttons on utility nav */
function hide_cta(id) {
	var cta = jQuery('#'+id+'');
	
	if (cta.is(':visible')) {		
		cta.slideUp('slow');
		jQuery('#utility .cta a').removeClass('selected');
	}
}

/* close aside - specific to main nav */
function close_aside() { 
	jQuery('#primary a.btn_close').parent('aside').hide();
}


// cta activities disjointed rollover
function swap_activity(id) { 
	var image_id = id;
	var any_image = jQuery('#cta_activities .display img');
	var any_link = jQuery('#cta_activities ul li a');
		
	jQuery(any_image).hide();
	jQuery('#'+image_id+'').show();
	jQuery(any_link).removeClass('selected');
	
}


/* generic close div by ID */
function close_div(id) { 
	jQuery('#'+id+'').fadeOut('fast');
}
		
/* check if element exists */
/*
if (jQuery(selector).length){  
	
}
*/

// show itinerary on spa packages 
function reveal(id) { 
	alert('bingo');
}






