

// MENU FUNCTIONS //

// Array of available sections/drop down names
var sections = [
    'adoptions',
    'animals',
    'conservation',
    'education',
    'events',
    'howyoucanhelp',
    'membership',
    'recruitment',
    'specialoffers',
    'thepark',
    'usefullinks',
    'kidscorner'
];

var noSection = '___NO_SECTION___';

// Returns the section name of the current page
function getCurrentSection() {
    var location = document.location.href;
    var numSections = sections.length;
    for (i = 0; i < numSections; i++) {
        if (location.indexOf(sections[i]) != -1) {
            return sections[i];
        }
    }
    
    return noSection;
}

// Hides context menus unless the id contains the current section name
function setupMenu() {
    var currentSection = getCurrentSection();
    //var menuItems = document.getElementsByClassName('contextmenu');
    var menuItems = $('.contextmenu');
    for (i = 0; i < menuItems.length; i++) {
        var menuItem = menuItems[i];
        if (menuItem.id.indexOf(currentSection) == -1) {
            hideElement(menuItem);
        }
    }
	var menuItemImages = $('.menuitemimage');
	for (i = 0; i < menuItemImages.length; i++) {
		var menuItemImage = menuItemImages[i];
		if (menuItemImage.id.indexOf(currentSection) == -1) {
			menuItemImage.src = 'images/menuArrowInactiveGrn.png';
		}
	}
}

// Hides the given element via css
function hideElement(element) {
    element.style.visibility = 'hidden';
    element.style.display = 'none';
}


// Shows the given element via css
function showElement(element) {
    menu.style.visibility = 'visible';
    menu.style.display = 'block';
}


// Changes the style class of the specified element to newStyleClass
function changeDivStyle(elementId, newStyleClass) {
    var element = document.getElementById(elementId);
    element.className = newStyleClass;
}



// COOKIE FUNCTIONS //

// Set a cookie
// name = the name of the cookie
// value = the value to set for the cookie
function setCookie(name, value) {
    var date = new Date();
    date.setTime(date.getTime() + (14 * 24 * 60 * 60 * 1000));
    var expires = '; expires=' + date.toGMTString();
	document.cookie = name + '=' + value+expires + '; path=/';
}

// Get a cookie value
// name = the name of the cookie whose value you wish to get
function getCookie(name) {
	var nameEQ = name + '=';
	var ca = document.cookie.split(';');
	for(var i=0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}


