﻿addLoadEvent(function() {
	yourLocalList();
});

// Highlight pub listings on hover, shoowing their addresses and logos
function yourLocalList() {

	// Grab pub list from DOM, and create a node array of all of its <li>s (pub listings)
	var pubList = $('yourLocal_pubList');
	var pubListings = pubList.getElementsByTagName('li');

	// Keep a reference to the logo, as it's ID is changed later and it thereby becomes inaccessible in the DOM
	var logo = $('yourLocal_logo');

	// Loop through all pub listings
	for (var i = 0; i < pubListings.length; i++) {

		var pubListing = pubListings[i];
		var pubName;

		// When a pub listing is moused over
		pubListing.onmouseover = function() {

			// Add "hover" class, used to highlight the row and show address
			addClass(this, 'hover');

			// Determine the pub name in camel case
			pubName = this.getAttribute('id').substring(10);

			// Change the ID of the logo, allowing the CSS to determine the correct logo image
			logo.id = pubName + '_logo';
		}

		// When a pub listing is moused off of, remove "hover" class
		pubListing.onmouseout = function() {

			// Remove "hover" class, thereby unhighlighting the row and hiding the address
			removeClass(this, 'hover');

			// Reinstate logo ID, thereby removing pub logo
			logo.id = 'yourLocal_logo';
		}

		// If this pub is closed, ensure clicking on its link doesn't navigate away from the page
		if (pubListing.getAttribute('rel') == 'closed') {
			pubListing.onclick = function() {
				return false
			};
		}
	}
}