// JavaScript Document
var NAVIGATION_DEPTH = 3;
var navigation = [
					{text:'', url:'#'},
					<!--{text:'about', children:[
					<!--{text:'', url:'#'},
					<!--	{text:'Bio', url:'bio.htm'},
					<!--	{text:'Clients', url:'clients.htm'},
					<!--	{text:'Services', url:'services.htm'}
					<!--]},
					<!--{text:'portfolio', children:[
					<!--	{text:'', url:'#'},
					<!--	{text:'Deuce Design', url:'d_deuce.htm'},
					<!--	{text:'Deus Ex Machina', url:'d_deus.htm'},
					<!--	{text:'Mambo', url:'d_mambo.htm'},
					<!--	{text:'Monster Children', url:'d_mc.htm'},
					<!--	{text:'Moshtix', url:'d_moshtix.htm'},
					<!--	{text:'Supply', url:'d_supply.htm'}
					<!--]},
						<!--{text:'Products & Projects', children:[
						<!--	{text:'', url:'#'},
						<!--	{text:'2x4', url:'http://www.2x4tshirts.com'},
						<!--	{text:'Australian INfront', url:'http://www.australianinfront.com.au'},
						<!--	{text:'We Are - Dec 07'}
				<!--	]},
					{text:'about', url:'about.html'},
					{text:'news', url:'news.html'},
					{text:'contact', url:'contact.php'},
					{text:'portfolio', url:'portfolio.html'},
					{text:'digital gallery', url:'digiArt.htm'},
					{text:'links', url:'links.html'}
					

				];
				
function $(id) { return document.getElementById(id); }

var navigationLists = [];

function Navigation_OnInit()
{
	navigationLists = [$('Navigation1'),$('Navigation2'),$('Navigation3')];

    PopulateNavigation(navigation, 0);
    
    var mtch = /.+\/(.+\.htm)/.exec(window.location.href);
    if (mtch)
	{
		var indexArray = findItem(navigation, mtch[1]);
		
		if (indexArray)
		{
			for (var i=0; i<indexArray.length; i++)
			{
				var navigationList = navigationLists[i];
				navigationList.selectedIndex = indexArray[i]+1;
				Navigation_OnChange(navigationList, true);
			}
		}
	}
}

function findItem(arr, str)
{
	for (var i=0; i<arr.length; i++)
	{
		if (arr[i].url==str)
			return [i];
		else if (arr[i].children)
		{
			var foundArray = findItem(arr[i].children, str);
			
			if (foundArray)
			{
				foundArray.splice(0,0,i);
				return foundArray;
			}					
		}
	
		
	}
}

function Navigation_OnChange(ddl,init)
{
	var option = ddl.options[ddl.selectedIndex];
	if (option.value!='' && !init) { window.location.href = option.value; return; }

	var nav = navigation;
	
	var disable = false;
	
	for (var i=0; i<navigationLists.length; i++)
	{
		var navigationList = navigationLists[i];
		navigationList.disabled = disable;
		
		var children = (nav.children || nav);
		
		if (navigationList==ddl)
		{
			disable = true;
			
			if (navigationList.selectedIndex>0 && navigationList.value=='')
			{
				PopulateNavigation(children[navigationList.selectedIndex-1].children, ++i);
				navigationLists[i].disabled = false;
				navigationLists[i].focus();
			}
		}
		
		if (navigationList.selectedIndex>0)					
			nav = children[navigationList.selectedIndex-1];
	}
}

function observe(obj)
{
	if (obj==null)
		return 'null';
	else if (obj instanceof Array)
	{
		var text = '[';
		for (var i=0; i<obj.length; i++)
		{
			if (i>0) text += ',';
			text += observe(obj[i]);
		}
		text += ']';
		
		return text;
	}
	else if (typeof(obj)=='undefined')
		return '<undefined>';
	else if (typeof(obj)=='Number')
		return obj.toString();
	else if (typeof(obj)=='string')
		return '"'+obj+'"';
	else if (obj instanceof Object)
	{
		var sep = '', text = '{';
		for (var prop in obj) { text += sep + prop + ':' + observe(obj[prop]); sep = ','; }
		text += '}';
		return text;
	}
	else
		return '<unknown>';
}

function PopulateNavigation(nav, level)
{
	var navigationList = navigationLists[level];

	while(navigationList.options.length>0)
		navigationList.options[0]=null;

	navigationList.options[0] = new Option('just add water..', '');

	for (var i = 0; i < nav.length; i++)
    {
		var opt = new Option();
		opt.text = nav[i].text;
		opt.value = (nav[i].url) ? nav[i].url : '';
		
		navigationList.options[navigationList.options.length] = opt;
	}
	
	Navigation_OnChange(navigationLists[level]);
	
	navigationLists[level].onchange = function() { Navigation_OnChange(this); }
}

window.onload = Navigation_OnInit;