/*
 * JavaScript scripts for Smith & Tinker
 * 
 * @author Michael Lam <michael q t lam at gmail dot com>
 */

/*
 * Set up drop down navigation.
 */

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open() {
  jsddm_canceltimer();
  jsddm_close();
  ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}

function jsddm_close() {
  if (ddmenuitem) {
    ddmenuitem.css('visibility', 'hidden');
  }
}

function jsddm_timer() {
  closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer() {
  if (closetimer) {
    window.clearTimeout(closetimer);
    closetimer = null;
  }
}

/*
 * Loads jQuery functions on document ready.
 */
$(document).ready(function(){
  
  // Image hover overs
  $("img.rollover").hover(
    function() {
      var src = $(this).attr("src").replace("_off","_on");
      $(this).attr("src", src);
    },
    function() {
      var src = $(this).attr("src").replace("_on","_off");
      $(this).attr("src", src);
    }
  );
  
  $("img.nav").hover(
    function() {
      var src = $(this).attr("src").replace("_off","_on");
      $(this).attr("src", src);
    },
    function() {
      if ($(this).attr("class").toLowerCase().indexOf("current") >= 0) {
        var src = $(this).attr("src").replace("_on","_on");
        $(this).attr("src", src);
      } else {
        var src = $(this).attr("src").replace("_on","_off");
        $(this).attr("src", src);
      }
    }
  );
  
  // Lightbox: image pop ups
  $(function() {
    $('a.lightbox').lightBox({
      fixedNavigation: true
    });
  });
  
  // Navigation
  $('#navigation > li').bind('mouseover', jsddm_open);
  $('#navigation > li').bind('mouseout',  jsddm_timer);
});

document.onclick = jsddm_close;

