/********************************************************
Ecommerce Design Services Javascript Library
(c) 2009 Network Solutions
*********************************************************/

/**
 * This is where you can turn on your navigation options.
 */
var header_nav = 'on';
var category_nav = 'off';
var all_modules = 'off';


// This object contains methods to get HTML elements
var htmlObject = function () {
	
	return {
		/**
		 * This is to shorten down the
		 * getElementById method.
		 *
		 * @param elementID
		 */
		el : function (elementID) {
			return document.getElementById(elementID);
		},
		
		/**
		 * This is to shorten down the
		 * getElementById method with
		 * the style option.
		 *
		 * @param elementID
		 */
		es : function (elementID) {
			return document.getElementById(elementID).style;
		},
		
		/**
		 * This is to shorten down the
		 * getElementsByTagName method.
		 *
		 * @param elementTag
		 */
		et : function (elementTag) {
			return document.getElementsByTagName(elementTag);
		},
		
		/**
		 * This method grabs an element by class name
		 * and then returns all the HTML elements within.
		 *
		 * @param searchClass
		 */
		ec : function (searchClass) {
			// Get all HTML Elements
			allElements = this.et('*');
	
			// Create a new Array
			classElements = new Array();
			
			// Loop through all elements
			for(i=0, j=0; i < allElements.length; i++) {
				
				// Store all elements contained within the given class
				if (allElements[i].className.match(searchClass)) {
					classElements[j] = allElements[i];
					j++;
				}
			}
			
			// Return array with all elements from given class
			return classElements;
		}
	
	}
	
}();

// This object contains methods to control fly outs and drop down menus
var Menu = function () {
	
	return {
		/**
		 * Setup an unordered list for drop out menus.
		 *
		 * @param elementClass
		 */
		setup : function (elementClass) {
				
				// Get all objects in a given class
				theMenus = htmlObject.ec(elementClass);
				
				// Loop through all HTML elements in a given class
				for(i=0;i<theMenus.length;i++) {
				
					var d = new Date();
					var t = d.getTime();
					
					// Assign main container a unique ID
					theMenus[i].id = elementClass+t;
					// Assign each menu object a unique ID
					menuObject = htmlObject.el(elementClass+t);
					// Get all <UL>'s by tag name
					menuLists = menuObject.getElementsByTagName("ul");
					
					// Loop through all unordered list
					for(ii=0; ii < menuLists.length; ii++) {
						
						// Get all <LI>'s in each unordered list
						menuListItems = menuLists[ii].getElementsByTagName("li");
						
						// Loop through all <LI>'s
						for(iii=0; iii <menuListItems.length; iii++) {
							// Store all the menu items in an array
							liContent = menuListItems[iii].innerHTML;
							
							if (liContent.match("<UL") || liContent.match("<ul")) {
								
								// Apply an onmouseover event to the <UL>'s
								menuListItems[iii].onmouseover=function() {
			
									liUL=this.getElementsByTagName("ul");	
									liUL[0].style.display="block";
			
								}
								
								// Apply an onmouseout event to all <UL>'s
								menuListItems[iii].onmouseout=function() {
			
									liUL=this.getElementsByTagName("ul");	
									liUL[0].style.display="none";
			
								}
			
							}
			
						}		
			
					}
			
				}
				
		}
	
	}
			
}();

// This object contains methods to apply window events
var windowEvents = function () {
	
	return {
		/**
		 * Setup a window.onload event
		 *
		 * @param func
		 */
		windowOnload : function (func) {
			// Set current onload event
			var currentOnLoad = window.onload;
			
			// Check to see if it is a function
			if (typeof window.onload != 'function') {
				// Fire onload event
				window.onload = func;
			} else {
				// Fire onload event
				window.onload = function () {
					currentOnLoad();
					func();
				}
			}			
		}
	}
		
}();

/**
 * Configure your site with needed calls
 */
 
 /**
  * This will setup your drop downs on
  * your header navigation. You will 
	* need to use the class of main-menu
	*/
if (header_nav == 'on') {
 windowEvents.windowOnload(function () { Menu.setup('main-menu'); });
}
 
 /**
  * This will setup your fly outs on your
	* left or right column menus.
	*/
if (category_nav == 'on') {
 windowEvents.windowOnload(function () { Menu.setup('category-module'); });
}
 
/**
 * This will allow you to apply fly outs
 * to all of your modules in the left or
 * right column.
 */
if (all_modules == 'on') {
 windowEvents.windowOnload(function () { Menu.setup('module'); });
}