$(function(){
    var pathname = location.pathname;
    var query    = location.search;
    var filename = pathname + query;
    var hostname = location.hostname;

    //if ( filename != '/_en/index.pl' && filename != '/_en/' ) {
    
        var filenameAltern = exceptionURI(filename);
        if (filenameAltern) {
            filename = filenameAltern;
        }

        var subnavigationHighlighted = 0;
    
        $("#sub-nav li a").each(
            function() {
                // highlight current navigation item
                if ( this.href.indexOf(hostname+filename) != -1 ) {
                    $(this).parent().addClass('active');
                    subnavigationHighlighted = 1;
                }
            }
        );

        if ( ! subnavigationHighlighted ) {
            var subnavigation = pathname.split('/',3).join('/') + '/';
            $("#sub-nav li a").each(
                function() {
                    // highlight current navigation item
                    if ( this.href.indexOf(subnavigation) != -1 ) {
                        $(this).parent().addClass('active');
                        subnavigationHighlighted = 1;
                    }
                }
            );
        }
    //}

    // mark last item
    $("#navigation-list>li:last").addClass("last");

    /*
    // add urchin tracking
    $.getScript("http://www.google-analytics.com/urchin.js", function(){
        _uacct = "UA-2469875-3";
        urchinTracker();
    });
    */
}
);

/* to be able to highlight the correct menu-item */
function exceptionURI( filename ) {

    var MyExceptionList = new Object();
    var myAlternativeFileName;

    // packaging
    MyExceptionList["/markets/packaging/_en/index.pl?appl_id=aee6d704-bd78-48d7-b8c4-4f01ef04b303&appl_name=Packaging"] = "/_scripts/gradeselector.pl?template=market&market=aee6d704-bd78-48d7-b8c4-4f01ef04b303";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=94b51f7f-a039-445e-b0ab-845e118c8c85"]           = "/_scripts/gradeselector.pl?template=market&market=aee6d704-bd78-48d7-b8c4-4f01ef04b303";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=8a570335-91a5-48aa-9b8c-90daa8dfac4c"]           = "/_scripts/gradeselector.pl?template=market&market=aee6d704-bd78-48d7-b8c4-4f01ef04b303";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=8d47f932-2538-44fa-bb1c-6ad26196791c"]           = "/_scripts/gradeselector.pl?template=market&market=aee6d704-bd78-48d7-b8c4-4f01ef04b303";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=d548ac26-e071-4d69-b4a3-3b40cfa4f21c"]           = "/_scripts/gradeselector.pl?template=market&market=aee6d704-bd78-48d7-b8c4-4f01ef04b303";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=51f12983-50ec-4db0-ab18-81f3c3306701"]           = "/_scripts/gradeselector.pl?template=market&market=aee6d704-bd78-48d7-b8c4-4f01ef04b303";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=a8a28d8c-d0f4-43a7-8798-b0ec5181cc22"]           = "/_scripts/gradeselector.pl?template=market&market=aee6d704-bd78-48d7-b8c4-4f01ef04b303";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=4483604d-7b13-4be2-ac81-07eff0f302fc"]           = "/_scripts/gradeselector.pl?template=market&market=aee6d704-bd78-48d7-b8c4-4f01ef04b303";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=b5d13b46-8fb0-478e-b7bb-df74c9974ff9"]           = "/_scripts/gradeselector.pl?template=market&market=aee6d704-bd78-48d7-b8c4-4f01ef04b303";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=6c60a81f-6ea0-427f-ba1c-61193f1aeba4"]           = "/_scripts/gradeselector.pl?template=market&market=aee6d704-bd78-48d7-b8c4-4f01ef04b303";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=df77d622-178e-4b65-9570-3dd65b831368"]           = "/_scripts/gradeselector.pl?template=market&market=aee6d704-bd78-48d7-b8c4-4f01ef04b303";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=f4abfa09-86bf-4276-bc78-a8509287bc7a"]           = "/_scripts/gradeselector.pl?template=market&market=aee6d704-bd78-48d7-b8c4-4f01ef04b303";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=d888bb01-6bea-4a0e-bc21-987799706f70"]           = "/_scripts/gradeselector.pl?template=market&market=aee6d704-bd78-48d7-b8c4-4f01ef04b303";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=cacc07d1-3be2-4ba2-8d3e-5b661d7d9ec0"]           = "/_scripts/gradeselector.pl?template=market&market=aee6d704-bd78-48d7-b8c4-4f01ef04b303";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=bcc860ff-fc27-4281-a58b-cac22cec212f"]           = "/_scripts/gradeselector.pl?template=market&market=aee6d704-bd78-48d7-b8c4-4f01ef04b303";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=ba13d186-40d1-4638-849b-7b8373146d29"]           = "/_scripts/gradeselector.pl?template=market&market=aee6d704-bd78-48d7-b8c4-4f01ef04b303";


    // pipe
    MyExceptionList["/markets/pipe/_en/index.pl?appl_id=b7f9d4d1-2320-49b5-993e-686eb5842483&appl_name=Pipe"] = "/_scripts/gradeselector.pl?template=market&market=b7f9d4d1-2320-49b5-993e-686eb5842483";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=5f4d6084-131e-4716-a06e-b668fc6bb3f6"] = "/_scripts/gradeselector.pl?template=market&market=b7f9d4d1-2320-49b5-993e-686eb5842483";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=255aa5db-6e0d-49e5-8801-4edcfa990683"] = "/_scripts/gradeselector.pl?template=market&market=b7f9d4d1-2320-49b5-993e-686eb5842483";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=a79e9b2b-7a99-461e-b3c1-058314873798"] = "/_scripts/gradeselector.pl?template=market&market=b7f9d4d1-2320-49b5-993e-686eb5842483";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=707f7d55-5a5d-4f23-892e-bef7aece25c1"] = "/_scripts/gradeselector.pl?template=market&market=b7f9d4d1-2320-49b5-993e-686eb5842483";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=55d9b3dd-4e71-4787-8ebd-4daa3bf23333"] = "/_scripts/gradeselector.pl?template=market&market=b7f9d4d1-2320-49b5-993e-686eb5842483";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=e05856ae-2d01-45fc-9e90-0206ceb32d43"] = "/_scripts/gradeselector.pl?template=market&market=b7f9d4d1-2320-49b5-993e-686eb5842483";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=0e39c532-f8ff-4008-9f05-86969783c9a0"] = "/_scripts/gradeselector.pl?template=market&market=b7f9d4d1-2320-49b5-993e-686eb5842483";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=61455a46-cbc0-4e01-83af-24b622bd1eea"] = "/_scripts/gradeselector.pl?template=market&market=b7f9d4d1-2320-49b5-993e-686eb5842483";


    // automotive
    MyExceptionList["/markets/automotive/_en/index.pl?appl_id=05e62bb9-a91d-4877-bbd2-0265f6d21d29&appl_name=Automotive"]   = "/_scripts/gradeselector.pl?template=market&market=05e62bb9-a91d-4877-bbd2-0265f6d21d29";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=fe159222-ea13-4c38-a6ca-764b2b0c8d17"]               = "/_scripts/gradeselector.pl?template=market&market=05e62bb9-a91d-4877-bbd2-0265f6d21d29";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=d74715a9-d57f-4813-afda-c994935867f3"]               = "/_scripts/gradeselector.pl?template=market&market=05e62bb9-a91d-4877-bbd2-0265f6d21d29";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=7a85049a-dc27-4d85-9ca3-229e09e5eec2"]               = "/_scripts/gradeselector.pl?template=market&market=05e62bb9-a91d-4877-bbd2-0265f6d21d29";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=f3582ed3-4448-4c5c-8352-6912e4863613"]               = "/_scripts/gradeselector.pl?template=market&market=05e62bb9-a91d-4877-bbd2-0265f6d21d29";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=a77479b7-ab39-4139-858d-2f05270b8039"]               = "/_scripts/gradeselector.pl?template=market&market=05e62bb9-a91d-4877-bbd2-0265f6d21d29";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=77385d38-82b5-4973-80fb-5cc37b8c7838"]               = "/_scripts/gradeselector.pl?template=market&market=05e62bb9-a91d-4877-bbd2-0265f6d21d29";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=c742f58c-d186-45a2-a5db-bdc1460c9110"]               = "/_scripts/gradeselector.pl?template=market&market=05e62bb9-a91d-4877-bbd2-0265f6d21d29";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=4f943736-0fe4-45ec-9993-225e74831e36"]               = "/_scripts/gradeselector.pl?template=market&market=05e62bb9-a91d-4877-bbd2-0265f6d21d29";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=28a05802-8a79-4cd2-873d-f213715c76df"]               = "/_scripts/gradeselector.pl?template=market&market=05e62bb9-a91d-4877-bbd2-0265f6d21d29";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=99bd1310-cd41-4aaa-be71-0dc631c91ed1"]               = "/_scripts/gradeselector.pl?template=market&market=05e62bb9-a91d-4877-bbd2-0265f6d21d29";


    // textiles
    MyExceptionList["/markets/textiles/_en/index.pl?appl_id=1a32ace7-7903-4e43-8013-f6a5a6805aaf&appl_name=Textiles"]       = "/_scripts/gradeselector.pl?template=market&market=1a32ace7-7903-4e43-8013-f6a5a6805aaf";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=b1ad2efa-8d86-4703-bd9f-33a31c6a8532"]               = "/_scripts/gradeselector.pl?template=market&market=1a32ace7-7903-4e43-8013-f6a5a6805aaf";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=ae93802c-5a2f-47ab-9a65-e3110f895e1e"]               = "/_scripts/gradeselector.pl?template=market&market=1a32ace7-7903-4e43-8013-f6a5a6805aaf";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=ce477df0-6a5a-47b3-92fe-a3353e1cfc3c"]               = "/_scripts/gradeselector.pl?template=market&market=1a32ace7-7903-4e43-8013-f6a5a6805aaf";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=8bdff46f-a643-4a5c-9663-a636e62f3f3f"]               = "/_scripts/gradeselector.pl?template=market&market=1a32ace7-7903-4e43-8013-f6a5a6805aaf";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=2e33a6c8-eb54-4ebf-9ae3-85639975e805"]               = "/_scripts/gradeselector.pl?template=market&market=1a32ace7-7903-4e43-8013-f6a5a6805aaf";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=991db4bf-fe4c-4b1e-a479-0fb31d661c43"]               = "/_scripts/gradeselector.pl?template=market&market=1a32ace7-7903-4e43-8013-f6a5a6805aaf";


    // coating resins
    MyExceptionList["/markets/coating_resins/_en/index.pl?appl_id=8dcd3327-48d9-4f12-80be-f1cef7cd1434&appl_name=Coating%20resins"] = "/_scripts/gradeselector.pl?template=market&market=8dcd3327-48d9-4f12-80be-f1cef7cd1434";
    MyExceptionList["/markets/coating_resins/_en/index.pl?appl_id=8dcd3327-48d9-4f12-80be-f1cef7cd1434&appl_name=Coating resins"]   = "/_scripts/gradeselector.pl?template=market&market=8dcd3327-48d9-4f12-80be-f1cef7cd1434";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=538ece5b-d360-4fc1-935d-64ca590eab3e"]                       = "/_scripts/gradeselector.pl?template=market&market=8dcd3327-48d9-4f12-80be-f1cef7cd1434";
    MyExceptionList["/_scripts/gradeselector.pl?template=market&market=6cd530bb-3ad8-4566-bfad-80f1e603964f"]                       = "/_scripts/gradeselector.pl?template=market&market=8dcd3327-48d9-4f12-80be-f1cef7cd1434";


    if (typeof MyExceptionList[filename] != "undefined") {
        myAlternativeFileName = MyExceptionList[filename];
    }

    return myAlternativeFileName;
}
