/*
	20090527 tomc
*//*
	.:: MENU NAV ROLLOVER ::.
*/
window.addEvent('domready',function(){
	/*
		an absolute positioned image
		appears within the li
	*/
	$$('ul.topnav>li').each(function(li,_i,_v){
		
		li.setStyle( 'background-image', 'url('+rootpath+'grx/topmenu-bg-over.gif)' );
		
		var e = new Element('div',{
			styles:{
				position:'absolute',
				top		:0,
				left	:0,
				width	:li.getSize().x + 'px',
				height	:li.getSize().y + 'px',
				background:'url('+rootpath+'grx/topmenu-bg-idle.gif)'
			}
		});
		e.inject( li, 'top' );
		
		/*
			SPECIAL CASE
			first li
		*/
		if( li.hasClass('first') ){
			li.setStyle( 'background-position', '-10px 0px' );
			e.setStyle( 'background-position', '-10px 0px' );
		}
		
		/*
			IF THIS IS THE ACTIVE PAGE
			CHANGE MENU BG
			OR
			CREATE ROLL OVER EVENTS
		*/
		var a = null;
		
		if( li.getElements('a').length
			&&	( a = li.getElements('a')[0] )){
			
			li.bgEl = e;
			li.addEvents({
				mouseenter:function(){ this.bgEl.fade(0); },
				mouseleave:function(){ this.bgEl.fade(1); }
			});
		}
	});
	
	
	/*
		sub menu drop fx
	*/
	$$('ul.topnav .submenu').each(function(sub,_i,_v){
		
		var par = sub.getParent();
		var padder = sub.getElements('.sub_padder')[0];
		var c;
		
		
		if( sub.getElements('ul').length ){
			sub.setStyles({
				visibility:'hidden',
				display:'block'
			});
			
		}else
			return;
		
		c = sub.getCoordinates();
		
		var wrap = new Element( 'div', {
			styles:{
				position:'absolute',
				zIndex:99,
				width:207, height:0,
				top:28, left:-15,
				overflow:'hidden',
				background:'url('+rootpath+'grx/topmenu-sub-shad.png) left bottom'/*,
				border:'1px solid red'*/
			}
		}).inject(sub,'before').adopt(sub);

		// PNG FIX CAUSED PROBLEMS //
		// IF (NOT IE) OR (IE > 6) USE PNG VERSISON //
		if( !( Browser.Engine.trident ) || ( Browser.Engine.trident && Browser.Engine.version > 4 )  ){
			wrap.setStyles({ background:'url('+rootpath+'grx/topmenu-sub-shad.png) left bottom' });
		} else {
			wrap.setStyles({ background:'url('+rootpath+'grx/topmenu-sub-shad.gif) left bottom' });
		}
		
		sub.setStyles({
			visibility:'visible',
			position:'absolute',
			bottom:0
		});
		
		par.addEvents({
			mouseenter:function(e,el,val){
				el.set('tween',{transition:Fx.Transitions.Quint.easeOut, duration:0});
				el.tween('height', val);
			}.create({arguments:[wrap, c.height], event:true}),
			mouseleave:function(e,el,val){
				el.set('tween',{transition:Fx.Transitions.Quint.easeInOut, duration:0});
				el.tween('height', val);
			}.create({arguments:[wrap, 0], event:true})
		});
		
	});
	
	/*
		MAKE FILTER UNCLICKBLE FOR JS ENABLED USERS
	*/
	$$('ul#topnav a.dfilter').removeProperty('href');
	
	
	
	// ------------------------------------------------------------------------ //
	/*
		SIDE NAV
	*/
	$$('ul#sideNav1 > li').each(function( li, _i, _v ){ 
		
		ul = $('sideNav1');
		col1 = ul.getParent();
		
		li.setStyles({background:'transparent'});
		col1.setStyles({overflow:'hidden'});
		
		li.img_idle = new Element( 'img', {
			src:rootpath+'grx/sidenav-li-bgw-idle.gif',
			styles:{
				position:'absolute',
				zIndex:1,
				top:li.getPosition( col1 ).y
			}
		});
		li.img_over = new Element( 'img', {
			src:rootpath+'grx/sidenav-li-bgw-over.gif',
			styles:{
				position:'absolute',
				zIndex:1,
				top:li.getPosition( col1 ).y
			}
		});
		
		li.img_idle.inject(col1, 'top');
		li.img_over.inject(col1, 'top');
		
		li.addEvents({
			mouseenter:function(){
				this.img_idle.fade(0);
				this.addClass('active');
			},
			mouseleave:function(){
				this.img_idle.fade(1);
				this.removeClass('active');
			}
		});
	});
	
	
	/*
		DEST PAGE SLIDER
		on safari 4 slide doesnt work on an element hash
		there each() is used, also had to use $() on the element !?!
	*/
	$$('.drop_slide').each(function(el, _i, _v){
		el.setStyle( 'display', 'block' );
		el.getParent().addEvents({
			//mouseover:function(){ $(this.getElements('.drop_slide')[0]).slide(); },		
			//mouseout:function(){ $(this.getElements('.drop_slide')[0]).slide(); }
		});
		
		//$(el).slide( 'hide' );	
	});
	
	/*
		SCROLL TO TOP
	*/
	$$('a.goto_top').each(function(el){
		el.removeProperty('href');
		el.addEvents({
			click:function(e){
				if(e) e.stop();
				new Fx.SmoothScroll(window).toTop();
				return false;
			}
		});
	});
	
	
	
	/*
		INJECT GOOGLE ANALYTICS
	*//*
		REQUEST ANALYTICS SOURCE
		FROM OUR SERVER
	*/
	var myRequest = new Request({
		url:"get-analytics-src.js",
		onSuccess:function(_r){
			eval( _r );
			try {
				var pageTracker = _gat._getTracker("UA-9892805-1");
				pageTracker._setDomainName("none");
				pageTracker._setAllowLinker(true);
				pageTracker._trackPageview();
			} catch(err) {}	
		}
	}).send();
	
	
	
});
