$(document).ready(function(){
	
	initMainMenu();
	initServices();
	ie6Fixes();			
	
	function initMainMenu(){	
		$('#mainMenu a').hover(function(){
			$(this).parent().children('.dropdown').stop().slideDown(400).show(400, function(){
				$(this).height('auto');
			});
		});
		
		$('#mainMenu li').hover(function(){
			if ( $(this).find('.dropdown').length > 0 ){
		}},function(){
			$(this).find('.dropdown').slideUp(400);
		});
	}
	
	function initServices(){
		
		$('.expand').click(function(){
			$(this).toggleClass('selected');
			$(this).parent().children('ul').slideToggle(400);
			return false;	
		});
		
		$('.toggle').click(function(){
			$('#overlay').show();
			$(this).parent().children('.popup').stop().animate({ bottom : 12 + 'px' }, 300).show();
			$('.inner ul').children('li').css('z-index', '1');
			$(this).parent().css('z-index', '9900');
			$('.toggle').removeClass('selected');
			$(this).addClass('selected');
			return false;
		});
		
		$('.expand').parent().children().children().children('.toggle').click(function(){
			$(this).parent().children('.popup').stop().animate({ bottom : 12 + 'px' }, 300).show();
			$('.inner li ul').children('li').css('z-index', '1');
			$(this).parent().parent().parent().css('z-index', '9900');
			$('.toggle').removeClass('selected');
			$(this).addClass('selected');
			$('#overlay').show();
			return false;	
		});
		
		$('.close').click(function(){
			$('.toggle').removeClass('selected');
			$('#overlay').hide();
			$('.popup').stop().animate({ bottom : 0 }, 0).hide();
			return false;	
		});

	}
	
	function ie6Fixes(){
		if ($.browser.msie && $.browser.version == 6){
			$('#products-box .products-list li:first-child, #services .box:first-child').addClass('first-child');
			$('#overlay').height($('html body').height() + 8);
		}
	}
	
});

function addEvent(obj, evType, fn){ 
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, true); 
		return true; 
	}else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	}else{ 
		return false; 
	} 
}

function hideFocusBorders(){
var theahrefs = document.getElementsByTagName("a");
	if (!theahrefs){return;}
		for(var x=0;x!=theahrefs.length;x++){
		theahrefs[x].onfocus = function stopLinkFocus(){this.hideFocus=true;};
	}
}

addEvent(window, 'load', hideFocusBorders);
