var resetTarget;
var resetCheck;
//////////////////////////////////////////////////////////////////////////////////////
/////////////////////Drop Nav Menu Constructor & prototype////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
function dropNav(oTarget){
	this.oTarget = oTarget;
	this.aHeadLinks = new Array();
	this.aDrops = new Array();
	var aLists = oTarget.getElementsByTagName('li');
	for(i=0;i<aLists.length; i++){
		if(aLists[i].id){
			var oDropList = new list(aLists[i]);
				oDropList.oParent = this;
			this.aDrops.push(oDropList);
		}
	}
}
dropNav.prototype.clearDrops = function(){
	for(i=0; i<this.aDrops.length; i++){
		if(this.aDrops[i].oList){
			this.aDrops[i].oTarget.className = '';
			this.aDrops[i].bClicked = false;
			this.aDrops[i].shieldDown();
		}
	}
}
dropNav.prototype.clearHighLights = function(currentSelection){
	for(i=0; i<this.aDrops.length; i++){
		if(this.aDrops[i].oTarget.className != 'navSelected' && this.aDrops[i].oTarget != currentSelection){
			this.aDrops[i].oTarget.className = '';
		}
	}
}
//////////////////////////////////////////////////////////////////////////////////////
///////////////////////List Item Constructor & prototype//////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
function list(oTarget){
	this.oParent;
	this.oTarget = oTarget;
	this.active = false;
	this.bClicked = false;
	this.oLink = this.oTarget.getElementsByTagName('a')[0];
	if(this.oLink.innerHTML.toLowerCase().indexOf('0')>=0){
		this.oLink.innerHTML = 'My mail';
	}
	this.oList = this.oTarget.getElementsByTagName('div')[0];
	if(this.oList){
		this.oLink.className = 'DDMenu';
		this.listLinks = this.oList.getElementsByTagName('li');
		this.setListLinks();
		this.oLink.onclick = this.killLink.bind(this);
		this.oTarget.onclick = this.turnOn.bind(this);
	}else{
		this.oTarget.onclick = this.followLink.bind(this);
	}
	this.oTarget.onmouseover = this.highLight.bind(this);
	this.oTarget.onmouseout = this.clearHighlights.bind(this);
}
list.prototype.killLink = function(){
	//debugger;
	return false;
}
list.prototype.followLink = function(){
	document.location.href= this.oLink.href;	
	return false;
}
list.prototype.turnOn = function(){
	if(this.bClicked){	
		this.oParent.clearDrops();
		this.oParent.clearHighLights();
	}else{
		this.startResetCheck();
		this.oParent.clearDrops();
		this.oTarget.className = 'navSelected';
		this.shieldUp(this.oList.offsetHeight, this.oList.offsetWidth);
		this.bClicked = true;
	}
	return false;
}
list.prototype.highLight = function(){
	this.startResetCheck();
	this.active = true;
	this.oParent.clearHighLights();
	if(this.oTarget.className != 'navSelected'){
		this.oTarget.className = 'highLighted';
	}
}
list.prototype.clearHighlights = function(){
	this.active = false;		
	this.oParent.clearHighLights(this.oTarget);
}
list.prototype.setListLinks = function(){
	for(l=0; l<this.listLinks.length; l++){
		this.listLinks[l].oParent = this;
		this.listLinks[l].shref = this.listLinks[l].getElementsByTagName('a')[0].href;
		this.listLinks[l].onmouseover = function(){
			this.oParent.active = true;
			this.className = "navListSelected";	
		}
		this.listLinks[l].onmouseout = function(){
			this.oParent.active = false;			
			this.className = "";	
		}
		this.listLinks[l].onclick = function(){
			document.location.href= this.shref;	
			return false;
		}
	}
}
list.prototype.shieldUp = function(height, width){
	if(!this.Shield){
		this.Shield = document.createElement('iframe');
		this.oTarget.appendChild(this.Shield);
		this.Shield.style.height = (height) + 'px';
		this.Shield.style.width = width + 'px';
		this.Shield.style.zIndex = -10;
	}
	this.Shield.style.visibility = 'visible';
	this.Shield.style.display = 'block';
}
list.prototype.shieldDown = function(){
	if(this.Shield){
		this.Shield.style.visibility = 'hidden';
		this.Shield.style.display = 'none';
	}
}
list.prototype.startResetCheck = function(){
	resetTarget = this;
	if(resetCheck){
		clearTimeout(resetCheck);
	}
	resetCheck = setTimeout(resetChecker, 1000);
}
function resetChecker(){
	if(!resetTarget.active){		
		resetTarget.oParent.clearDrops();
		resetTarget.oParent.clearHighLights();
	}
}
window.document.onclick = function(){
	if(resetTarget){
		resetChecker();	
	}
}