// Menu ----->

var selected = false;
var selectedSub = false;

function selectMenu(id) { // Menu
	if (selected != id) {
		if (selected) {
			unselectMenu(selected);
		}
		Element.show(id + '-sub');
		selected = id;
	}
	else {
		unselectMenu(id);
	}
}

function unselectMenu(id) {
	Element.hide(id + '-sub');
	selected = false;
}

function selectSubMenu(id) { // Sub Menu
	if (selectedSub != id) {
		if (selectedSub) {
			unselectSubMenu(selectedSub);
		}
		Element.show(id + '-sub');
		selectedSub = id;
	}
	else {
		unselectSubMenu(id);
	}
}

function unselectSubMenu(id) {
	Element.hide(id + '-sub');
	selectedSub = false;
}



// Show & Hide Scroller ----->

var selectedText = false;

function selectText(id) { // Menu
	if (selectedText != id) {
		if (selectedText) {
			unselectText(selectedText);
		}
		Element.show(id);
		selectedText = id;
		loadScroller(id);
	}
	else {
		unselectText(id);
	}
}

function unselectText(id) {
	Element.hide(id);
	selected = false;
}

function loadScroller(id) {
	var idstr = id.replace(/-text/,"")
	var objheight = Element.getHeight(idstr + '-scroll-content');
	var wrapheight = Element.getHeight(idstr + '-scroll-content-wrapper');
	if (objheight > wrapheight)
		Element.show(idstr + '-scroll-content-scroller') // Show scroller
}



// Scroller ----->

function scroller(id,direction) {
	var speed = 4; // Set speed in pixels
	var wrap = $(id + '-scroll-content-wrapper'); // Content wrapper
	var wrapheight = Element.getHeight(wrap);
	var obj = $(id + '-scroll-content'); // Content to scroll
	var objheight = Element.getHeight(obj);
	if (direction == "down") {
		if (parseInt(obj.style.top) >= (wrapheight - objheight))
		obj.style.top = parseInt(obj.style.top) - speed + "px";
	}
	else if (direction == "up") {
		if (parseInt(obj.style.top) <= 0)
		obj.style.top = parseInt(obj.style.top) + speed + "px";
		if(parseInt(obj.style.top) > 0) obj.style.top = 0 + "px";
	}
	timerID = setTimeout("scroller('" + id + "','" + direction + "')",20)
}

function scrollerStop(id) {
	clearTimeout(timerID);
	timerID = null;
}



// Tours Popup ----->

function popUp(url) {
	newWindow = window.open(url,'tour','scrollbars=no,resizable=yes,width=800,height=600');
	newWindow.focus();
}