/*
	created by: Rob Sutherland / FitzMartin
	created: October 2007
	
	requires: prototype
*/

Event.observe(window, 'load', function() {

	//$$('li.h-showul').each( makehoverable );
	equalizeheight($$('div.eq-h'));
	$$('a.ext').each( relativelinks );
	
});

function relativelinks(el)
{
	el.target = '_blank';
}

function makehoverable(el)
{
	var	t = el;
	Event.observe(el, 'mouseover', function() { Element.addClassName(t, 'show-sub'); } );
	Event.observe(el, 'mouseout', function() { Element.removeClassName(t, 'show-sub'); } );
}

function equalizeheight(els)
{
	var h = 0;
	for(var i = 0; i < els.length; i++)
	{
		var h2 = els[i].getHeight();
		if(h2 > h) h = h2;
	}
	
	for(var i = 0; i < els.length; i++)
	{
		els[i].setStyle({height: h+'px'});
	}
}


var RotateElements = function(container) {
	if(!Prototype || !Effect) { alert('Requires prototype and scriptaculous'); return; }
	
	this.container = $(container);
	this.baseOptions = {tag: 'LI', direction: 'up', delay: 3, paused: false};
	this.options = Object.extend(this.baseOptions, arguments[1] || { });		
	this.paused = this.options.paused;
	this.scroller = document.getElementsByClassName('scrolling',this.container)[0];

	this.container.makePositioned();
	this.scroller.makePositioned();	

	this.scroll = function() {
		if(this.paused) return;
		if(!this.scroller) return;
		
		var t = this.scroller.firstChild;
		var t2 = null;
		
		while(t.nodeType == 3)
			t = t.nextSibling;
	

		while(t && t.tagName != this.options.tag)
			t = t.nextSibling;

		if(this.options.tag == 'DT')
		{
			var t2 = t.nextSibling;
			while(t2 && t2.tagName != 'DD')
				t2 = t2.nextSibling;
		}
			
		if(!t) return;
		
		Effect.Fade(t, {afterFinish: function(e) {
			var el = e.element;
			var p = el.parentNode;
			p.appendChild(el);
			Effect.Appear(el);
		}});
		
		if(t2)
		Effect.Fade(t2, {afterFinish: function(e) {
			var el = e.element;
			var p = el.parentNode;
			p.appendChild(el);
			Effect.Appear(el);
		}});
	}	
	
	if(this.scroller.getElementsByTagName(this.options.tag).length > 0)
		this.executer = new PeriodicalExecuter(this.scroll.bind(this), this.options.delay);
}