//	Copyright © Coretomic, 2005

var MENU_STYLE_DROP_RIGHT = 1;
var MENU_STYLE_DROP_LEFT = 2;
var MENU_STYLE_DROP_DOWN = 3;

Menu.prototype.addItem = m_addItem;
Menu.prototype.restoreItem = m_restoreItem;
Menu.prototype.mouseOver = m_mouseOver;
Menu.prototype.mouseOut = m_mouseOut;
Menu.prototype.hideNow = m_hideNow;
Menu.prototype.hideAll = m_hideAll;
Menu.prototype.menuLeft = m_menuLeft;
Menu.prototype.menuTop = m_menuTop;
Menu.prototype.hideElements = m_hideElements;
Menu.prototype.showElements = m_showElements;

function Menu(name) {
	this.name = name;
	this.container_id = new Array();
	this.items = new Array();
	this.elements = new Array();
	this.count = -1;
	this.timer = 0;
	this.dom = (document.getElementById) ? (true) : (false);
	this.ie = (document.all) ? (true) : (false);
	this.ie4 = this.ie && !this.dom;
	this.nn4 = (document.layers) ? (true) : (false);
	this.nn6 = (navigator.userAgent.indexOf("Gecko") != -1);
	this.visible = 'block';	//(nn4) ? ('show') : ('visible');
	this.hidden = 'none';	//(nn4) ? ('hide') : ('hidden');
	this.invert_style = false;
	this.invert_style_id = 0;
}

function getElementById(id) {
	var element;
	if (!id) return;
	if (this.dom) element = document.getElementById(id);
	else if (this.ie4) element = document.all[id];
	else if (this.nn4) element = document.layers[id];

	return element;
}

function getElementByIdFromParent(id, parent) {
	var element = null;

	if (parent) {
		for (var i = 0; i < parent.childNodes.length; i++) {
			var child = parent.childNodes.item(i);

			if (child.id) {
				if (child.id == id) {
					element = child;
					break;
				}
			}

			child = getElementByIdFromParent(id, child);

			if (child) {
				if (child.id) {
					if (child.id == id) {
						element = child;
						break;
					}
				}
			}
		}
	}

	return element;
}

function m_addItem(id, containerId, className, iconId, iconSrc, imageId, imageSrc, backgroundId, backgroundSrc) {
	this.items[this.items.length] = new Array(id, containerId, className, iconId, iconSrc, imageId, imageSrc, backgroundId, backgroundSrc);
}

function m_restoreItem(i) {
	var element = getElementById(this.items[i][0]);
	element.className = this.items[i][2];

	if (this.items[i][4] != '') {
		var icon = getElementById(this.items[i][3]);
		if (icon) {
			icon.src = this.items[i][4];
		}
	}
	if (this.items[i][6] != '') {
		var image = getElementById(this.items[i][5]);
		if (image) {
			image.src = this.items[i][6];
		}
	}
	if (this.items[i][8] != '') {
		var background = getElementById(this.items[i][7]);
		if (background) {
			background.style.backgroundImage = 'url(' + this.items[i][8] + ')';
		}
	}
}

function m_mouseOver(id, a, containerId, offset_x, offset_y, style, parent_position) {
	if (!style) {
		// Set default style.
		style = MENU_STYLE_DROP_RIGHT;
	}
	if (this.invert_style) {
		// Invert menu drop style.
		if ((style & MENU_STYLE_DROP_LEFT) == MENU_STYLE_DROP_LEFT) {
			style &= ~MENU_STYLE_DROP_LEFT;
			style |= MENU_STYLE_DROP_RIGHT;
		}
		if ((style & MENU_STYLE_DROP_RIGHT) == MENU_STYLE_DROP_RIGHT) {
			style &= ~MENU_STYLE_DROP_RIGHT;
			style |= MENU_STYLE_DROP_LEFT;
		}
	}

	if (this.timer) {
		clearTimeout(this.timer);
		this.timer = 0;
	}

	// Close containers till current or till container to open.
	while (this.count > -1) {
		if ((this.container_id[this.count] == id) || (this.container_id[this.count] == containerId)) {
			break;
		}
		this.hideNow(this.container_id[this.count]);
		this.count--;
	}

	// Restore class names and images for all items in same container.
	for (var i = 0; i < this.items.length; i++) {
		if (this.items[i][1] == id || this.items[i][1] == containerId) {
			this.restoreItem(i);
		}
	}

	// Show SELECTs.
	this.showElements("SELECT");

	// Open new popup.
	var open = getElementById(id);
	if (!open) return;
	var open_style;
	if (!this.nn4) open_style = open.style;

	if (a) {
		var left = this.menuLeft(id, a);
		var top = this.menuTop(id, a);
		if (containerId == "") {
			left += offset_x;
			top += offset_y;
		}
		else {
			var container = getElementById(containerId);
			if (container) {
				if ((style & MENU_STYLE_DROP_RIGHT) == MENU_STYLE_DROP_RIGHT) {
					left += container.offsetWidth;
				}
				if ((style & MENU_STYLE_DROP_LEFT) == MENU_STYLE_DROP_LEFT) {
					left -= container.offsetWidth;
				}
				if ((style & MENU_STYLE_DROP_DOWN) == MENU_STYLE_DROP_DOWN) {
					top += container.offsetHeight;
				}
			}
		}
		if (!parent_position) open_style.left = left + "px";
		open_style.top = top + "px";
	}
	open_style.display = this.visible;

	// Correct menu position.
	if ((left + open.offsetWidth) > (document.documentElement.scrollLeft + document.documentElement.clientWidth)) {
		left = (document.documentElement.scrollLeft + document.documentElement.clientWidth - open.offsetWidth);
		if (!parent_position) open_style.left = left + "px";

		// Invert menu style.
		this.invert_style = true;
		this.invert_style_id = id;
	}
	if ((top + open.offsetHeight) > (document.documentElement.scrollTop + document.documentElement.clientHeight)) {
		top = (document.documentElement.scrollTop + document.documentElement.clientHeight - open.offsetHeight);
		open_style.top = top + "px";
	}

	if (this.container_id[this.count] != id) {
		this.count++;
		this.container_id[this.count] = id;
	}

	// Hide SELECTs.
	this.hideElements("SELECT");
}

function m_mouseOut() {
	this.timer = setTimeout(this.name + '.hideAll()', 200);
}

function m_hideNow(id) {
	var hide = getElementById(id);
	if (!hide) return;
	if (!this.nn4) hide = hide.style;

	hide.display = this.hidden;

	if (this.invert_style) {
		if (id == this.invert_style_id) {
			this.invert_style = false;
		}
	}
}

function m_hideAll() {
	while (this.count > -1) {
		this.hideNow(this.container_id[this.count]);
		this.count--;
	}
	this.timer = 0;

	// Restore all class names and images.
	for (var i = 0; i < this.items.length; i++) {
		this.restoreItem(i);
	}

	// Show SELECTs.
	this.showElements("SELECT");
}

function m_menuLeft(id, a) {
	if (this.nn4) return document.layers['x' + id].pageX;
	else {
		var pos = a.offsetLeft;
		while (a.offsetParent != null) {
			a = a.offsetParent;
			pos += a.offsetLeft;
			if (a.tagName == 'BODY') break;
		}
		return pos;
	}
}

function m_menuTop(id,a) {
	if (this.nn4) return document.layers['x' + id].pageY;
	else {
		var pos = a.offsetTop;
		while (a.offsetParent != null) {
			a = a.offsetParent;
			pos += a.offsetTop;
			if (a.tagName == 'BODY') break;
		}
		return pos;
	}
}

function m_hideElements(tagName) {
	if (this.nn6) return;
	// For all opened DIVs.
	for (var j = 0; j <= this.count; j++) {
		var elDiv = getElementById(this.container_id[j]);

		var divLeft = elDiv.offsetLeft;
		var divRight = divLeft + elDiv.offsetWidth;
		var divTop = elDiv.offsetTop;
		var divBottom = divTop + elDiv.offsetHeight;

		// For all specified elements.
		var els = document.all.tags(tagName);
		for (var i = 0; i < els.length; i++) {
			var el = els.item(i);
			var elParent = el;

			var left = 0;
			var top = 0;
			var width = elParent.offsetWidth;
			var height = elParent.offsetHeight;
			while (elParent) {
				left += elParent.offsetLeft;
				top += elParent.offsetTop;
				elParent = elParent.offsetParent;
			}

			if ((left < divRight) && (left + width > divLeft) && (top < divBottom) && (top + height > divTop)) {
				// Hide element.
				el.style.visibility = (nn4) ? ('hide') : ('hidden');

				// Find and store hidden element.
				var found = false;
				var free_index = this.elements.length;
				for (var k = 0; k < this.elements.length; k++) {
					if (this.elements[k] == 0) {
						free_index = k;
					}
					if (this.elements[k] == el) {
						found = true;
						break;
					}
				}
				if (!found) {
					this.elements[free_index] = el;
				}
			}
		}
	}
}

function m_showElements(tagName) {
	if (this.nn6) return;
	// For all hidden elements.
	for (var i = 0; i < this.elements.length; i++) {
		var el = this.elements[i];
		if (el) {
			var elParent = el;

			var left = 0;
			var top = 0;
			var width = elParent.offsetWidth;
			var height = elParent.offsetHeight;
			while (elParent) {
				left += elParent.offsetLeft;
				top += elParent.offsetTop;
				elParent = elParent.offsetParent;
			}

			var show = true;
			// For all opened DIVs.
			for (var j = 0; j <= this.count; j++) {
				var elDiv = getElementById(this.container_id[j]);

				var divLeft = elDiv.offsetLeft;
				var divRight = divLeft + elDiv.offsetWidth;
				var divTop = elDiv.offsetTop;
				var divBottom = divTop + elDiv.offsetHeight;

				if ((left < divRight) && (left + width > divLeft) && (top < divBottom) && (top + height > divTop)) {
					show = false;
				}
			}
			if (show) {
				// Show element.
				el.style.visibility = (nn4) ? ('show') : ('visible');

				// Find and remove hidden element.
				for (var k = 0; k < this.elements.length; k++) {
					if (this.elements[k] == el) {
						this.elements[k] = 0;
						break;
					}
				}
			}
		}
	}
}




tabManager = function()
{
	this.activeTab = false;
	this.tabs = [];
	
	this.setTab = function(tabID, inactiveImage, activeImage, overImage)
	{
		var _this = this;
		this.tabs[tabID] = [
			new imageLoader(inactiveImage, function(width, height)
				{
					_this.getTab(tabID).width = _this.getTab(tabID).style.width = width;
					_this.getTab(tabID).height = _this.getTab(tabID).style.height = height;
				}
			), 
			new imageLoader(activeImage, null), 
			new imageLoader(overImage, null)
		];
		
		if(!this.activeTab)
			this.activeTab = tabID;
		
		with(this.getTab(tabID))
		{
			style.backgroundImage = "url('"+(this.activeTab == tabID ? activeImage : inactiveImage)+"')";
			style.backgroundPosition = "left top";
			style.backgroundRepeat = "no-repeat";
			style.textAlign = "center";
			style.verticalAlign = "middle";
			style.cursor = "pointer";
			onmouseover = this.overTab(tabID);
			onmouseout = this.outTab(tabID);
			onclick = this.selectTab(tabID);
			
			if(this.activeTab == tabID)
				this.getText(tabID).style.display = "block";
		}
	}
	
	this.overTab = function(tabID)
	{
		var _this = this;
		return function()
		{
			_this.getTab(tabID).style.backgroundImage = "url('"+_this.tabs[tabID][2].src+"')";
		}
	}
	
	this.outTab = function(tabID)
	{
		var _this = this;
		return function()
		{
			_this.getTab(tabID).style.backgroundImage = "url('"+_this.tabs[tabID][_this.activeTab == tabID ? 1 : 0].src+"')";
		}
	}
	
	this.selectTab = function(tabID)
	{
		var _this = this;
		return function()
		{
			if(_this.activeTab)
			{
				_this.getTab(_this.activeTab).style.backgroundImage = "url('"+_this.tabs[_this.activeTab][0].src+"')";
				_this.getText(_this.activeTab).style.display = "none";
			}
			_this.getTab(tabID).style.backgroundImage = "url('"+_this.tabs[tabID][1].src+"')";
			_this.getText(tabID).style.display = "block";
			_this.activeTab = tabID;
		}
	}
	
	this.getTab = function(tabID)
	{
		return document.getElementById("tabbedmenu_tab"+tabID);
	}
	
	this.getText = function(tabID)
	{
		return document.getElementById("tabbedmenu_text"+tabID);
	}
}




imageLoader = function(src, callback)
{
	this.width = 0;
	this.height = 0;
	this.loaded = false;
	this.src = src;
	
	var _this = this;
	this.img = new Image();
	this.img.onload = function()
	{
		_this.width = this.width;
		_this.height = this.height;
		if(callback)
			callback(this.width, this.height);
	}
	this.img.src = src;
}




function ImgMenu(name, parent_id, width, offset)
{
	this.item_width = arguments.length > 4 && arguments[4] ? arguments[4] : 50;//default value, pixels
	this.title_position = arguments.length > 5 ? arguments[5] : false;//false - top; true - bottom
	this.nav_width = arguments.length > 6 ? arguments[6] : 15;//default value, pixels
	this.pointer_img = arguments.length > 7 && arguments[7] ? arguments[6] : "/images/dlb-08.gif";//default value
	this.nav_left_img = arguments.length > 8 && arguments[8] ? arguments[8] : "/images/aux-10-left.gif";//default value
	this.nav_right_img = arguments.length > 9 && arguments[9] ? arguments[9] : "/images/aux-10-right.gif";//default value
	
	if(!width)
	{
		width = document.getElementById(parent_id).parentNode.clientWidth;
		if(!width)
			width = document.body.clientWidth;
	}
	if(offset)
		width -= offset;
	
	this.name = name;
	this.width = width;
	this.client_width = this.width - 2 * this.nav_width;
	this.over_now = false;
	this.items_count = 0;
	this.current_index = "";
	this.selected_index = "";
	this.prev_title = "";
	this.images = [];
	this.tags = [];
	this.position = 0;
	this.scroll_busy = false;
	
	this.parent_id = parent_id;
	this.parent_obj = document.getElementById(parent_id);
	this.parent_obj.className = "image-menu";
	this.parent_obj.style.width = this.width+"px";
	this.tempNode = null;
	
	var nav = document.createElement('div');
	nav.className = "nav";
	nav.style.width = this.nav_width+"px";
	this.nav_lbutton = document.createElement('input');
	this.nav_lbutton.setAttribute("type", "image");
	this.nav_lbutton.setAttribute("src", this.nav_left_img);
	this.nav_lbutton.style.visibility = "hidden";
	nav.appendChild(this.nav_lbutton);
	this.parent_obj.appendChild(nav);
	
	var cont = document.createElement('div');
	cont.className = "menu-container";
	cont.style.width = this.client_width+"px";
	this.owner = document.createElement('div');
	this.owner.className = "show-menu";
	cont.appendChild(this.owner);
	this.parent_obj.appendChild(cont);
	
	var nav = document.createElement('div');
	nav.className = "nav";
	nav.style.width = this.nav_width+"px";
	this.nav_rbutton = document.createElement('input');
	this.nav_rbutton.setAttribute("type", "image");
	this.nav_rbutton.setAttribute("src", this.nav_right_img);
	this.nav_rbutton.style.visibility = "hidden";
	nav.appendChild(this.nav_rbutton);
	this.parent_obj.appendChild(nav);
	
	this.addItem = function(url, title, inactivename, activename, overname)
	{
		var is_active = arguments.length > 5 ? arguments[5] : false;
		var in_new_window = arguments.length > 6 ? arguments[6] : false;
		var popup_mode = arguments.length > 7 ? arguments[7] : false;
		var popup_width = arguments.length > 8 ? arguments[8] : false;
		var popup_height = arguments.length > 9 ? arguments[9] : false;
		if(!inactivename)
			inactivename = activename;
		
		var imgcont = document.createElement('div');
		imgcont.className = "menu-item";
		imgcont.style.width = this.item_width+"px";
		
		if(!this.title_position)
		{
			this.appendTitle(imgcont, title, is_active);
			this.appendPointer(imgcont, is_active);
		}
		
		var anhor = document.createElement('a');
		anhor.setAttribute("href", url);
		if(in_new_window)
		{
			if(popup_mode)
				anhor.onclick = this.doPopup(url, popup_width, popup_height);
			else
				anhor.setAttribute("target", "_blank");
		}
		
		var img = document.createElement('img');
		img.className = "item";
		img.setAttribute("src", is_active ? activename : inactivename);
		img.setAttribute("id", this.getImageId(this.parent_id + "_" + this.items_count));
		this.images[this.items_count] = [inactivename, activename, overname];
		
		img.onmouseover = this.onOver(this.name, img);
		
		anhor.appendChild(img);
		imgcont.appendChild(anhor);
		
		if(this.title_position)
		{
			this.appendPointer(imgcont, is_active);
			this.appendTitle(imgcont, title, is_active);
		}
		
		imgcont.onmouseout = this.onOut(this.name, img);
		this.owner.appendChild(imgcont);
		
		if(is_active)
			this.current_index = this.selected_index = this.parent_id + "_" + this.items_count;
		
		if(is.ie)
			this.setTitleOffsetDelayed(this.items_count, 0);
		else
			this.setTitleOffset(this.tags[this.items_count][0], this.tags[this.items_count][1]);
		
		this.prev_title = title;
		this.items_count++;
		
		this.init();
		if(this.items_count * this.item_width > this.client_width)
		{
			this.nav_lbutton.style.visibility = "visible";
			this.nav_rbutton.style.visibility = "visible";
		}
	}
	
	this.appendTitle = function(parent, title, is_active)
	{
		var ttl = document.createElement('div');
		ttl.className = "title";
		ttl.setAttribute("id", this.getTitleContId(this.parent_id + "_" + this.items_count));
		
		var ttl_txt = document.createElement('span');
		ttl_txt.className = is_active ? "enable" : "disable";
		ttl_txt.style.visibility = is_active ? "visible" : "hidden";
		ttl_txt.setAttribute("id", this.getTitleId(this.parent_id + "_" + this.items_count));
		ttl_txt.appendChild(document.createTextNode(title));
		ttl.appendChild(ttl_txt);
		
		parent.appendChild(ttl);
		
		this.tags[this.items_count] = [ttl, ttl_txt];
		
		return true
	}
	
	this.appendPointer = function(parent, is_active)
	{
		var img = document.createElement('img');
		img.className = "pointer";
		img.setAttribute("src", this.pointer_img);
		img.setAttribute("id", this.getPointerId(this.parent_id + "_" + this.items_count));
		img.style.visibility = is_active ? "visible" : "hidden";
		
		parent.appendChild(img);
		
		return true
	}
	
	this.init = function()
	{
		if(typeof(this.has_init) == "undefined")
		{
			this.nav_lbutton.onclick = this.onNavLeftClick(this.name, this.nav_lbutton);
			this.nav_rbutton.onclick = this.onNavRightClick(this.name, this.nav_rbutton);
			
			this.page_size = Math.floor(this.client_width / this.item_width);
			this.max_position = 0;
			
			setTimeout(this.name+".run()", 1000);
			
			this.has_init = true;
		}
		
		this.min_position = this.client_width - this.items_count * this.item_width;
	}
	
	this.run = function()
	{
		if(this.current_index)
		{	
			if(this.isItemVisible(this.current_index))
				this.setOverflow(this.current_index, true);
			else
				this.scrollToItem(this.current_index);
		}
	}
	
	this.setTitleOffsetDelayed = function(item_index, counter)
	{
		var width = this.tags[item_index][1].offsetWidth;
		counter++;
		if(width || counter > 60)
			this.setTitleOffset(this.tags[item_index][0], this.tags[item_index][1]);
		else
			setTimeout(this.name+".setTitleOffsetDelayed(" + item_index + ", " + counter + ")", 1000);
	}
	
	this.setTitleOffset = function(obj, text_obj)
	{
		var title_width = text_obj.offsetWidth;
		
		if(title_width > this.item_width)
		{
			obj.style.textAlign = "left";
			obj.style.marginLeft = this.calcTitleOffset("center", title_width)+"px";
		}
	}
	
	this.calcTitleOffset = function(align, title_width)
	{
		switch(align)
		{
			case "left":
				return 0;
			case "center":
				return Math.round(-(title_width-this.item_width)/2);
			case "right":
				return Math.round(this.item_width - title_width);
		}
		
		return 0;
	}
	
	this.resetState = function()
	{
		if(!this.over_now)
		{
			this.setActive(this.current_index, true);
		}
	}
	
	this.setActive = function(active_index, is_reset)
	{
		if(this.selected_index)
		{
			if(!this.scroll_busy && this.isItemVisible(this.selected_index))
				this.setOverflow(this.selected_index, false);
			document.getElementById(this.getTitleId(this.selected_index)).className = "disable";
			document.getElementById(this.getTitleId(this.selected_index)).style.visibility = "hidden";
			document.getElementById(this.getPointerId(this.selected_index)).style.visibility = "hidden";
			var new_src = this.images[this.extractIndex(this.selected_index)][this.selected_index == this.current_index ? 1 : 0];
			if(new_src)
				document.getElementById(this.getImageId(this.selected_index)).setAttribute("src", new_src);
		}
		
		if(active_index)
		{
			if(!this.scroll_busy && this.isItemVisible(active_index))
				this.setOverflow(active_index, true);
			document.getElementById(this.getTitleId(active_index)).className = "enable";
			if(this.isItemVisible(active_index))
			{
				document.getElementById(this.getTitleId(active_index)).style.visibility = "visible";
				document.getElementById(this.getPointerId(active_index)).style.visibility = "visible";
			}
			var new_src = this.images[this.extractIndex(active_index)][is_reset ? 1: 2];
			if(new_src)
				document.getElementById(this.getImageId(active_index)).setAttribute("src", new_src);
			this.selected_index = active_index;
		}
	}
	
	this.setOverflow = function(index, state)
	{
		var onScroll = arguments.length > 2 && arguments[2] ? arguments[2] : false;
		
		if(is.ie)
		{
			var sourceNode = document.getElementById(this.getTitleId(index)).parentNode;
			sourceNode.style.position = state ? "relative" : "static";
		}
		else if(this.isItemVisible(index))
		{
			if(this.tempNode)
			{
				this.parent_obj.removeChild(this.tempNode);
				this.tempNode = null;
			}
			
			var sourceNode = document.getElementById(this.getTitleId(index));
			sourceNode.style.position = "relative";
			
			if(state)
			{
				this.tempNode = document.createElement("div");
				this.tempNode.className = "title";
				this.tempNode.style.position = "absolute";
				this.tempNode.style.whiteSpace = "nowrap";
				this.tempNode.style.left = sourceNode.offsetLeft+"px";
				this.tempNode.style.top = sourceNode.offsetTop+"px";
				var txt_node = document.createElement("span");
				txt_node.textContent = sourceNode.textContent;
				this.tempNode.appendChild(txt_node);
				this.parent_obj.appendChild(this.tempNode);
				
				sourceNode.style.visibility = "hidden";
			}
			else if(onScroll && index == this.current_index)
			{
				sourceNode.style.visibility = "visible";
			}
		}
	}
	
	this.setVisible = function(index, visible)
	{
		document.getElementById(this.getTitleId(index)).style.visibility = visible ? "visible" : "hidden";
	}
	
	this.scrollToItem = function(full_id)
	{
		var new_position = Math.floor(0.5 * (this.client_width - this.item_width)) - this.extractIndex(full_id) * this.item_width;
		this.scrollTo(new_position);
	}
	
	this.scrollPage = function(dir)
	{
		var pages_count = arguments.length > 1 ? arguments[1] : 1;
		
		var new_position = this.position + pages_count * this.item_width * this.page_size * (dir ? -1 : 1);
		this.scrollTo(new_position);
	}
	
	this.scrollTo = function(position)
	{
		var firstTime = arguments.length > 1 ? arguments[1] : true;
		
		if(firstTime)
		{
			if(this.scroll_busy)
				return false;
			
			this.scroll_busy = true;
			position = this.checkPosition(position);
			if(this.current_index)
			{
				if(this.isItemVisible(this.current_index))
					this.setOverflow(this.current_index, false, true);
				else
					this.setVisible(this.current_index, true);
			}
		}
		
		if(this.position == position)
		{
			this.scroll_busy = false;
			if(this.current_index)
			{
				if(this.isItemVisible(this.current_index))
					this.setOverflow(this.current_index, true);
				else
					this.setVisible(this.current_index, false);
			}
		}
		else
		{
			var step = Math.max(2, Math.round(0.1 * Math.abs(this.position - position)));
			this.owner.style.marginLeft = this.position + "px";
			this.position = this.checkPosition(this.position > position ? Math.max(this.position - step, position) : Math.min(this.position + step, position), this.position > position ? 1 : 2);
			setTimeout(this.name+".scrollTo("+position+", false)", 40);
		}
		
		return true;
	}
	
	this.checkPosition = function(position)
	{
		var mode = arguments.length > 1 ? arguments[1] : 0;
		
		if(!mode || mode == 1)
			position = Math.max(this.min_position, position)
		if(!mode || mode == 2)
			position = Math.min(this.max_position, position);
		
		return position;
	}
	
	this.doPopup = function(url, popup_width, popup_height)
	{
		return function()
		{
			window.open(url, "", (popup_width ? "width="+popup_width : "")+(popup_height ? ",height="+popup_height : ""));
			return false;
		}
	}
	
	this.onOver = function(menu, obj)
	{
		return function()
		{
			var _this = eval(menu);
			_this.over_now = true;
			_this.setActive(_this.extractId(obj.id), false);
		};
	}
	
	this.onOut = function(menu, obj)
	{
		return function()
		{
			var _this = eval(menu);
			_this.over_now = false;
			setTimeout(menu+".resetState()", 300);
		};
	}
	
	this.onNavLeftClick = function(menu, obj)
	{
		return function()
		{
			obj.blur();
			var _this = eval(menu);
			return _this.scrollPage(false);
		}
	}
	
	this.onNavRightClick = function(menu, obj)
	{
		return function()
		{
			obj.blur();
			var _this = eval(menu);
			return _this.scrollPage(true);
		}
	}
	
	this.isItemVisible = function(full_id)
	{
		var abs_pos = this.item_width * this.extractIndex(full_id);
		var rel_pos = abs_pos + this.position;
		return rel_pos >= 0 && rel_pos < this.client_width;
	}
	
	this.getTitleId = function(id)
	{
		return "img_menu_title__" + id;
	}
	
	this.getTitleContId = function(id)
	{
		return "img_menu_title_cont__" + id;
	}
	
	this.getImageId = function(id)
	{
		return "img_menu_item__" + id;
	}
	
	this.getPointerId = function(id)
	{
		return "img_menu_pointer__" + id;
	}
	
	this.extractId = function(full_id)
	{
		return full_id.substr(2+full_id.lastIndexOf("__"));
	}
	
	this.extractIndex = function(full_id)
	{
		return parseInt(full_id.substr(1+full_id.lastIndexOf("_")));
	}
}
