﻿function showHide(element_id) {

    if (document.getElementById && document.getElementById(element_id) && document.getElementById(element_id).style) {

        var menu = document.getElementById(element_id);
        var arrow = document.getElementById(element_id + '_arrow');
        var title = document.getElementById(element_id + '_arrow');
        var style = "";

        if (menu.style.display == "") {
            if (element_id == "explore") {
                style = "none";
            }
            else
                style = "block";
        }
        else {
            style = menu.style.display;
        }

        if (style == "block") {
            menu.style.display = "none";
            if (arrow.src) { arrow.src = arrow.src.replace("down", "right"); }
            if (title.title) { title.title = title.title.replace("Close", "Open"); }
        }
        else {

            menu.style.display = "block";
            if (arrow.src) { arrow.src = arrow.src.replace("right", "down"); }
            if (title.title) { title.title = title.title.replace("Open", "Close"); }
        }
    }
    return false;
}

$(document).ready(function () {

    var availableTags = document.getElementById('ctl00_hfAutoCompleteList').value.split(',');

    $(".searchBox").autocomplete({
        source: availableTags
    });



    //Control show or hide the child menu 
    $("ul.menu").each(function () 
    {
        var selectedNavItems = $(this).find("a.selected");

        if ($(this).parent().find('div.mygovt').html() != null) 
        {
            $(this).hide();
            $(this).parent().find("img").attr("src", "/Style Library/FSCO/Internet/images/arrow_right.gif");
            $(this).parent().find("img").attr("title", "Open Menu");
        }
        else
        {
            if (selectedNavItems.length > 0) 
            {
                $(this).show();
                //alert( $(this).parent().find("img").parent().html());
                $(this).parent().find("img").attr("src", "/Style Library/FSCO/Internet/images/arrow_down.gif");
                $(this).parent().find("img").attr("title", "Close Menu");
            }
            else 
            {
                $(this).hide();
                //alert( $(this).parent().find("img").parent().html());
                $(this).parent().find("img").attr("src", "/Style Library/FSCO/Internet/images/arrow_right.gif");
                $(this).parent().find("img").attr("title", "Open Menu");
            }
        }
    });

    // if the current nav node is marked as 'selected' show it's following sibling - i.e. the div containing all nav sub-nodes
    $('div.selected').next().show();


    // remove href link for anchor and might have to change its style as regular text
    // Sample <a name="book1" id="book1" href="/anchor">anchor here</a>
    $("div.caption a").each(function () {
        if ($(this).attr("href") == "/anchor") {
            //alert("Control before: " + $(this).parent().html());
            $(this).removeAttr("href");
            $(this).removeAttr("id");

            $(this).attr("style", "text-decoration: none; color:black");
            //alert("Control after: " + $(this).parent().html());
        }
    });

    // Trim down spelling check options
    if (typeof (spellcheck) != "undefined") {
        var splitString = document.location.href.split('/');
        var serverUrl = 'http:\/\/' + splitString[2] + '\/';

        spellcheck = { 'defaultLanguage': 1033, 'languages': [{ 'lcid': 1033, 'name': 'English - United States' }, { 'lcid': 1036, 'name': 'French - France'}], 'siteUrl': serverUrl };
    }


    if (typeof (document.getElementById('ctl00_hdPageTitle')) != "undefined") {
        if (document.getElementById('ctl00_hdPageTitle') != null) {
            if (document.getElementById('ctl00_hdPageTitle').value != '') {
                var newTitle = document.getElementById('ctl00_hdPageTitle').value;
                $("div.ms-bodyareacell > div#ctl00_MSO_ContentDiv > h1").text(newTitle);
                $(".breadcrumbCurrentNode").text(newTitle);
            }
        }
    }


});

