/*
	20100902	tomc
	eclipse-creative.com
	
	common layout features
	
*/
/*
	ENTRY
*/
window.addEvent("domready",function(){
	//
	// MENU 1 (site-map)
	//
	var menuEl = document.getElement(".head ul.site-map");
	if( menuEl ){
		menuEl.getElements(".menu-item").each(function(li,i,ul){
			//
			//	SHOW SUB MENU
			//
			li.getElements("ul.sub-menu").setStyles({display:"block"}).fade("hide");
			li.addEvents({
				mouseenter:function(){
					li.getElements("ul.sub-menu").fade(1);
				},
				mouseleave:function(){
					menuEl.getElements(".menu-item ul.sub-menu").fade(0);
				}
			});
			// IE7 problem with inline element //
			li.getChildren("a").addEvents({
				mouseout:function(e){
					new Event(e).stop();
					return false;
				}
			});
		},this);
	}
	
	//
	// MENU 2 (site overview)
	//
	$$(".head .site-overview>li").each(function(li){
		var subMenu = li.getElement("ul.sub-menu");
		if( subMenu ){
			subMenu.fade("hide");
			li.addEvents({
				mouseenter:function(){
					subMenu.fade(1);
				},
				mouseleave:function(){
					subMenu.fade(0);
				}
			});
		}
	});

	//
	//	A TAG ROLLOVERS
	//
	$$(".view-more").addEvents({
		mouseenter:function(){
			this.morph({
				"background-color"	:["#003d51","#3f6d7c"],
				"border-color"		:["#406e7d","#2d5a69"]				
			});
		},
		mouseleave:function(){
			this.morph({
				"background-color"	:["#3f6d7c","#003d51"],
				"border-color"		:["#2d5a69","#406e7d"]
			});
		}
	});
	
	//
	//	CLEAR THE VALUE IN EMAIL FIELD
	//
	var input = document.getElement("#join-list input.text[name=email]");
	if(input){
		input.hasCleared = false;
		input.addEvents({click:function(){
			if(!input.hasCleared){
				this.setProperty("value","");
				input.hasCleared = true;
			}
		}});
	}
	
	
	//
	//	CLONE PART OF NAVIGATION INTO COL2
	//
	var col2 = document.getElement("#intro-content .col2.enquiry-col");
	if( col2 ){
		$$("ul .active-url").each(function(a, index, menuLinks){
			var el = a;
			while( el.getParent("li") ){
				el = el.getParent("li");
			}
			var newUl = new Element("ul", {
				"class"		:"nav-copy",
				"html"		:el.getProperty('title') ? ('<li class="heading-2"><h3>'+el.getProperty('title')+'</h3></li>') : ''		
			}).inject(col2,"top");
			
			el.clone().inject(newUl);
			
			newUl.getElement("ul").fade("show");
		});
	}
});

