var smplnavmenu_coll = {
	collection : new Array(),
	active : -1,
	add : function (smplnavmenu)
	{
		smplnavmenu.id = this.collection.length;
		this.collection[this.collection.length] = smplnavmenu;
		return smplnavmenu;
	}
};

var smplnavmenu = Class.create();

smplnavmenu.prototype = 
{
	raiser : false,
	submenu : false,
	timeout : 1,
	id : -1,
	timer : false,
	just_open : false,
	top_offset : 0,
	left_offset : 0,
	initialize : function (_raiser, _submenu, _timeout)
	{
		this.raiser = $(_raiser);
		this.submenu = $(_submenu);
		this.timeout = $(_timeout);
		if (null != this.raiser && null != this.submenu)
		{
			Event.observe(this.raiser, 'mouseover', this.over.bindAsEventListener(this));
			Event.observe(this.raiser, 'mouseout', this.out.bindAsEventListener(this));
			Event.observe(this.submenu, 'mouseover', this.over.bindAsEventListener(this));
			Event.observe(this.submenu, 'mouseout', this.out.bindAsEventListener(this));
		}
	},
	setoffset : function (left, top)
	{
		this.left_offset = left;
		this.top_offset = top;
	},
	hide : function()
	{
		if (null != this.submenu)
			this.submenu.hide();
		if (false != this.timer)
		{
			window.clearTimeout(this.timer);
			this.timer = false;
		}
	},
	show : function ()
	{
		if (null != this.submenu && !this.submenu.visible())
		{
			var pos = Position.cumulativeOffset(this.raiser);
			
			this.submenu.style.left = pos.left + this.left_offset;
			this.submenu.style.top = pos.top + this.raiser.getHeight() + this.top_offset;
			this.submenu.show();
			smplnavmenu_coll.active = this.id;
		}
	},
	timer_hide : function()
	{
		this.timer = window.setTimeout(this.hide.bind(this), this.timeout * 1000);
	},
	over : function (e)
	{
		if (smplnavmenu_coll.active != this.id && smplnavmenu_coll.active != -1)
		{
			smplnavmenu_coll.collection[smplnavmenu_coll.active].hide();
			this.just_open = true;
		}
		this.show();
		if (this.timer)
		{
			window.clearTimeout(this.timer);
			this.timer = false;
		}
	},
	out : function (e)
	{
		//if (this.just_open)
		//	this.just_open = false;
		//else
			this.timer_hide();
	}
}

var more_photo = {
	show : function (e)
	{
		var data = $A(arguments);		
		var listner = $(data[1]);		
		var photo = $(data[2]);
		var left = $(data[3]);
		var top = $(data[4]);
		photo.style.left = Position.cumulativeOffset(listner).left + left;
		photo.style.top = Position.cumulativeOffset(listner).top + top;
		photo.show();
	},
	hide : function (e)
	{
		var data = $A(arguments);
		var listner = $(data[1]);
		var photo = $(data[2]);
		photo.hide();
	},
	register : function(listner, photo, left, top)
	{
		$(photo).hide();
		Event.observe($(listner), 'click', more_photo.show.bindAsEventListener(more_photo, listner, photo, left, top));
		Event.observe($(photo), 'click', more_photo.hide.bindAsEventListener(more_photo, listner, photo));
	}
}


function ex_mp_register(listner, photo, relative)
{
	var pos = Position.cumulativeOffset($(relative));
	var p_pos = Position.cumulativeOffset($(listner));
	more_photo.register(listner, photo, pos.left - p_pos.left, pos.top - p_pos.top);

}