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

jQuery.fn.submitWithAjax = function() {
  this.submit(function() {
    $.post(this.action, $(this).serialize(), null, "script");
    return false;
  })
  return this;
};


function showcase_logic() {
	$("#showcase-container").css("overflow", "hidden");
	$("#showcase-container").after("<div id='showcase-next'>");
	$("#showcase-container").scrollLeft(0);
	
	var current_scroll = 0,
	    item_width = 529,
	    showcase_width = ($("#showcase li").length-1) * (item_width);
	$("#showcase-next").click(function(){
	  if(current_scroll < showcase_width) {
	    current_scroll += item_width;
  	  $("#showcase-container").animate({scrollLeft: current_scroll}, 200); 
	  } else {
	    current_scroll = 0;
	    $("#showcase-container").animate({scrollLeft: current_scroll}, 200);  
	  }
	});
}

function contact_form_logic() {
  $("#page").append("<div id='message-sent'>Your message was sent. Thank you.</div>");
  $("#new_contact").after("<input type='submit' value='Cancel' class='cancel' />");
  
	$("#message-sent").hide();
	
	$("#new_contact").submitWithAjax();
	$("#link-to-contact").click(function(){
	  if(parseInt($("#contact").css("right")) == 0) {
	    $("#contact").animate({right: -315}, 200);
	    return false;
	  } else {
	    $("#contact").animate({right: 0}, 200);
  	  return false;
	  }
	});
	
	$("#contact .cancel").click(function() {
	  $("#contact").animate({right: -315}, 200);
	});
} 

$(document).ready(function(){
	$(".event-targets").ezpz_tooltip({
  	showContent: function(content) {
  		content.fadeIn(100);
  	},
  	hideContent: function(content) {
  		content.stop(true, true).fadeOut(50);
  	}
  });
	
	$("#contact input").ezpz_hint();
  $(".download-targets").ezpz_tooltip();
	
	$(".story").each(function(){
		$(this).find("a.lightbox").lightBox();
	})
	
	contact_form_logic();
	showcase_logic();
})