
// Document Ready
$(document).ready(function(){
  
  // Fix all TOP links
  $("a[href^=#]").click(function(event){ event.preventDefault(); document.location.hash = $(this).attr('href'); });
  
  // Update all images with "hover" states
  $("img[data-hover]").each(function(){
    // Add a data-hover to the image
    $(this).attr('data-hover', $(this).attr('data-hover'));
    $(this).attr('data-blur', $(this).attr('src'));
    // Add a hover event to the image
    $(this).hover(
      function(){
        $(this).attr('src',$(this).attr('data-hover'));
        },
      function(){
        $(this).attr('src',$(this).attr('data-blur'));
        }
      );
    });
  
  // Add hover events to all menu buttons
  $("a[data-dropdown]").each(function(){
    var thisLink = this;
    var theseItems = window[$(thisLink).attr('data-dropdown')];
    if (theseItems){
      thisLink.onmouseover = function(e){
        if (!e) var e = window.event;
        dropdownmenu(thisLink, e, theseItems, '155px');
        };
      thisLink.onmouseout = function(e){
        if (!e) var e = window.event;
        delayhidemenu();
        };
      }
    });
    
  // Change any pretty photo links to lightboxes
  if (jQuery().colorbox){
    $("a[rel^=colorbox]").each(function(){
      // Create custom variables if needed
      var isIframe = $(this).is('[rel*=\[iframe\]]') ? true : false;
      var isInline = $(this).is('[rel*=\[inline\]]') ? true : false;
      var thisWidth = $(this).attr('data-width') ? $(this).attr('data-width') : false;
      var thisHeight = $(this).attr('data-height') ? $(this).attr('data-height') : false;
      // If it is an iframe link
      if (isIframe){
        $(this).colorbox({opacity:0.5,current:'{current} / {total}',href:$(this).attr('href'),iframe:true,width:(thisWidth ? thisWidth : 500),height:(thisHeight ? thisHeight : 500)});
        }else if(isInline){
        $(this).colorbox({opacity:0.5,current:'{current} / {total}',href:$(this).attr('href'),inline:true,width:(thisWidth ? thisWidth : 500),height:(thisHeight ? thisHeight : 500)});
        }else{
        $(this).colorbox({opacity:0.5,current:'{current} / {total}',width:thisWidth,height:thisHeight});
        }
      });
  }
     
});

// Image preloader
jQuery.preloadImages = function() {
  for(var i = 0; i < arguments.length; i++) {
    jQuery("<img>").attr("src", arguments[i]);
  }
}
