addLoadEvent(function () {
	showProductListOnDivisionHover();
});

function showProductListOnDivisionHover() {

	var divisions = $('home_divisionList').getElementsByTagName('li');
	var hideDelay = 350;
	var showDelay = 250;
	var cursorOnImage = false;

	var performanceDirectDivision = $('home_performanceDirect');
	var performanceDirectVisitWebsiteLink = $('home_performanceDirectVisitWebsiteLink');

	// Loop through each division
	for (var i = 0; i < divisions.length; i++) {

		// Wrap in self-executing function to create distinct scope
		(function () {
			var division = divisions[i];
			var hideTimeout = null;
			var showTimeout = null;

			// If this isn't a division, return
			if (!hasClass(division, 'division')) return;

			// Get product list node reference
			var productList = division.getElementsByTagName('div')[1];

			// If there isn't a product list, continue to next division
			if (!productList) return;

			// Get image node reference
			var image = division.getElementsByTagName('img')[0];

			// If this image shouldn't show the product list when hovered upon
			if (image.getAttribute('rel') !== 'hoverable') {

				// Flag that the image is hovered upon
				image.onmouseover = function () {
					cursorOnImage = true;
				}
	
				// Flag the image is moused off of
				image.onmouseout = function () {
					cursorOnImage = false;
					division.onmouseover();
				}
			}

			// If we're on the Performance Direct division
			if (division == performanceDirectDivision) {

				// Ensure hovering on the Visit Website link, ensure product list isn't shown
				performanceDirectVisitWebsiteLink.onmouseover = function () {
					cursorOnImage = true;
				}

				performanceDirectVisitWebsiteLink.onmouseout = function () {
					cursorOnImage = false;
					division.onmouseover();
				}
			}

			// When the division is hovered upon
			division.onmouseover = function () {

				// If the cursor is on the image, return
				if (cursorOnImage) return;

				// Stop timeout waiting to hide this product list
				if (hideTimeout) clearTimeout(hideTimeout);

				// Set timeout to show the product list
				showTimeout = setTimeout(function () {
					productList.style.display = 'block';
				}, showDelay);
			};

			// When the division is moused off of, set timeout to hide product list
			division.onmouseout = function () {

				// Stop timeout waiting to show this particular product list
				if (showTimeout) clearTimeout(showTimeout);

				// Set timeout to hide the product list
				hideTimeout = setTimeout(function () {
					productList.style.display = 'none';
				}, hideDelay);
			};
		})();
	}
}