// Moo dropdown extension. Copyright © 2006 Blix Interactive. www.blixinteractive.com

var hDropDown = new Class({
						  
	setOptions: function(options){
		this.options = {
			timeOut: 250
		}
		Object.extend(this.options, options || {});
	},
	
	initialize: function(elements, containers, options){
		this.elements = elements;
		this.containers = containers;
		this.setOptions(options);
		this.elopen = null;
		
		$A(elements).each(function(el){
			var element = el.getPrevious();
			
			if(element.getTag()=="a")
			{		
				this.getitems(el);
				
				Object.extend(element, { hasevent: true });
				
				element.onmouseover = function(){
    				this.show(el, element);
					return false;
				}.bind(this);
										
				element.onmouseout = function(){
    				this.hide();
				}.bind(this);
			}
		}, this);
		
		$A(containers).each(function(eh){
			$A(eh.getElements('a')).each(function(e){
				if(!e.hasevent)
				{
					e.onmouseover = function(){
						this.timer = $clear(this.timer);
						if(e.getParent().getProperty('class')!='singleLink') e.setStyle('background-position', '0 -24px');
						if(this.elopen!=null) 
						{
							this.elopen.setStyle('display', 'none');
							this.eldown.setStyle('background-position', '0 0');
						}
						this.elopen=null;
						return false;
					}.bind(this);
					
					e.onmouseout = function(){
						if(e.getParent().getProperty('class')!='singleLink') e.setStyle('background-position', '0 0');
					}.bind(this);
				}
			}, this);
		}, this);
		
	},
	
	getitems: function(el){
		$A(el.getElements('a')).each(function(e){
			
			Object.extend(e, { hasevent: true });
			
			e.onmouseover = function(){
				this.timer = $clear(this.timer);
				return false;
			}.bind(this);
												
			e.onmouseout = function(){
    			this.hide();
			}.bind(this);

		},this);
	},

	show: function(el, element){
		this.timer = $clear(this.timer);
		if(this.elopen!=null) 
		{	
			this.elopen.setStyle('display', 'none');
			this.eldown.setStyle('background-position', '0 0');
		}
		this.elopen = el;
		el.setStyle('display', 'block');
		
		if(element.getParent().getProperty('class')!='lsme') 
			element.setStyle('background-position', '0 -24px');
		else
			element.setStyle('background-position', '-70px -24px');			
			
		this.eldown = element;
	},

	hide: function(){
		this.timer = $clear(this.timer);
		this.timer = this.close.delay(this.options.timeOut, this);
	},

	close: function(){
		this.elopen.setStyle('display', 'none');
		//this.eldown.setStyle('background-position', '0 0');
		
		if(this.eldown.getParent().getProperty('class')!='lsme') 
			this.eldown.setStyle('background-position', '0 0');
		else
			this.eldown.setStyle('background-position', '-70px 0');
			
		this.elopen=null;
	}
	
});


/*	
Script: LinkTips
*/
var LinkTips = new Class({

	initialize: function(elements){
		this.toolOpen = null;
		this.elements = elements;
		this.toolTip = new Element('div').addClass('linktip').setStyle('position', 'absolute');
		this.toolTip.injectInside(document.body);
		this.toolTip.setOpacity(.8);
		this.toolTip.setStyle('z-index', '3200');
		this.toolTip.setStyle('display', 'none');
		this.toolTitle = new Element('a').injectInside(this.toolTip);
		this.toolTitle.onmouseover = function(){
			this.active();
			return false;
		}.bind(this);
		this.toolTitle.onmouseout = function(){
			this.timer = $clear(this.timer);
			this.disappear(this.toolOpen);
		}.bind(this);
			
		this.toolText = new Element('a').injectInside(this.toolTip);
		this.toolText.onmouseover = function(){
			this.active();
			return false;
		}.bind(this);	
		this.toolText.onmouseout = function(){
			this.timer = $clear(this.timer);
			this.disappear(this.toolOpen);
		}.bind(this);	
		
		$A(elements).each(function(el){
			el.myTitle = "Philadelphia";
			el.myText = "New York";
			if(el.id == "popSign")
			{
				el.myTitleA = "/training/coaching/packages/philadelphia/"
				el.myTextA = "/training/coaching/packages/nyc/"
			}
			else if(el.id == "popCal")
			{
				el.myTitleA = "/training/schedule/cal_pa/"
				el.myTextA = "/training/schedule/cal_nyc/"
			}						
			
			el.onmouseover = function(){
				this.locatestart(el);
				this.show(el);
				return false;
			}.bind(this);
			el.onmouseout = function(){
				this.timer = $clear(this.timer);
				this.disappear(el);
			}.bind(this);
		}, this);
	},

	show: function(el){
		this.timer = $clear(this.timer);
		if(this.toolOpen!=null)
		{
			this.toolOpen.setStyle('background-color', '#000');
		}
		this.toolOpen = el;
		this.toolTitle.innerHTML = el.myTitle;
		this.toolTitle.href = el.myTitleA;
		this.toolText.innerHTML = el.myText;
		this.toolText.href = el.myTextA;
		el.setStyle('background-color', '#444');
		this.toolTip.setStyle('display', 'block');
	},
	
	active: function(el){
		this.timer = $clear(this.timer);		
	},

	locatestart: function(el){
		var doc = document.documentElement;
		this.toolTip.setStyles({'top': el.getTop() + doc.scrollTop + 14 + 'px', 'left': el.getLeft() + doc.scrollLeft + 'px'});
	},

	disappear: function(el){
		this.timer = $clear(this.timer);
		this.timer = this.close.delay(350, this);
	},

	close: function(){
		this.toolOpen.setStyle('background-color', '#000');
		this.toolTip.setStyle('display', 'none');
		this.toolOpen = null;
	}	

});