﻿$().ready(function() {
// Get current page and query string
var path = location.pathname;
var sec_path = path + location.search;

// Create array of exceptions that will not change the first sub nav item's color
var exception = new Array();
exception[0] = '/press_kit.aspx';
exception[1] = '/image_gallery.aspx';
exception[2] = '/job_opening.aspx';
exception[3] = '/job_openings.aspx';
exception[4] = '/job_openings_list.aspx';
exception[5] = '/application_form.aspx';
exception[6] = '/vessel_schedule.aspx';
exception[7] = '/statistics.aspx';
exception[8] = '/investors.aspx?id=7893';
exception[9] = '/contactus.aspx';

//in_array function (similiar to php's in_array)
function in_array(needle, haystack, strict) {
 
    var found = false, key, strict = !!strict;
 
    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }
 
    return found;
}

// If a main menu item is selected, the first submenu item will be highlighted (exceptions made for differently named subpages)
if (location.search == "" && !in_array(path,exception)) {
    $('#subnav ul li a:first').attr('style', 'color:#237E9C !important;');
}
if (path == '/press_kit.aspx' || path == '/image_gallery.aspx') {
    path = '/port_news.aspx';
}
if (path == '/job_openings.aspx' || path == '/application_form.aspx' || path == '/job_opening.aspx' || path == '/job_openings_list.aspx') {
    path = '/careers.aspx';
}
if (path == '/vessel_schedule.aspx') {
    path = '/port_information.aspx';
}
if (path == '/statistics.aspx') {
    path = '/introduction.aspx';
}
if (path == '/') {
    path = '/default.aspx';
}
if (path == '/port_news_item.aspx' || path == '/highlighted.aspx') {
    path = '/port_news.aspx';
    sec_path = path;
}
if (path == '/contactus.aspx') {
    path = 'contacts.aspx';
    sec_path = path;
}
// Change the appropriate links' text color
if (path) {
    $('#nav li a[@href$="' + path + '"]').attr('style', 'color:#F09034 !important;');
    $('#subnav ul li a[@href$="' + sec_path + '"]').attr('style', 'color:#237E9C !important;');
}
});

