/*

© 2008 Ben Jones / e-motion design

Usage: Include this script
Then call
setupLink( 'abc' , 'http://google.com' );
- this links element with ID='abc' to google
or
setupLink( 'def' );
- which links element 'def' to the first link found within itself

*/

// Have the browser load the passed URL
function openURL( URL ) {
 window.location=URL;
}

// Set the cursor to be the hand (or normal cursor)
function setMouseStatus( e , cursorHand ) {
 // Set the cursor style appropriately
 if ( cursorHand ) {
  // Mouse-over code here
  e.style.cursor = 'pointer';
 } else {
  // Mouse-out code here
  e.style.cursor = 'default';
 }
}

// Link the element
function setupLink( e , URL ) {
 // Get the URL
 if ( URL == null ) {
  // If we weren't passed a URL, get the first A-HREF inside the element
  fe = e.getElementsByTagName('a')[0];
  if ( fe != null ) {
   URL =  fe.href;
  } else {
	 // If there are none inside, set to #
   URL = '#';
  }
 }
 // Set the click and mouseover/out behaviours
 e.onclick = new Function( "openURL('" + URL + "')" );
 e.onmouseover = new Function( "setMouseStatus( this , true )" );
 e.onmouseout = new Function( "setMouseStatus( this , false )" );
}
