//  EEmenu Item

function ei(title,url){
	if(title || url){
		this.title 	= title;
		this.url 	= url;
		this.isLink	= true;
	}else{
		this.isLink = false;
		}
	}

// EarthExplorer menu 1.16

function eeMenu(items,pB){
	this.parentButton 		= ge(pB);
	this.img			= this.parentButton.getElementsByTagName('img')[0];
	this.width				= 200;
	this.itemHeight			= 22;
	this.height				= 0;
	this.window				= dce('div');
	this.window.className	= 'ee_menu';
	this.window.id			= pB + '_eeMenu';
	this.visible			= false;
	this.items 				= [];
	this.hTimeout			= 50;
	
	this.picture = this.img.src;
	this.pictureOver = '';
	
	}
	
eeMenu.prototype.addItem = function(title,url){
	this.items.push(new ei(title,url));
	}
	
eeMenu.prototype.initEvents = function(){
		// events routines
	var its = this;
	var w = ge(this.window.id);
	this.parentButton.onclick = function(e){
			var e = e || window.event;
			its.setVisibility();
			e.cancelBubble = true;
			}
	this.parentButton.onmouseover = function(e){
			var e = e || window.event;
			its.show();
			e.cancelBubble = true;
			}
	this.parentButton.onmouseout = function(e){
		its.timer2 = window.setTimeout(function(){its.hide()},its.hTimeout);
		}	
	w.onmouseout = function(e){
		its.timer = window.setTimeout(function(){its.hide();},its.hTimeout);
		}
	w.onmouseover = function(e){
		window.clearTimeout(its.timer);
		window.clearTimeout(its.timer2);
		}
	}
	
eeMenu.prototype.addSplitter = function(){
	this.items.push(new ei());
	}

eeMenu.prototype.init = function(){
	var item = '';
	var innerDIV = dce("div");
	for(i = 0;i < this.items.length;i++){
		if(this.items[i].isLink == true){
			item += '<a href="'+this.items[i].url+'">'+this.items[i].title+'</a>';
			this.height +=this.itemHeight;
		}else{
			item +='<span></span>';
			this.height +=3;
			}
		}
	this.window.style.visibility 	= 'hidden';
	this.window.style.position 		= 'absolute';
	this.window.style.display 		= 'block';
	innerDIV.innerHTML = item;
	
	var w = this.width-2;
	var h = this.height;
	this.window.innerHTML = '<div style="width:'+w+'px'+'; height:'+h+'px'+';">'+item+'</div>';
	var h = this.height+2+'px';

	document.write('<div id="'+this.window.id+'" class="'+this.window.className+'" style="visibility:hidden;position:absolute;display:block;left:0px;top:0px;height:'+h+'">'+this.window.innerHTML+'</div>');

	this.initEvents();
	}	

eeMenu.prototype.setPos = function(){
	var o = getLeftTop(this.parentButton);
	var left = (this._offsetLeft)?this._offsetLeft:0;
	var top = (this._offsetTop)?this._offsetTop:0;
	top = (window.opera)?top-3:top;
	var w = ge(this.window.id);
	w.style.left = o.l+left+'px';
	w.style.top= o.t+o.h+top+'px';
	}

eeMenu.prototype.show = function(){
		var w = ge(this.window.id);
		this.setPos();
		w.style.visibility = 'visible';
		this.visible = true;
		if(this.pictureOver){
			this.img.src = this.pictureOver;
		}
	}
	
eeMenu.prototype.hide = function(){
		var w = ge(this.window.id);
		w.style.visibility = 'hidden';
		this.visible = false;
		window.clearTimeout(this.timer);
		if(this.pictureOver){
			this.img.src = this.picture;
		}
	}

eeMenu.prototype.setVisibility= function(){
		(this.visible==false) ? this.show() : this.hide();
	}
	
// Init attach events

document.onclick = function(){em.hide();}
window.onresize = function(){if(em.visible==true)em.setPos();}
