initNav = function() {
	var navRoot = document.getElementById("nav");
	var lis = navRoot.getElementsByTagName("li");
	for (var i=0; i<lis.length; i++)
	{
		lis[i].onmouseover = function()
		{
			this.className += " hover";
		}
		lis[i].onmouseout = function()
		{
			this.className = this.className.replace("hover", "");
		}
	}
}
if (document.all && window.attachEvent)
	attachEvent("onload", initNav);
	
	
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')  
  	}
	}
})



var SplashIntro = Class.create({
  initialize: function(){
    
    var splash = $('splash');
    var logo = $('splash_logo');
    var color = $('splash_color');
    var enter = $('splash_enter');
    
    var anim_1 = $('anim_1');
    var anim_2 = $('anim_2');
    var anim_3 = $('anim_3');
    var anim_4 = $('anim_4');
    var anim_5 = $('anim_5');
    var anim_6 = $('anim_6');
    var anim_7 = $('anim_7');
    var anim_8 = $('anim_8');
    
    if(splash){
      
      // color.morph({top: 0, opacity: 1});
      // color.appear();
      // color.grow(20);
      // enter.appear();
      
      anim_1.morph( "left: 0; width: 500px", {duration: 1});
      anim_2.morph( "bottom: 0; height: 600px", {duration: 1.2});
      anim_3.morph( "right: 0; width: 500px", {duration: 1.4});
      anim_4.morph( "top: 0; height: 600px", {duration: 1.6});
      anim_5.morph( "left: 0; width: 500px", {duration: 1.8});
      anim_6.morph( "left: 0; width: 500px", {duration: 3});
      anim_7.morph( "right: 0; width: 500px", {duration: 3});
      // anim_8.morph( "top: 60px; right: 50; width: 300px;", {duration: 2});
      // logo.appear({ queue: 'end' });
      enter.appear({ queue: 'end' });
      splash.morph('background-color: #666');
      // Effect.Queues.global.interval = 2;
      
    }
  }
})


// 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>')
	}

  // Expanding link descriptions
  $$('.expand').each(function(div){
    div.hide()
    div.insert({before:'<a href="#">...</a>'})
    div.previous('a').observe('click', function(e){ 
      div.toggle()
      e.stop()
    })
  })

	new PageTabs('#main-content')
	var splash = new SplashIntro()
  //new AncientBrowserFixes()
})


Effect.BlindLeft = function(element) {
  element = $(element);
  element.makeClipping();
  return new Effect.Scale(element, 0,
    Object.extend({ scaleContent: false,
      scaleY: false,
      scaleMode: 'box',
      scaleContent: false,
      restoreAfterFinish: true,
      afterSetup: function(effect) {
        effect.element.makeClipping().setStyle({
          height: effect.dims[0] + 'px'
        }).show();
      },
      afterFinishInternal: function(effect) {
        effect.element.hide().undoClipping();
      }
    }, arguments[1] || { })
  );
};