/* Global variables */
var scrollerStarted = false;


/* A function to display a menu item
*
* @param key int
* @param size int
*/
function displayMenuItem(key, size){
	//Hide the other menu items
	for (var i = 0; i < size; i++){
		//($('menuChildren_' +i).style.display != "none" || 
		if (i != key && $('parent_' +i).className == "menuParentSelected"){
			$('parent_' +i).className = "menuParent";
			$('parent_' +i).getElementsByTagName("img")[0].src = $('parent_' +key).getElementsByTagName("img")[0].src.replace(/list_arrow_down.png/, "list_arrow.png");
			if ($('parent_' +i).parentNode.getElementsByTagName("div").length > 1){
				new Effect.SlideUp('menuChildren_' +i, { duration: 0.4, queue: 'end' });
			}
		}
	}
	
	//Display the menu item
	if ($('menuChildren_' +key).style.display == "none"){
		$('parent_' +key).className = "menuParentSelected";
		$('parent_' +key).getElementsByTagName("img")[0].src = $('parent_' +key).getElementsByTagName("img")[0].src.replace(/list_arrow.png/, "list_arrow_down.png");
		new Effect.SlideDown('menuChildren_' +key, { duration: 0.6, queue: 'end' });
	}
}

/* A function when hovering over a menu item */
function hoverMenuItem(element){
	if (element.className == 'menuParent'){
		element.className = 'menuParentHover'
	}
	else if (element.className == 'menuParentHover'){
		element.className = 'menuParent'
	}		
	else if (element.className == 'menuChild'){
		element.className = 'menuChildHover'
	}		
	else if (element.className == 'menuChildHover'){
		element.className = 'menuChild'
	}		
	else if (element.className == 'lastMenuChild'){
		element.className = 'lastMenuChildHover'
	}		
	else if (element.className == 'lastMenuChildHover'){
		element.className = 'lastMenuChild'
	}		
}


/* Check if an e-mail address is valid or not */
function checkEmail(email){
	//^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$
	return /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/.test(email);
}


/* Update the description block of the scroller on the homepage */
function updateScrollerDescription(description, url, quote){
	
	if(document.getElementById("advertisement").getElementsByTagName("img").length == 0){
		document.getElementById("advertisement").style.display = "none";
		document.getElementById("advertisement").innerHTML = "";		
		
		var a = document.createElement("a");
		a.href = url;
		a.innerHTML = quote;
		document.getElementById("advertisement").appendChild(a);
		document.getElementById('advertisement_overlay').onclick = function(){window.location = url}
		
		if("undefined" != typeof $ && scrollerStarted) {
			$('advertisement').appear({ duration: 0.6 });
		}
		else {
			document.getElementById("advertisement").style.display = "";
		}
	}
	
	document.getElementById("scroller_description").style.display = "none";
	document.getElementById("scroller_description").innerHTML = "";
	
	var a = document.createElement("a");
	a.href = url;
	a.innerHTML = description;
	document.getElementById("scroller_description").appendChild(a);
	document.getElementById('scroller_overlay').onclick = function(){window.location = url}
	
	if("undefined" != typeof $ && scrollerStarted) {
		$('scroller_description').appear({ duration: 0.6 });
	}
	else {
		document.getElementById("scroller_description").style.display = "";
		scrollerStarted = true;
	}
}


/* display a FAQ item's children */
function displayFaqAnswer(id){	
	//Show
	if (document.getElementById("faq_answer_" +id).style.display == "none"){
		document.getElementById("faq_answer_" +id).style.display = "block";
	}
	
	//Hide
	else {
		document.getElementById("faq_answer_" +id).style.display = "none";
	}
}

/* Display some images in lightbox */
function GroupDelegate(id) {
	var objLink = document.getElementById(id);
	Lightbox.prototype.start(objLink);
}
