// global variables to hold the timer on the search box (otherwise we cant reset the search)
var t = 0;
var lastopen;
var currenttopopen;
var ttactive;
var tickeractive;
var genactive;
var guideactive;



 String.prototype.charCount=function()
{
var aTmp=this.split(arguments[0]);

return iLen=aTmp.length-1;
}



if (typeof topLevel === 'undefined')
var prefix = '../';
else
var prefix = '';


if (location.href.charCount('/') == 5)
{
var prefix = '../../';

}


var currentpic = 1;
var homepagepicelement = null;
 
function swapHomePic() {
 
	 homepagepicelement = document.getElementById("pics");
	var images = homepagepicelement.getElementsByTagName('img');  

	
	for(i = 0; i < images.length; i++) {
		imagetoshow = images[i];
		imagetoshow.style.display = 'none';
	}
	 
	imagetoshow = images[currentpic];
	imagetoshow.style.display = 'block'; 
	 
	currentpic++;
	
 
	if (currentpic > images.length - 1)
		currentpic = 0;

	 

}
 

var menurules = {
	
	
	'#press' : function (el){
		el.onmouseover = function() {
			document.getElementById('pressed').style.display  = 'block';
		} 
		el.onmouseout = function() {
			document.getElementById('pressed').style.display  = 'none';
		} 
	}, 

	
	'#pics img' : function(el) {
		 
		 el.style.display = 'none';
		
	}

	,
	'#pics' : function(el) {
		 
		var images = el.getElementsByTagName('img');  
		var numimages = images.length;
		
		homepagepicelement = el;
		
	
		
		//uncomment the following three lines and leave the ones below commented to display a randome pic
		//var randomPic = Math.ceil((Math.random() * numimages)) - 1;
	  	//imagetoshow = images[randomPic];
		// imagetoshow.style.display = 'block'; 
		 
		// uncomment theses and comment the above three to make the images rotate;
		 imagetoshow = images[0];
		 imagetoshow.style.display = 'block';
		
		if (document.getElementById('pic1')) {
			setInterval('swapHomePic()', 3000); 
		}
	}
	,
	'#topNav a' : function (el){
	el.onmouseover = function()
		{
			hideAllTopMenu();
			clearAllOpenMenus();
		
			if (el.nextSibling.nextSibling)
			el.nextSibling.nextSibling.style.display  = 'block';
		}
	},
	
		'#topNav li ul li a' : function (el){
		el.onmouseover = function()
		{
			
			// do nothing.. have to define this!
		}
		},
		
		
		'#leftNav a' : function (el){
		el.onmouseover = function()
		{
			hideAllTopMenu();
			clearAllOpenMenus();
			
		}
	},
		
		'#leftNav ul li ul' : function(el){
		
		
		if (el.parentNode.id == 'timetables' && tt)
		{
			el.style.display = 'block';
			//el.parentNode.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tarrow_on.gif")'; 
			ttactive = true;
		}else if (el.parentNode.id == 'trams' && tr)
		{
			el.style.display = 'block';
			//el.parentNode.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tckarrow_on.gif")'; 
			tractive = true;
		}
		else if (el.parentNode.id == 'ticketing' && tk)
		{
			el.style.display = 'block';
			//el.parentNode.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tckarrow_on.gif")'; 
			tickeractive = true;
		}
		
		else if (el.parentNode.id == 'accessible' && at)
		{
			el.style.display = 'block';
			//el.parentNode.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tckarrow_on.gif")'; 
			tickeractive = true;
		}
				
		else if (el.parentNode.id == 'better' && bb)
		{
			el.style.display = 'block';
			//el.parentNode.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tckarrow_on.gif")'; 
			tickeractive = true;
		}
		
		else if (el.parentNode.id == 'general' && ge)
		{
			el.style.display = 'block';
			//el.parentNode.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_giarrow_on.gif")';
			genactive = true;
		}
		else if (el.parentNode.id == 'guides' && gd)
		{
			//el.parentNode.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_garrow_on.gif")'; 
			el.style.display = 'block';
			guideactive = true;
		}
		//else if (el.parentNode.id == 'search' && gd)
		//{
			//el.parentNode.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_garrow_on.gif")'; 
		//	el.style.display = 'block';
		//	guideactive = true;
		//}
		
		else
		el.style.display = 'none';
				
		},
		
		'#leftNav ul li ul li a' : function(el){
		el.onclick = function()
		{
			document.location = el.href;
		
		}
		
		
		el.onmouseover = function()
		{
	
			clearAllOpenMenus();
			hideAllTopMenu();
		   
		   if (el.nextSibling)
		   {
		   		if (el.nextSibling.nextSibling)
		   		{
		   			el.nextSibling.nextSibling.style.display  = 'block';
					lastopen =  el.nextSibling.nextSibling;
				}
			}
			return false;	
		};	
		
		}
		,	
		
		'#leftNav ul li ul li ul li a' : function(el){
		el.onclick = function()
		{
			document.location = el.href;
		
		}
		},	
		
		'#leftNav ul #timetables ul li ul li a' : function(el){
		el.onmouseover = function()
		{
			// do nothing
			el.parentNode.parentNode.parentNode.firstChild.className = 'timetableshover';
			
		};
		
				
		},
		
		
		
		'#leftNav ul #better ul li ul li a' : function(el){
		el.onmouseover = function()
		{
			// do nothing
			el.parentNode.parentNode.parentNode.firstChild.className = 'betterhover';
			
		};
			
		},
		
		
		
		'#leftNav ul #ticketing ul li ul li a' : function(el){
		el.onmouseover = function()
		{
			// do nothing
			el.parentNode.parentNode.parentNode.firstChild.className = 'ticketinghover';
			
		};
		
			
		},
		
		
		'#leftNav ul #trams ul li ul li a' : function(el){
		el.onmouseover = function()
		{
			// do nothing
			el.parentNode.parentNode.parentNode.firstChild.className = 'tramshover';
			
		};
		
			
		},
		
		
		
		
		'#leftNav ul #general ul li ul li a' : function(el){
		el.onmouseover = function()
		{
			// do nothing
			el.parentNode.parentNode.parentNode.firstChild.className = 'generalhover';
			
		};
		
				},
		
		'#leftNav ul #accessible ul li ul li a' : function(el){
		el.onmouseover = function()
		{
			// do nothing
			el.parentNode.parentNode.parentNode.firstChild.className = 'accessiblehover';
			
		};
		
			
		},
		
		'#leftNav ul #guides ul li ul li a' : function(el){
		el.onmouseover = function()
		{
			// do nothing
			el.parentNode.parentNode.parentNode.firstChild.className = 'guideshover';
			
		};
		
			
		},
		
		
		//'#leftNav ul #search ul li ul li a' : function(el){
		//el.onmouseover = function()
		//{
			// do nothing
		//	el.parentNode.parentNode.parentNode.firstChild.className = 'searchhover';
			
		//};
		
			
		//},
		
		
		'#timetables' : function(el){
		el.onclick = function()
		{
			hideAll();
		//	el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tarrow_on.gif")'; 
		
			el.firstChild.nextSibling.nextSibling.style.display = 'block';
			ttactive = true;
			return false;	
		};	
		
		el.onmouseover = function()
		{
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tarrow_on.gif")'; 
			
		};	
		el.onmouseout = function()
		{
			//if (!ttactive)
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tarrow_off.gif")'; 
			
		};	
		
		
		},
		
		
		
		'#trams' : function(el){
		el.onclick = function()
		{
			hideAll();
		//	el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tarrow_on.gif")'; 
		
			el.firstChild.nextSibling.nextSibling.style.display = 'block';
			tractive = true;
			return false;	
		};	
		
		el.onmouseover = function()
		{
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tarrow_on.gif")'; 
			
		};	
		el.onmouseout = function()
		{
			//if (!ttactive)
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tarrow_off.gif")'; 
			
		};	
		
		
		},
		
		
		
		'#ticketing' : function(el){
		
				
		el.onclick = function()
		{
			
			hideAll();
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tckarrow_on.gif")'; 
			
			el.firstChild.nextSibling.nextSibling.style.display = 'block';
			tickeractive = true;
			return false;	
		};	
		
		el.onmouseover = function()
		{
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tckarrow_on.gif")'; 
			
		};	
		el.onmouseout = function()
		{
			//if (!tickeractive)
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tckarrow_off.gif")'; 
			
		
			
		};	
		
		},
		'#accessible' : function(el){
		
				
		el.onclick = function()
		{
			
			hideAll();
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tckarrow_on.gif")'; 
			
			el.firstChild.nextSibling.nextSibling.style.display = 'block';
			tickeractive = true;
			return false;	
		};	
		
		el.onmouseover = function()
		{
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tckarrow_on.gif")'; 
			
		};	
		el.onmouseout = function()
		{
			//if (!tickeractive)
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tckarrow_off.gif")'; 
			
		
			
		};	
		
		
				},
		'#better' : function(el){
		
				
		el.onclick = function()
		{
			
			hideAll();
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tckarrow_on.gif")'; 
			
			el.firstChild.nextSibling.nextSibling.style.display = 'block';
			tickeractive = true;
			return false;	
		};	
		
		el.onmouseover = function()
		{
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tckarrow_on.gif")'; 
			
		};	
		el.onmouseout = function()
		{
			//if (!tickeractive)
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tckarrow_off.gif")'; 
			
		
			
		};	
		
		
		
		
		},
		'#general' : function(el){
		
				
		el.onclick = function()
		{
			hideAll();
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_giarrow_on.gif")'; 
			
			el.firstChild.nextSibling.nextSibling.style.display = 'block';
			genactive = true;
			return false;	
		};	
		
		el.onmouseover = function()
		{
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_giarrow_on.gif")'; 
			
		};	
		el.onmouseout = function()
		{
			//if (!genactive)
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_giarrow_off.gif")'; 
			
		};	
		
		
		
		},
		'#guides' : function(el){
		
				
		el.onclick = function()
		{
				hideAll();
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_garrow_on.gif")'; 
		
			el.firstChild.nextSibling.nextSibling.style.display = 'block';
			guideactive = true;
			return false;	
		};	
		
		el.onmouseover = function()
		{
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_garrow_on.gif")'; 
			
		};	
		el.onmouseout = function()
		{
			//if (!guideactive)
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_garrow_off.gif")'; 
			
		};	
		
		
		},
		
		
		//'#search' : function(el){
		
				
	//	el.onclick = function()
	//	{
		//		hideAll();
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_garrow_on.gif")'; 
		
	//		el.firstChild.nextSibling.nextSibling.style.display = 'block';
	//		guideactive = true;
	//		return false;	
	//	};	
		
	//	el.onmouseover = function()
	//	{
	//		//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_garrow_on.gif")'; 
			
	//	};	
	//	el.onmouseout = function()
	//	{
			//if (!guideactive)
			//el.firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_garrow_off.gif")'; 
			
	//	};	
		
		
	//	},
		
		'#pageContentHome' : function(el){
		el.onmouseover = function()
		{
			clearAllOpenMenus();
			hideAllTopMenu();
		};
		}
	,
'#pageContent' : function(el){
		el.onmouseover = function()
		{
			clearAllOpenMenus();
			hideAllTopMenu();
		};
		}
		,
		'#header' : function(el){
		el.onmouseover = function()
		{
			clearAllOpenMenus();
			hideAllTopMenu();
		};		
			
		},
		'#yellowbg' : function(el){
		el.onmouseover = function()
		{
			clearAllOpenMenus();
			hideAllTopMenu();
		};
		},
		'.newwindow' : function(el){
		el.onclick = function()
		{
			alert('This will open a new window and take you to another site.  Please close that window to return to the Adelaide Metro site');
			window.open(el.href);
			return false;
		};
		
		
			
		}
		
		
	
	
};


function hideAll()
{

// maybe store these 
	//document.getElementById('search').firstChild.nextSibling.nextSibling.style.display = 'none';
	document.getElementById('guides').firstChild.nextSibling.nextSibling.style.display = 'none';
	document.getElementById('general').firstChild.nextSibling.nextSibling.style.display = 'none';
	document.getElementById('ticketing').firstChild.nextSibling.nextSibling.style.display = 'none';
	document.getElementById('timetables').firstChild.nextSibling.nextSibling.style.display = 'none';
	document.getElementById('accessible').firstChild.nextSibling.nextSibling.style.display = 'none';
	document.getElementById('better').firstChild.nextSibling.nextSibling.style.display = 'none';
	document.getElementById('trams').firstChild.nextSibling.nextSibling.style.display = 'none';
	
//	document.getElementById('guides').firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_garrow_off.gif")';
//	document.getElementById('general').firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_giarrow_off.gif")'; 
//	document.getElementById('ticketing').firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tckarrow_off.gif")';
//	document.getElementById('timetables').firstChild.style.backgroundImage=  'url("' + prefix + 'images/nav_tarrow_off.gif")'; 

	ttactive = tickeractive = genactive = guideactive = tractive = false;


	
	hideAllTopMenu();
}

function hideAllTopMenu()
{
// maybe store these 
	document.getElementById('topNav_special').style.display = 'none';
	document.getElementById('topNav_mailing').style.display = 'none';
	document.getElementById('topNav_contacts').style.display = 'none';
//	document.getElementById('topNav_press').style.display = 'none';
	document.getElementById('topNav_about').style.display = 'none';
}

function clearAllOpenMenus()
{
	
	
	if (lastopen)
	{
		lastopen.style.display = 'none';
		lastopen.parentNode.firstChild.className = '';
	}
	
}


Behaviour.register(menurules);

