﻿
jQuery(document).ready( function() {
	MenuHelper.create([ "menuLocations", "menuInfo", "menuSales" ],
					  [ "popupLocations", "popupInfo", "popupSales" ]);
});

var MenuHelper = {
	create: function (menuIds, popupIds) {
		
		for (var i = 0; i < menuIds.length; i++) {
			ScriptedDropDown.create("#" + menuIds[i], "#" + popupIds[i]);
		}
	}
};


var ScriptedDropDown = {
	timers: Array(),
	panels: Array(),
	
	create: function (activator, panel) {
		var index = ScriptedDropDown.timers.length;
		
		ScriptedDropDown.timers.push(0);
		ScriptedDropDown.panels.push(panel);
		
		jQuery(activator).hover(
			function() { clearTimeout(ScriptedDropDown.timers[index]); jQuery(panel).fadeIn('fast'); },
			function() { ScriptedDropDown.timers[index] = setTimeout('ScriptedDropDown.hide(' + index + ')', 250); }
		);

		jQuery(panel).hover(
			function() { clearTimeout(ScriptedDropDown.timers[index]); },
			function() { ScriptedDropDown.timers[index] = setTimeout('ScriptedDropDown.hide(' + index + ')', 250); }
		);
	},
	
	createMulti: function (activators) {
		jQuery(activators).each(function (index, obj) {
			ScriptedDropDown.create(obj, jQuery(obj).find("> ul"));
		});
	},
	
	hide: function (index) {
		jQuery(ScriptedDropDown.panels[index]).fadeOut('fast');
	}
};



