/*
	eclipse-creative.com 
	20090329 tomc
*/

// hand grx Array
baseHandSrc = '';
var hands = [
	{ src:'../grx/hands2/film.gif' },	
	{ src:'../grx/hands2/image.gif' },
	{ src:'../grx/hands2/audio.gif' },
	{ src:'../grx/hands2/curr.gif' },
	{ src:'../grx/hands2/showcase.gif' },
	{ src:'../grx/hands2/facil.gif' }
];
/* pre load hand grx */
for( var i = 0; i != hands.length; ++i ){
	hands[i].image = new Image();
	hands[i].image.src = hands[i].src
}




var switchHand = function( _i ){
	$('tllHands').src = hands[_i].image.src;
}

var resetHand = function( ){
	$('tllHands').src = baseHandSrc;
}

/*
	ENTRY
*/
window.addEvent('domready',function(){

	baseHandSrc = $('tllHands').src;
	
	subMenus = $$('#topnavarea .m_bDropCont');
	btns = $$('#topnavbtns a');
	
	/*
		config btn objects
	*/
	btns.each( function( el, _i, _v ){
		
		el.sub = subMenus[_i];
		if( el.sub.hasClass('fixed') ) return;		
		
		el.addEvents({
			mouseenter:function(e){	this.sub.requestShow(); },
			mouseleave:function(e){ this.sub.requestHide();	}
		});
		
		/*
			stop click event,
			except for facilities
		*/
		if( el.getProperty('href') != '../facilities/' ){
			el.addClass( 'noclick' );
			el.addEvent( 'click', function(e){ e.stop(); return false; } );
		}
		
		
	});
	
	/*
		config submenu objects
	*/
	subMenus.each( function(sub, _i, _v){
		
		if( sub.hasClass('fixed') ) return;
		
		sub.btn = btns[_i];
		
		sub.status = 'hidden';
		
		sub.hideInt = 0; // timeout interval //
		
		sub.fx = new Fx.Tween(sub,{
			duration:'275',
			transition:Fx.Transitions.Expo.easeOut
		});
		
		sub.requestShow = function(){
			
			$clear(this.hideInt);
			
			/* take over from the current top layer */
			tops = $$('.topLayer');
			tops.each( function(el){ el.fx.cancel(); el.removeClass('topLayer'); } );
			if( tops.length ){
				this.setStyle('top', tops[0].getStyle('top') );
			}
			
			this.addClass('topLayer');
			this.fx.cancel();
			this.fx.start('top','0px');
			
			switchHand(_i);
		};
		
		sub.requestHide = function(){
			
			this.hideInt = function(){
				this.fx.cancel();
				this.fx.start('top','-40px');
			}.delay( 200, this );
			
			resetHand();
			
		};
		
		sub.addEvents({
			mouseenter:function(e){ this.requestShow(); },
			mouseleave:function(e){ this.requestHide(); }
		});
	});
	
	
	
	/*
		GENERIC ROLLOVER
	*/
	$$('a.rollfade').each(function(a){
		var imgs = a.getElements('img');
		
		if( imgs.length == 2 ){
			a.imgs = imgs;
			a.addEvents({
				mouseenter:function(e){ this.imgs[1].fade(0); },
				mouseleave:function(e){ this.imgs[1].fade(1); }
			});
		}
	});
	
});