/*LightBox.Add({	
	LinkId: 'TEST',  
	LightBoxId: 'LightBoxTest'		
});*/

var MGHTools={	
	init: function(){
		this.rollOver();
		if( $E('.tN') ){
			this.setLiHover();
		}				
		if( $E('.tabNav') ){
			this.tabNavigation();
		}			
		if( $E('.toTop') ){
			this.pageScroll();
		}			
		if ( $E('.toolTip') ) {
			this.toolTips();
		}				
	},	
	setLiHover: function(){
		$$('.tN').addEvents({				
			'mouseenter': function(){				
				this.addClass('hover');									
			},				
			'mouseleave': function(){					
				this.removeClass('hover');	
			}							
		});		
	},		
	rollOver: function(){
		$$('.rollOver').addEvents({
			'mouseenter': function(){
				var srcName = this.getProperty('src');
				var xSrc = srcName.substring(0, srcName.indexOf('.gif'));					
				var newSrc = xSrc + '_over.gif';
				this.setProperty('src', newSrc);
			},
			'mouseleave': function(){
				var srcName = this.getProperty('src');				
				var newSrc = srcName.replace(/_over/i, "");					
				this.setProperty('src', newSrc);
			}							
		});
	},		
	tabNavigation: function(){
		var allTabs = $$('.tabNav li');
		var infoDivs = $$('.tabInfo');					
		var currTab = $E('.tabNav .active');
		var currHref = currTab.getElement('a').getProperty('href');
		var tabIndex = currHref.substring(currHref.indexOf('tab')+ 3) -1 ;	
		var currTabContent = infoDivs[tabIndex];	
		// hide all divs EXCEPT the one specified in tabIndex - displayed by default.
		infoDivs.each(function(div){
			if(div != currTabContent){					
				div.hide();
			}
		});		
		allTabs.each(function(ele){				
			ele.addEvent('click', function(evt){
				new Event(evt).stop();
				if(currTab != this) {
					currTab.removeClass('active');
				}
				var href = this.getElement('a').getProperty('href');
				var divID = href.substring(href.indexOf('#')+1);	
				
				if(currTabContent != $(divID)) {
					currTabContent.hide();
				}					
				this.addClass('active');
				$(divID).show();	
				currTab = this;
				currTabContent = $(divID);
			});
		});					
	},		
	pageScroll: function(){
		var scroll = new Fx.Scroll(window, {
			duration: 1000,
			transition: Fx.Transitions.Quad.easeInOut
		});
		$$('.toTop').each(function(el){				
			el.addEvent('click', function(event){
				event = new Event(event).stop();
				scroll.toTop();
			});
		});
	},
	toolTips: function(){
		var tipArrow = new Element('div', {			
			'class': 'tipArrow'			
		});				
		var myTips = new Tips($$('.toolTip'), {
        maxTitleChars: 50,
		offsets: {'x': -27, 'y': -30},
		fixed: true,
    	initialize:function(){
		this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 200, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
			var tipBox = $E('.tool-tip');
			if(tipBox){
				tipArrow.inject(tipBox);
			}
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
		});				
	}				
}

Element.extend({
	show : function() {
		//this.setStyle("display","");
		this.removeClass('hidden');
	},					
	hide : function() {
		//this.setStyle("display","none");
		this.addClass('hidden');
	},
	isHidden: function() {
		//return( this.getStyle('display') == 'none' );
		return this.hasClass('hidden');
	}
});			

window.onDomReady(function() {
	MGHTools.init();
});