var easySwapImg = {
	
	ImagesOver : function() {
		var img = document.images, ipt = document.getElementsByTagName('input'), i, preLoadImg = [];
		// img elements
		for (i = 0; i <img.length; i++) {
			if ((img[i].src.match(/.*_n\./))||(img[i].style.filter)){
				preLoadImg[preLoadImg.length] = new Image;
				preLoadImg[preLoadImg.length-1].src = img[i].src.replace('_n.', '_on.');

				img[i].onmouseover = easySwapImg.over;
				img[i].onmouseout  = easySwapImg.out;
				try {img[i].addEventListener('click', easySwapImg.click, false);}
				catch(e){img[i].attachEvent('onclick', (function(el){return function(){easySwapImg.click.call(el);};})(img[i]));}
			}
		}
		// input[image] elements
		for (i = 0; i <ipt.length; i++) {
			if ((ipt[i].src.match(/.*_n\./))&&(ipt[i].getAttribute('type')=='image')){
				preLoadImg[preLoadImg.length] = new Image;
				preLoadImg[preLoadImg.length-1].src = img[i].src.replace('_n.', '_on.');

				ipt[i].onmouseover = easySwapImg.over;
				ipt[i].onmouseout  = easySwapImg.out;
				try {ipt[i].addEventListener('click', easySwapImg.click, false);}
				catch(e){ipt[i].attachEvent('onclick', (function(el){return function(){easySwapImg.click.call(el);};})(ipt[i]));}
			}
		}
	}
	,
	
	over : function() {
		var imgSrc, preLoadImgSrc;
		if((this.style.filter)&&(this.style.filter.match(/_n\.png/)))//(IE5.5-6 && png)
			this.style.filter = this.style.filter.replace('_n.png', '_on.png');
		else
			this.src = this.src.replace('_n.', '_on.');
	},

	out : function(){
		if((this.style.filter)&&(this.style.filter.match(/_on\.png/)))//(IE5.5-6 && png)
			this.style.filter = this.style.filter.replace('_on.png', '_n.png');
		else
			this.src = this.src.replace('_on.', '_n.');
	},
	
	click : function(){
		if((this.style.filter)&&(this.style.filter.match(/_on\.png/)))//(IE5.5-6 && png)
			this.style.filter = this.style.filter.replace('_on.png', '_n.png');
		else
			this.src = this.src.replace('_on.', '_n.');
	},

	addEvent : function(){
		try {
			window.addEventListener('load', this.ImagesOver, false);
		} catch (e) {
			window.attachEvent('onload', this.ImagesOver);
		}
	}
}

easySwapImg.addEvent();

var TimeOut         = 300;
var currentLayer    = null;
var currentitem     = null;
var currentLayerNum = 0;
var noClose         = 0;
var closeTimer      = null;

function mopen(n) {
  var l  = document.getElementById("menu"+n);
  var mm = document.getElementById("mmenu"+n);
	
  if(l) {
    mcancelclosetime();
    l.style.visibility='visible';
    if(currentLayer && (currentLayerNum != n))
      currentLayer.style.visibility='hidden';
    currentLayer = l;
    currentitem = mm;
    currentLayerNum = n;			
  } else if(currentLayer) {
    currentLayer.style.visibility='hidden';
    currentLayerNum = 0;
    currentitem = null;
    currentLayer = null;
 	}
}

function mclosetime() {
  closeTimer = window.setTimeout(mclose, TimeOut);
}

function mcancelclosetime() {
  if(closeTimer) {
    window.clearTimeout(closeTimer);
    closeTimer = null;
  }
}

function mclose() {
  if(currentLayer && noClose!=1)   {
    currentLayer.style.visibility='hidden';
    currentLayerNum = 0;
    currentLayer = null;
    currentitem = null;
  } else {
    noClose = 0;
  }
  currentLayer = null;
  currentitem = null;
}

document.onclick = mclose; 


