YE.onDOMReady(function()
{
	dropDownMenus('mainMenu');
	menuHighlighter('customerMenu');
});

function dropDownMenus(id)
{
	var menu = YD.getFirstChild(id);
	
	if(!menu) {
		return;	
	}
	
	var i, ul, list = [], temp = menu.getElementsByTagName('li');
	
	for(i = 0; i < temp.length; i++) {
		ul = temp[i].getElementsByTagName('ul')[0];
		if(ul) {
			list.push(temp[i]);	
		}
	}

	YE.addListener(list, 'mouseover', function() 
	{
		ul = this.getElementsByTagName('ul')[0];
		if(ul) {
			YD.setStyle(ul, 'display', 'block');
		}
	});
	
	YE.addListener(list, 'mouseout', function() 
	{
		ul = this.getElementsByTagName('ul')[0];
		if(ul) {
			YD.setStyle(ul, 'display', 'none');
		}
	});
};

function menuHighlighter(id)
{
	var menu = YD.getFirstChild(id);
	
	if(!menu) {
		return;	
	}
	
	var host = 'http://' + document.location.host.toLowerCase();
	var pathname = document.location.href.replace(host, '').toLowerCase().split('#').shift();
	var menu = document.getElementById(id);
	var items = menu.getElementsByTagName('li');
	var a = '';

	for(var i = 0; i < items.length; i++)
	{
		a = items[i].getElementsByTagName('a')[0].href.toLowerCase().replace(host, '').split('#').shift();

		if(pathname == '/' && a == '/') {
			items[i].className += ' active';
			break;
		}
		else if(pathname != '/' && a == '/') {
			continue;	
		}
		else if(pathname.indexOf(a) > -1) {
			items[i].className += ' active';
		}
	}
};

function tabs()
{
	YE.onDOMReady(function()
	{
		var hash = window.location.hash.split('?')[0];
		var active = Sizzle(hash);
		
		if(active.length > 0) {
			var activeLink = Sizzle('.tabsMenu a[href='+ hash+']')[0];
			var onshow = YD.getAttribute(activeLink, 'onshow');
			
			YD.setStyle(active, 'display', 'block');
			YD.addClass(activeLink.parentNode, 'active');
			window.scrollTo(1,1);
			
			if(onshow != null) {
				eval(onshow);
			}
		}
		
		YE.addListener(Sizzle('.tabsMenu a'), 'click', function(e)
		{
			window.location.hash = this.href.split('#').pop();
			
			YE.preventDefault(e);
			YD.setStyle(Sizzle('.tabsContent'), 'display', 'none');
			YD.setStyle(Sizzle('#' + this.href.split('#').pop()), 'display', 'block');
			YD.removeClass(Sizzle('.tabsMenu li'), 'active');
			YD.addClass(this.parentNode, 'active');
			
			var onshow = YD.getAttribute(this, 'onshow');

			if(onshow != null) {
				eval(onshow);
			}
		});
	});
};

