var tempX = 0;
var IE = document.all?true:false
/*
function captureMousePosition(e) {
  if (IE) {
    tempX = event.clientX + document.body.scrollLeft;
  } else {
    tempX = e.pageX;
  }
}
*/
var Menu = new function() {
	this.isInit = false;
	this.images = [];
	this.layers = [];
	this.activeItem = null;
	this.activeAnimation = null;
	this.timeoutID = -1;
	this.items = [
		{
		items : [
			{
			href : 'gallery.php?galKat=tattoo&nr=1',
			alt : 'Galeria Kolor',
			target : '_self'
			},
			{
			href : 'gallery.php?galKat=tattoo&nr=2',
			alt : 'Galeria B&W',
			target : '_self'
			}
		],
		x : 110,
		y : 212
		}
	];
	this.preloadImage = function(src) {
		var idx = this.images.length;
		this.images[idx] = new Image();
		this.images[idx].src = src;
	}
	this.swapArrow = function(i,j,src) {
		if(is.nn4) this.layers[i][j].elm.document.images['arrow'+i+'_'+j].src = src;
		else document.images['arrow'+i+'_'+j].src = src;
	}
	this.generate = function(m) {
		this.clearAutoHide();
		if(!this.isInit || m == this.activeItem) return;
		var tempY = 109;
		var tempX = this.items[m].x;
		this.hideActiveItem();
		this.activeItem = m;
		this.activeAnimation = new animatorObj();
		if(this.layers[m] && this.layers[m].length > 0) {
			var i;
			for(i = 0; i < this.layers[m].length; i++) {
				this.activeAnimation.addAnimation(this.layers[m][i],tempX,tempY,tempX,tempY + this.header.height + i*25,this.layers[m].length*2,10,1);
				this.layers[m][i].moveTo(tempX,tempY);
				this.layers[m][i].show();
			}
			this.activeAnimation.addAnimation(this.footer,tempX,tempY,tempX,tempY + 25*i + this.header.height,this.layers[m].length*2,10,1);
			this.header.moveTo(tempX,tempY);
			this.header.show();
			this.footer.moveTo(tempX,tempY);
			this.footer.show();
			this.activeAnimation.start();
		}
	}
	this.hideActiveItem = function() {
		if(!this.isInit) return;
		this.header.hide();
		this.footer.hide();
		if(this.layers[this.activeItem] && this.layers[this.activeItem].length > 0) {
			if(this.activeAnimation) this.activeAnimation.stop();
			for(var i = 0; i < this.layers[this.activeItem].length; i++) this.layers[this.activeItem][i].hide();
		}
		this.clearAutoHide();
		this.activeItem = null;
	}
	this.setAutoHide = function() {
		if(!this.isInit) return;
		if(this.timeoutID != -1) clearTimeout(this.timeoutID);
		this.timeoutID = setTimeout('Menu.hideActiveItem()',500);
	}
	this.clearAutoHide = function() {
		if(!this.isInit) return;
		if(this.timeoutID != -1) clearTimeout(this.timeoutID);
		this.timeoutID = -1;
	}
	this.init = function() {
		status = 'Generowanie menu...';
		var tempLayer = new layerObj('menuPositionDiv');
		for(var i = 0; i < this.items.length; i++) for(var j = 0; j < this.items[i].items.length; j++) {
			if(!this.layers[i]) this.layers[i] = [];
			var html = '<table width=213 border=0 cellspacing=0 cellpadding=0 bgcolor="#1F1F1F" height=25><tr>';
			html += '<td width=20><img src="img/pic01.gif" width=20 height=11></td>';
			html += '<td width=188><a href="'+this.items[i].items[j].href+'" target="' + this.items[i].items[j].target + '" onfocus="blur()"><font color="#BFBFBF">'+this.items[i].items[j].alt+'</font></a></td>';
			html += '<td width=5 bgcolor="#333333"><img src="img/menu_bg.gif" width=1 height=1></td>';
			html += '</tr>';
			html += '<tr><td colspan="3"><img src="img/menu_line.gif" width="213" height="7" alt=""></td></tr></table>';
			this.layers[i][j] = new layerObj(tempLayer,0,0,false,j,213,25,html);
			this.layers[i][j].elm.onmouseover = function() { Menu.clearAutoHide() }
			this.layers[i][j].elm.onmouseout = function() { Menu.setAutoHide() }
		}
		this.header = new layerObj(tempLayer,0,0,false,0,213,23,'<img src=img/menu_top.gif alt= width=213 height=23 border=0>');
		this.footer = new layerObj(tempLayer,0,0,false,0,213,23,'<img src=img/menu_bottom.gif width=213 height=23 border=0>');
		status = '';
		this.isInit = true;
	}
}
