
jQuery.ajaxSetup({ 
  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})

$(document).ready(function() {
	$('.autofocus:first').focus();
	$("#popup_request_form").submit(function() {
		$.post(this.action, $(this).serialize(), null, "script");
		$("#form_submit_button").attr("disabled", "true");
		return false;
	});
	
	$("#persistant_contact_link").click(function(){
                    $("#persistant_contact_form").animate({width:'toggle'},1000);
    });
    
    $("#cancel_persistant_contact_form").click(function() {
    	$("#persistant_contact_form").animate({width:'toggle'},1000);
    });
    
    $("#persistant_contact_form_container").show();
    
     $("#persistant_contact_form form").submit(function() {
		$.post(this.action, $(this).serialize(), null, "script");
		$("#contact_form_submit_button").attr("disabled", "true");
		return false;
	}); 
	
	$(".tip").tooltip({ offset: [0, 75] }).dynamic({ bottom: { direction: 'down' } });
	     
	//this is the homepage tabs
	$("ul#flowtabs").tabs("div.items > div.item", { effect: 'fade', fadeoutspeed: "slow", rotate: true}).slideshow({
	autoplay: true,
	clickable: false,
	interval: 15000
	});
	
	//this is the scroll function for the about_us pages
	$("#about_us_scroller").scrollable({ vertical: true, circular: true, speed:800 }).autoscroll({autoplay: true, interval: 8000});

   //slide down share with friend menu
   $("a#share_with_friend_link").click(function() {
   		$("#hidden_share_with_friend_form").slideDown("fast").toggle();
   		$("a#share_with_friend_link") .toggleClass("menu_open");
   		return false;
   });
   $("#share_with_friend a.cancel").click(function() {
   		$("#hidden_share_with_friend_form").hide();
   		$("a#share_with_friend_link").removeClass("menu_open");
   		return false;
   });
   
   //slidedown info request menu
   $("a#request_more_information_link").click(function() {
   		$("#hidden_request_more_information_form").slideDown("fast").toggle();
   		$("a#request_more_information_link") .toggleClass("menu_open");
   		return false;
   });
   $("#request_more_information a.cancel").click(function() {
   		$("#hidden_request_more_information_form").hide();
   		$("a#request_more_information_link").removeClass("menu_open");
   		return false;
   });
   
   //vacation pages popup gallery
   $("img[rel]").overlay({
   	top: '1%',
   	mask: {
   		color: '#202020',
   		loadSpeed: 200,
   		opacity: 0.9,
   	}
   });
   
   $(".scrollable").scrollable();
   $("img.launch_photo").click(function() {
 
	// see if same thumb is being clicked
	if ($(this).hasClass("active")) { return; }
 
	// calclulate large image's URL based on the thumbnail URL (flickr specific)
	if ($(this).hasClass("note_photo")) {
		var url = $(this).attr("src").replace("medium", "large");
	}
	else {
		var url = $(this).attr("src").replace("thumb", "large");
	}
	//var url = $(this).attr("src").replace("thumb", "large");
	//var url = $(this).attr("src").replace("medium", "large");
 
	// get handle to element that wraps the image and make it semi-transparent
	var wrap = $("#image_wrap").fadeTo("medium", 0.75);
 	//var wrap = $("#image_wrap");
	// the large image from www.flickr.com
	var img = new Image();
 
 
	// call this function after it's loaded
	img.onload = function() {
 
		// make wrapper fully visible
		wrap.fadeTo("fast", 1);
 
		// change the image
		wrap.find("img").attr("src", url);
 
	};
 
	// begin loading the image from www.flickr.com
	img.src = url;
 
	// activate item
	$("img.launch_photo").removeClass("active");
	$(this).addClass("active");
	});
});
