// -----------------------------------------------------------------------------------

var EnpresivNav = Class.create();

EnpresivNav.prototype = {
	
	navContainer: 'navMain',
	tagName: 'a',
	className: 'navitem',
	marginRight: 1,
	marginLeft: 0,
	lastElementMarginRight: 0,
	lastElementMarginLeft: 0,
	
	// initialize()
	// Constructor runs on completion of the DOM loading. Loops through anchor tags looking for 
	// 'lightbox' references and applies onclick events to appropriate links. The 2nd section of
	// the function inserts html at the bottom of the page which is used to display the shadow 
	// overlay and the image container.
	//
	// UPDATE (Tom Hoffmann): Removed DOM mods, just use hardcoded HTML (time constraints)
	initialize: function() {
	
		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName(this.tagName);
		
		var navContainerEl = document.getElementById(this.navContainer);
		var navContainerWidth = navContainerEl.offsetWidth;
		
		var navItemsWidth = 0;
		var navItemsCount = 0;
		
		var navItemsNewWidth = 0;
		
		// loop through all anchor tags to retrieve the total width of all anchor tags
		for (var i=0; i<anchors.length; i++){
		
			var anchor = anchors[i];
			
			var classAttribute = String(anchor.className);
			
			if (classAttribute.toLowerCase().match(this.className)) {
				navItemsCount++;
				navItemsWidth += anchor.offsetWidth;
				
				if (i == anchors.length-1) {
					navItemsWidth += this.lastElementMarginLeft + this.lastElementMarginRight;
				} else {
					navItemsWidth += this.marginLeft + this.marginRight;					
				}
				
			}
			
		}
		
		navItemsNewWidth = Math.floor((navContainerWidth-navItemsWidth)/navItemsCount);
		
		// loop through all anchor tags to set the padding of the tags
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			
			var relAttribute = String(anchor.className);
			
			if (relAttribute.toLowerCase().match('navitem')) {
				// alert(anchor.style.padding);
				anchor.style.paddingLeft = navItemsNewWidth/2 + "px";
				anchor.style.paddingRight = navItemsNewWidth/2 + "px";
				
			}
			
		}
		
		document.getElementById(this.navContainer).style.visibility = 'visible';
		
	}
}

function initEnpresivNav () { myNav = new EnpresivNav(); }
Event.observe(window, 'load', initEnpresivNav, false);