$(document).ready(function(){
  if ($("body.front").length) {
    $("#block-menu_block-2 ul.menu, #block-menu_block-3 ul.menu, #block-menu_block-7 ul.menu").superfish(superfishSettings);
  }
  
  $(".region-sidebar-first .block-menu_block li").addClass("clearfix");

  if ($("#block-menu_block-6").length) {
    if ($("#block-menu_block-6 ul.menu:eq(0)").html().match('class="active')) {
      $("#block-menu_block-6").addClass("active-trail");
    };
    
    $("#block-menu_block-6").hoverIntent(
      function() {
        $(this).addClass("displayed");
        $(this).find(".content").fadeIn("normal");
      },
      function() {
        $(this).removeClass("displayed");
        $(this).find(".content").hide();
      }  
    );
  }

  if ($("#service-alerts").length) {
    $("#service-alerts .view-data-node-title").hoverIntent(function() {
      $(this).nextAll().show("fast");
      }, function() {
    });
  }
  if ($(".highlight-spec").length) {
    highlightSpecAnimating = 0;
    $(".highlight-spec").each(function() {
      var target = "#highlight-"+ $(this).attr("id").replace("highlight-spec-","");
      function highlightSpec() {
        if (!highlightSpecAnimating) {
          highlightSpecAnimating = 1;
          $(".highlight-hidden:not('"+ target +"')").slideUp("normal", function() {
            $(target).slideDown("normal", function() {
              highlightSpecAnimating = 0;
            });
          });
        }
      }
      $(this).addClass("highlight-processed").hoverIntent(highlightSpec, function() {
      }).bind("click", highlightSpec);
    });
  }

  $(".right-elements select").bind("click", function() {
    $(this).addClass("focused");    
  }).hoverIntent(function() {
    $(this).addClass("focused");
  }, function() {
    $(this).removeClass("focused");
  });

  /* Directories */
  if ($("#block-webform-2629").length) {
    $("#directory-feedback").colorbox({inline: true, href: "#block-webform-2629 .webform-client-form", close: "cancel", scrolling: false, width: "50%"});
  }

  $(".node-type-featured-container h2.title a, .node-type-featured-container-b h2.title a, .region-content-bottom h2.title a:not('.rss')").append(" &raquo;");

  if ($('a[class="slideshow-trigger"]').length) {
    $(".slideshow-data a").each(function() {
      $(this).attr("rel", $(this).attr("class"));
    });
    $('a[class="slideshow-trigger"]').each(function() {
      var rel = $(this).attr("id").replace("trigger-","slideshow-");
      $("a[rel='"+ rel +"']").colorbox({scalePhotos: false, scrolling: false, slideshow: true, slideshowSpeed: 5500, slideshowStart: "resume slideshow", slideshowStop: "pause slideshow", transition: "elastic", title: function() {
        return $("."+ $(this).attr("id")).html();
      }});
      $(this).click(function(event) {
        event.preventDefault();
        $("a[rel='"+ rel +"']:eq(0)").trigger("click");
      });
    });
  }

  $(".dropjump").bind("change", function(e) {
    destination = $(this).val();
    if (destination != "0") {
		  if ($("html").hasClass("www")) {
		    if (!destination.match("://")) {
    		  destination = destination +".html";
    		}
		  }

      document.location = destination;
    }
  });
  
  $(".sundial-rsvp-link").bind("click", function(e) {
    e.preventDefault();
    return false;
  });

  if (location.href.split("#")[1] == "thanks") {
    $.colorbox({html:'<div id="feedback-thankyou"><h2 class="title">Thank you.</h2><p>We appreciate your time in helping us create a better Columbia.edu.</p></div>', transition: "none"});
  }
});
