﻿var tabs = new Array();

function showImage(imagePath,text){
	var img = document.getElementById("image_show");
	var container = document.getElementById("image_container");
	
	if(container.style.display = 'none')
		container.style.display = 'block';
	document.getElementById("image_text").innerHTML = "<br/><img src='img/loading.gif'/><br/>";
	img.src = imagePath;
	img.onload = (function(){
		if(text!=undefined)
			document.getElementById("image_text").innerHTML = "<br/>"+text+"<br/>";
		else
			document.getElementById("image_text").innerHTML = "";
		window.scroll(0,200);
	});
}

function closeImage(){
	document.getElementById("image_container").style.display = 'none';
	window.scroll(0,0);
}

function addCredits(){
	var dest = document.getElementById("credits");
	dest.innerHTML = ("Allegra Ravizza Art Project<br/>Web Credits: <a href='http://www.byderman.it' target='_blank'>Nowave Internet Things Corporation</a> 2008 - 2009<br/>" +
			"Best resolution 1024x768 or higher<br/>"+
			"Tested on Internet Explorer 7.0, Safari 3.1.2, Firefox 3.0.4, Opera 9.20</span>");	
}

function addMenu(currentPage, language, alternativeVersionPage){
	var menu = document.getElementById("main_menu");
	var img = document.getElementById("menu_img");
	var menuElementsTags = new Array();
	var menuElements = new Array();
	var menuElementsLinks = new Array();
	var alternativeVersionLink;
	
	if(language=="ita"){
		menuElementsTags.push("home");
		menuElementsTags.push("news");
		menuElementsTags.push("artisti");
		menuElementsTags.push("onshow");
		menuElementsTags.push("upcoming");
		menuElementsTags.push("downloads");
		menuElementsTags.push("fotografie");
		menuElementsTags.push("contatti");

		menuElements.push("home");
		menuElements.push("news");
		menuElements.push("artisti");
		menuElements.push("on show");
		menuElements.push("upcoming show");
		menuElements.push("downloads");
		menuElements.push("fotografie");
		menuElements.push("contatti");
	
		menuElementsLinks.push("index.html");
		menuElementsLinks.push("news.html");
		menuElementsLinks.push("artisti.html");
		menuElementsLinks.push("onshow.html");
		menuElementsLinks.push("#");
		menuElementsLinks.push("downloads.html");
		menuElementsLinks.push("foto.html");
		menuElementsLinks.push("contatti.html");
		
		if(alternativeVersionPage=="#")
			alternativeVersionLink= "<a href='#'>english version</a>";
		else
			alternativeVersionLink= "<a href='en/" + alternativeVersionPage + "'>english version</a>";
	}else{
		menuElementsTags.push("home");
		menuElementsTags.push("news");
		menuElementsTags.push("artists");
		menuElementsTags.push("onshow");
		menuElementsTags.push("upcoming");
		menuElementsTags.push("downloads");
		menuElementsTags.push("photos");
		menuElementsTags.push("contacts");

		menuElements.push("home");
		menuElements.push("news");
		menuElements.push("artists");
		menuElements.push("on show");
		menuElements.push("upcoming show");
		menuElements.push("downloads");
		menuElements.push("photos");
		menuElements.push("contacts");
	
		menuElementsLinks.push("index.html");
		menuElementsLinks.push("news.html");
		menuElementsLinks.push("artists.html");
		menuElementsLinks.push("../onshow.html");
		menuElementsLinks.push("#");
		menuElementsLinks.push("downloads.html");
		menuElementsLinks.push("photos.html");
		menuElementsLinks.push("contacts.html");
		
		if(alternativeVersionPage=="#")
			alternativeVersionLink= "<a href='#'>versione italiana</a>";
		else
			alternativeVersionLink= "<a href='../" + alternativeVersionPage + ">versione italiana";
	}
	
	if(alternativeVersionPage=="#")
		alternativeVersionLink= "<a href='#'>versione italiana";
	
	for(i=0;i<menuElementsTags.length;i++){
		if(menuElementsTags[i]!=currentPage)
			menu.innerHTML = menu.innerHTML + ("<a href='" + menuElementsLinks[i] + "' class='menu_item'>" + menuElements[i] + "</a> &nbsp;");
	}
	menu.innerHTML = menu.innerHTML + ("<span style='float:right;margin-right:20px;'>" + alternativeVersionLink + "</span>");
	
	img.src="img/heads/" + currentPage + ".jpg";
}

function findChild(component, childIdentifier){
	if(typeof(component) == "string") component = doc(component);
	var i;
	var res;
	var len = component.childNodes.length;

	for(i=0; i<len; i++){
		if(checkIdentifier(component.childNodes[i], childIdentifier)){
			res = component.childNodes[i];
			break;
		}
		else if(component.childNodes[i].childNodes)
			if(res = findChild(component.childNodes[i], childIdentifier)) break;
	}
	
	return res;
}

function findParent(component, parentIdentifier){
	if(typeof(component) == "string") component = doc(component);	
	
	if(component.parentNode)
		if(checkIdentifier(component.parentNode, parentIdentifier)) return component.parentNode;
		else return findParent(component.parentNode, parentIdentifier);
	else
	
	return null;
}

function checkIdentifier(component, identifier){
	switch(identifier[0]){
		case ".":{
			if(component.className==clean(identifier)) return true;
			return false;			
		}
		case "#":{
			if(component.id==clean(identifier)) return true;
			return false;			
		}
		case "_":{
			if(component.tagName==clean(identifier)) return true;
			return false;			
		}
		default:{
			if(component.id==identifier || component.className==identifier) return true;
			return false;
		}
	}
	
	function clean(ident){
		var cleanId = "";
		var j;
		for(j=1; j<ident.length; j++)
			cleanId+=ident[j];
		return cleanId;
	}
}
