/*==========================================================
  MAIN JS FILE
  For  global functions, etc.
==========================================================*/

// -- ENABLE TRACING USING jsTrace -- //
var trace;
if( typeof( jsTrace ) != 'undefined' ){
  trace = function( msg ){
    jsTrace.send( msg );
  };
} else {
  trace = function(){ };
}

// -- ENABLE inArray() -- //
Array.prototype.inArray = function( value ){
  var i;
  for( i=0; i < this.length; i++ ){
    if( this[i] === value ){
      return true;
    }
  }
  return false;
};

var Highlighter = Class.create();
Highlighter.prototype = {
  initialize: function(){
    trace( 'initalize' );
    $A( document.getElementById( 'headshots' ).getElementsByTagName( 'a' ) ).each( function( link, i ){
      link.setAttribute( 'id', 'photo_'+i );
      Event.observe( link, 'mouseover', this.focusName, false );
      Event.observe( link, 'mouseout', this.blurName, false );
    }.bind( this ));
    $A( document.getElementById( 'staff-nav' ).getElementsByTagName( 'a' ) ).each( function( link, i ){
      link.setAttribute( 'id', 'name_'+i );
      Event.observe( link, 'mouseover', this.focusPhoto, false );
      Event.observe( link, 'mouseout', this.blurPhoto, false );
    }.bind( this ));
  },
  focusName:  function( e ){
    var el = Event.element( e );
    if( el.nodeName.toLowerCase() == 'img' ) el = el.parentNode;
    var id = el.getAttribute( 'id' ).replace( 'photo_', '' );
    Element.addClassName( document.getElementById( 'name_'+id ), 'hover' );
  },
  blurName:   function( e ){
    var el = Event.element( e );
    if( el.nodeName.toLowerCase() == 'img' ) el = el.parentNode;
    var id = el.getAttribute( 'id' ).replace( 'photo_', '' );
    Element.removeClassName( document.getElementById( 'name_'+id ), 'hover' );
  },
  focusPhoto: function( e ){
    var id = Event.element( e ).getAttribute( 'id' ).replace( 'name_', '' );
    Element.addClassName( document.getElementById( 'photo_'+id ), 'hover' );
  },
  blurPhoto:  function( e ){
    var id = Event.element( e ).getAttribute( 'id' ).replace( 'name_', '' );
    Element.removeClassName( document.getElementById( 'photo_'+id ), 'hover' );
  }
};
// if Prototype, lowpro & required DOM methods are available
if( typeof( Prototype ) != 'undefined' &&
    typeof( LowPro ) != 'undefined' ){
  Event.onReady( function(){
    if( document.getElementById( 'headshots' ) &&
        document.getElementById( 'staff-nav' ) ){
      var highlighter =  new Highlighter();
    }
  } );
}