/**
 * Initialize the jQuery functions
 */ 
jQuery(function($)
{
  initSuperfish();
  initLinkhandling();
  initFancybox();
  initHover();
});

function initSuperfish()
{
  if (! $('#mainnav > ul').length ) return;
  
  /* HEI.at Dropdown Navigation */
  $("#mainnav > ul").superfish({
    hoverClass: "opened",
    autoArrows: false,
    delay: 500
  });
}

function initLinkhandling()
{
  // target blank for external links
  $("a[href^='http']").attr("target", "_blank");
  
  // exclude search results (they always begin with http)
  // $("dl.searchresults a[href^='http']").removeAttr("target");
}

function initFancybox ()
{
  if (! $('.imageSmall a').length ) return;
  
  $('.imageSmall a').fancybox({
    zoomOpacity: true,
    zoomSpeedIn: 300,
    zoomSpeedOut: 300,
    zoomSpeedChange: 200,
    overlayShow: true,
    overlayOpacity: 0.6
  });
}

/**
 * This function makes blocks clickable. 
 */ 
function initHover()
{
  if (! $('.clickable').length ) return;
  
  $('.clickable')
  .hover(
    function()
    {
      $(this).addClass('clickableHover');
    },
    
    function()
    {
      $(this).removeClass('clickableHover');
    }
  )
  .click(function()
  {
    window.location = $('a', this).attr('href');
  });
}

