// JavaScript Document

function menu()
{
	this.nodes=new Array();
	
	this.setHovImageReplaceString=function setReplStr(search_str,replace_str)
	{
		this.search_str=search_str;
		this.replace_str=replace_str;
		this.replaceObj=new RegExp(search_str);
	}
	
	this.build=function build(container_id)
	{
		topmenu=document.getElementById(container_id).getElementsByTagName("a");
		for (var i = 0; i < topmenu.length; i++) {
  			this.add(topmenu[i]);
		}
	}
	
	this.add_single=function add_single(node_id,search_str,replace_str)
	{
		node=document.getElementById(node_id);
			
		node.image=node;
		node.image_src=node.image.src;
		replaceObj=new RegExp(search_str)
		node.image_hov_src=node.image_src.replace(replaceObj,replace_str);
		
		node.preload=new Image();
		node.preload.src=node.image_hov_src;
		
		node.onmouseover=this.hover;
		node.onmouseout=this.dehov;
		node.selected=false;
	}
	
	this.select=function select(id)
	{
		node=this.nodes[id];
		node.image.src=node.image_hov_src;
		node.selected=true;
	}
	
	this.add=function add(node)
	{
		node.image=node.getElementsByTagName("img")[0];
		node.image_src=node.image.src;
		node.image_hov_src=node.image_src.replace(this.replaceObj,this.replace_str);
		
		node.preload=new Image();
		node.preload.src=node.image_hov_src;
		
		node.onmouseover=this.hover;
		node.onmouseout=this.dehov;
		
		check=new RegExp(node.href)
		
		/*
		if(url.toString()==node.href || url.toString().match(check,url.toString()))
		{
		 	node.image.src=node.image_hov_src;
			node.selected=true;
		}
		else
		{
			node.selected=false;
		}
		*/
		node.selected=false;
		
		this.nodes[this.nodes.length]=node;
	}
	
	this.hover=function hover()
	{
		if(this.selected==false) this.image.src=this.preload.src; //this.image.src=this.image_hov_src;
	}
	
	this.dehov=function dehov()
	{
		if(this.selected==false) this.image.src=this.image_src;
	}
}



function textmenu()
{
	this.nodes=new Array();
	
	this.build=function build(container_id)
	{
		topmenu=document.getElementById(container_id).getElementsByTagName("a");
		for (var i = 0; i < topmenu.length; i++) {
  			this.add(topmenu[i],i);
		}
	}
	
	this.select=function select()
	{
		this.old_style=this.style;
		if(this.style)
		{
			this.style.fontWeight="bold";
			this.style.color="#FFFFFF";
		}
		
		document.getElementById("m_cont_"+this.i).style.display="block";
		
		this.selected=true;
		if(this.parent_menu.selected) 
		{
			this.parent_menu.selected.style.fontWeight="normal";
			this.parent_menu.selected.style.color="#CCCCCC";
			document.getElementById("m_cont_"+this.parent_menu.selected.i).style.display="none";
		}
		this.parent_menu.selected=this;
	}
	
	this.add=function add(node,i)
	{
		node.i=i;
		
		node.onclick=this.select;
		node.selected=false;
		node.parent_menu=this;
		
		this.nodes[this.nodes.length]=node;
	}
	
	this.hover=function hover()
	{
		//if(this.selected==false) this.image.src=this.preload.src; //this.image.src=this.image_hov_src;
	}
	
	this.dehov=function dehov()
	{
		//if(this.selected==false) this.image.src=this.image_src;
	}
}

function open_album(url)
{
        var left = (screen.availWidth - 549  ) / 2;
        var top = (screen.availHeight - 549 ) / 2;
		
		album_window=window.open(url,"album_window","width=549,height=549,left="+left+",top="+top+",status=no");
		album_window.focus();
}


window.onload = function()
{
			m=new menu();
			m.setHovImageReplaceString("_0","_1");
			if(document.getElementById("topnav")) m.build("topnav");
			if(document.getElementById("langmenu")) m.build("langmenu");
}
