//Libraries we're using:
//  jQuery 1.3.2
//  jQuery.easing 1.3
//  jQuery.backgroundPosition 1.1
//  jQuery.Tools 1.1.0 [tools.tabs-1.0.2, tools.tabs.slideshow-1.0.0, tools.tooltip-1.1.0, tools.overlay-1.1.0, tools.overlay.apple-1.0.0, tools.expose-1.0.4]

$(document).ready(function(){

  //home page animations

  $("#homenavleft").hover(
    function() {
      $("#homeimage").animate({"backgroundPosition": "(0px 0px)"}, { "duration": 1200, "easing": "easeOutBack" });
      $("#homeimage > p").animate({"backgroundPosition": "(0px 284px)"}, { "duration": 1200, "easing": "easeOutBack" });
      $("#homenavleftover").fadeIn("normal");      
    },
    function() { }
  );

  $("#homenavleftover").hover(
    function() { },
    function() {
      $("#homenavleftover").fadeOut("normal");
    }
  );

  $("#homenavright").hover(
    function() {
      $("#homeimage").animate({"backgroundPosition": "(200px 0px)"}, { "duration": 1200, "easing": "easeOutBack" });
      $("#homeimage > p").animate({"backgroundPosition": "(200px 284px)"}, { "duration": 1200, "easing": "easeOutBack" });
      $("#homenavrightover").fadeIn("normal");
    },
    function() { }
  );

  $("#homenavrightover").hover(
    function() { },
    function() {
      $("#homenavrightover").fadeOut("normal");
    }
  );


  $("#homebranding").hover(
    function() {
      $("#homeimage").animate({"backgroundPosition": "(100px 0px)"}, { "duration": 600, "easing": "easeOutQuad" });
      $("#homeimage > p").animate({"backgroundPosition": "(100px 284px)"}, { "duration": 600, "easing": "easeOutQuad" });
    },
    function() { }
  );
  
  
  
  //prepare the survey overlay
  $("a[rel]").overlay({ 
 
    expose: '#344e8e', 
    effect: 'apple', 
    
    onBeforeLoad: function() {
      this.getContent().find("div.wrap").load(this.getTrigger().attr("href") + "&overlay=1", "", prepareOverlayHandlers); 
    }
  });  


  //prepare "read more" links
  $("a.moreinfolink").click(function(e) {
    e.preventDefault();
    $(".moreinfo").slideToggle();
  });
});



function prepareOverlayHandlers() {
  $("#surveyform").submit(function(e) {
    e.preventDefault();
    
    $.post("index.php?mod=survey&overlay=1", $("#surveyform").serialize(), function(postresult) { $("#surveyoverlay > div.wrap").html(postresult); prepareOverlayHandlers(); }, "html");
  });
}

