// Hover Behaviour for Nav etc.
var HoverBehavior = Class.create({
  initialize: function() {
    $A(document.styleSheets).each( function(stylesheet) {
      $A(stylesheet.rules).each( function(rule) {
        if( rule.selectorText.match(/:hover/i) ) {
          stylesheet.addRule( rule.selectorText.replace(/:hover/ig, '.hover'), rule.style.cssText )
        }
      })
    })

    $A(arguments).each( function(arg) {
      $$(arg).each( function(tag) {
        Event.observe(tag, 'mouseenter', function() { Element.addClassName(tag, 'hover'); }, true)
        Event.observe(tag, 'mouseleave', function() { Element.removeClassName(tag, 'hover'); }, true)
      })
    })
  }
})

var AncientBrowserFixes = Class.create({		
	initialize: function(){
    
    // IE6/7 is being ridiculous and needs these corners "touched" to make them visible
    $$('#masthead .corner').invoke('setStyle',{zoom:1})    
      	
  	if (Prototype.Browser.IE) {
  		try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}
  		new HoverBehavior('#nav li')  
  	}
	}
})


// Global DOM onload
document.observe("dom:loaded",function(){

	// Mark if we're in surf-to-edit
	if (location.href.match(/nterchange/g)) { 
	  $$('body').first().addClassName('nterchange') 
	  $$('body').first().insert('<div id="nterchange"></div>')
	}
	
	new PageTabs('#main')
  new AncientBrowserFixes()
})

