/**
 Object responsible for the topnavigation onmouseover() and onmouseout() effects
 
 All functions and variables of this object could be used as "static" without creating the object instance
*/

function TopNavigation() {}

TopNavigation.prototype.images = null; // array for onmouseover/onmouseout images

/**
Attach onmouseover and onmouseout event handlers to the img elements inside top navigation hyperlinks
*/
TopNavigation.prototype.attach = function() 
{
	TopNavigation.prototype.images = new Array();
	
	// NavBar div
	nvabar = document.getElementById('NavBar');
	
	// We need only images inside hyperlinks
	var links = nvabar.getElementsByTagName("a");
	var imgs = null;
	var img_id = '';
	var reg = new RegExp("^nav_[a-z]+$"); // given very srictly (since image names are caclulated based on the id attribute, also to avoid some XSS attempts)
	var temp = null;
	var img_src = '';
 for(var i = 0; i < links.length; i++)
 {
 	// to avoid problems with possible text child nodes (also XPath could be used)
 	imgs = links[i].getElementsByTagName("img");
 	if(undefined!=imgs[0])
 	{
 		img_id = imgs[0].id;
 		// Simple check (made because image names are calculated, not hardcoded)
   if(!img_id.match(reg))
   {
   	alert('An image id is not valid');
   	return;
   }
   temp = img_id.split('_');
   imgs[0].top_nav_img_src = imgs[0].src;
   imgs[0].top_nav_img_h = new Image();
   imgs[0].top_nav_img_h.src = 'images/' + temp[1] + '_h.gif';
   
 		// onmouseover and onmouseout handlers
   imgs[0].onmouseover = function()
   {
   	this.src = this.top_nav_img_h.src;
   }
   imgs[0].onmouseout = function()
   {
   	this.src = this.top_nav_img_src;
   }   
 	}
 }
}
