//Author:   John Gardner
//Written:  8th November 2003
//Updated:  27th January 2004
//Updated 9/8/2007 by Michael Bowker death by snoo snoo
openPopup = function(imageURL, caption)
{
var w = window.open ("","imageWin","width=600,height=550,top=100,left=100,resizable");
w.document.write ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">" +
"<html><head><title>Large Image</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">" +
"<meta http-equiv=\"Content-Language\" content=\"en-gb\"><script language=\"JavaScript\" type=\"text/javascript\">" +
"function resizewindow () { window.resizeTo (document.myimage.width+17, document.myimage.height+71); }" +
" window.onload = resizewindow; </script></head><body onblur=\"self.close()\" onclick=\"self.close()\"" +
"style=\"margin: 0px; padding: 0px;\"><img src=\"" + imageURL + "\" alt=\"" + caption + "\" name=\"myimage\"></body></html>");
w.document.close ();
if (window.focus) w.focus();
return false;
};

// with the popout menu, all browsers need onfocus event handlers as CSS won't work

init = function() {
  $('#nav ul').addClass('popin');//.hide();
  setTimeout(addEvents,0);
};
// for IE, events need to be added to all .cat links (due to focus not working with no href attribute)
// for IE 6 hover event on the child li's on #nav (IE6 has no hover)
// all browsers need an event fired from the nested ul to set .hover on it's parent li, this
// pops out the list
// for IE this event must also highlight the category link
addEvents = function() {
  var b = $.browser;
  var v = parseInt(b.version);
  // hide all subcats
  if(b.msie) {
    if(v < 7) { // only IE below 7 needs this
      $('#nav > li').hover( function() {
        $(this).addClass('hover');
        return false;
      },
      function() {
        $(this).removeClass('hover');
        return false;
      } );
    }
  }
// this will make the nested UL 'poopout' if a subcat link is focused/hovered etc
  $('#nav a.sub').keyfocus( function() {
    $(this.parentNode.parentNode.parentNode).addClass("hover");
    return false;
  },
  function() {
    $(this.parentNode.parentNode.parentNode).removeClass("hover");
    return false;
  } );
};
jQuery.fn.keyfocus = function(f,g) {
  // A private function for keyboard version of mouse 'hovering'
  function handler(e) {
  //alert("type is "+e.type);
    var p = e.relatedTarget; // Check if mouse(over|out) are still within the same parent element
    var par = this.parentNode;
    while ( p && p != par ) try { p = p.parentNode; } catch(e) { p = this; };// Traverse up the tree
    // If we actually just moused on to a sub-element, ignore it
    if ( p == this ) return false;
    return (e.type == "focus" ? f : g).apply(this, [e]); // Execute the right function
  }
  // Bind the function to the two event listeners
  return this.focus(handler).blur(handler);//.mouseover(handler).mouseout(handler);
};
