window.addEvent("domready", function(){
	parseExternalLinks();

	
	foldAllNavigation();
	var bodyClass = document.body.className
	bodyClass = bodyClass.split(" ");
	var currentSection = bodyClass[0];
	var sections = new Hash();
	sections['webLaw'] = ['webLaw' , 'antispamLaw' , 'accessibilityLaw' , 'lopd' , 'intellectualProperty'];
	sections['webPages'] = ['webPages', "internetPresence", "dynamicContents", "eCommerce"];
	sections['services'] = ['services', 'xhtmlcss', 'webProgramming', 'consulting', 'seo', 'process'];
	sections['tools'] = ['tools', 'onLineEdit', 'pdf2pagefliper', 'crawler'];
	
	sections.each(function(section, index){
		if(section.indexOf(currentSection) != -1)
			expandNavigation(index);
	})
});
// Parses all external links in document adding onclick = open.window
parseExternalLinks = function()
{
	var url = document.location.protocol+"//"+document.location.host;
	$$("a[href]").each(function(a){ 
		if (!a.href.match(new RegExp("^"+url))) a.addEvent("click", 
			function(e) {e.stop();  window.open(this.href); }); });
}

expandNavigation = function(currentSection) 
{
	if($type(currentSection) == "element")
	{
		var ul = currentSection;
		ul.unFold();
	}
	else
	{
		var ul = $$("#mainNavigation li."+currentSection+" ul")[0];
		ul.visible();
	}	
	if(window.current && window.current != ul)
	{
		window.current.fold();
		//window.current.getPrevious("h2").setStyle("background", "url(css/images/closedArrow.gif) 0 10px no-repeat");
	}
	//ul.getPrevious("h2").setStyle("background", "url(css/images/openArrow.gif) 0 15px no-repeat");
	window.current = ul;
}





foldAllNavigation = function()
{
	$$("#mainNavigation li ul").hidden();
	if(!Browser.Engine.trident)
	{	
		$$("#mainNavigation li ul").each(function(ul){
			var h2 = ul.getPrevious("h2");
			h2.addEvent("mouseenter", function(e){
				expandNavigation(ul);
			})
		})
	}	
	$$("#mainNavigation li h2").each(function(el){
		//el.setStyle("background", "url(css/images/closedArrow.gif) 0 14px no-repeat");
	});
}