// JavaScript Document

/********** MAIN MENU VARIABLES AND FUNCTIONS **********/
var imgLocation = '/uploadedImages/public_site/submenus/';
var MMvalue = null;
var imgClass = null;
var imgItem = null;
var imgData = null;
var imgName = null;
var imgActive = null;
var imgInactive = null;
var dropMenu = null;
var timeout = 250;
var closer = 0;

/*THIS FUNCTION SETS THE APPROPRIATE MENU ITEM TO ACTIVE */
function setActive() {
	MMvalue = document.getElementById("main-menu-control");
	// If the main-menu-control div exists, process the data; otherwise, do nothing.
	if (MMvalue != null)
	{
		imgClass = $('#main-menu-control').attr('class');
		imgItem = $('#main_menu > li#' + imgClass).find('img').attr('src');
		// If the Main Menu item exists, swap the image and apply a class; otherwise, do nothing.
		if (imgItem){
			imgName = imgItem.replace(imgLocation, '').replace('.jpg', '');
			imgActive = imgLocation + imgName + '_active.jpg';
			$('#main_menu > li#' + imgClass).find('img').attr('src', imgActive);
			$('#main_menu > li#' + imgClass).addClass('isActive');
		}
		else {}
	}
	else
	{}
}

/* THESE FUNCTIONS CONTROL THE IMAGE SWAP FOR THE MAIN MENU */
function swapIn(event) {
	// If this Main Menu item does not contain the class 'isActive', then swap the image and drop the dropdown menu if it exists;
	//    otherwise, do nothing and drop the dropdown menu if it exists.
	if ($(this).attr('class') != 'isActive'){
		imgData = $(this).find('img').attr('src');
		imgName = imgData.replace(imgLocation, '').replace('.jpg', '');
		imgActive = imgLocation + imgName + '_active.jpg';
	
		$(this).find('img').attr('src', imgActive);
	}
	else{}
		// Controls Drop Down functionality
		menuTimerCancel();
		menuClose();
		dropMenu = $(this).find('ul').css('visibility', 'visible');
}

function swapOut(event) {
	// If this Main Menu item does not contain the class 'isActive', then swap the image and remove the dropdown menu if it exists;
	//    otherwise, do nothing and remove the dropdown menu if it exists.
	if ($(this).attr('class') != 'isActive'){
		imgData = $(this).find('img').attr('src');
		imgInactive = imgData.replace('_active', '');
		
		$(this).find('img').attr('src', imgInactive);
	}
	else {}
		// Controls Drop Down functionality
		closer = window.setTimeout(menuClose, timeout);
//		$(this).find('ul').css('visibility', 'hidden');
}
/********** END MAIN MENU FUNCTIONS **********/

function menuClose() {
	if (dropMenu) {
		dropMenu.css('visibility', 'hidden');
	}
}

function menuTimerCancel() {
	if (closer) {
		window.clearTimeout(closer);
		closer = null;
	}
}

document.onclick = menuClose;










/********** LEFT NAVIGATION FUNCTIONS **********/
function setLeftNav() {
	var hasLeftNav = $('#left_nav').find('ul').attr('id');

	if ( hasLeftNav ) {
		var LnavValue = $('#subnavID').attr('class');
		$('#' + LnavValue).addClass('list_item-hover');
		$('#' + LnavValue + ' a').removeAttr('href');
	}
}
/********** END LEFT NAVIGATION FUNCTIONS **********/
