﻿// JScript File

var prevId;
// Expands toggle an div with specified id 
function SlideDown(id) 
{
    // Closing the prev menu, if it is not the current menu, and if it is opened
    if ((prevId != id) && ($("#subMenuItems_"+prevId).css("display") == "block"))
    {
        $("#subMenuItems_"+prevId).slideUp("fast");
        $("#menuItem_"+prevId + " .plus").toggle();
        $("#menuItem_"+prevId + " .minus").toggle();
    }

    $("#menuItem_"+id + " .plus").toggle();
    $("#menuItem_"+id + " .minus").toggle();
    $("#subMenuItems_"+id).slideToggle("fast");
    prevId = id;
    
}

function AddMainLink()
{
    window.open("http://www.google.co.il");
}


function GenerateLink(mainMenuId, hasSubMenu)
{

    if(hasSubMenu == true)
    {
        SlideDown(mainMenuId);
    }
    else
    {
        AddMainLink(mainMenuId);
    }
    
    
    
}


//-----------------------------------------------------------------------
window.onload = function()
    {
        OpenMenuAndMakeSiteMap();
        ss.load();//this line - only to load the newsticker
    }

// Expanding the current's page menu
function OpenMenuAndMakeSiteMap()
{
    var SiteMap = "";
    var sPath = document.URL;
    sPath = sPath.replace("#"," ");
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
    
    var HomeNode = "<a href='Index.aspx'>דף הבית</a>"
    var Seperator = '&nbsp;&nbsp;' + ">>" +'&nbsp;&nbsp;';
    
    // Going over all the menus
    $("span.menuStyle span").each(
        function()
        {
            if($(this).parent().parent().attr("href") == sPage)
            {   
                SiteMap+=Seperator;
                SiteMap+=$(this).html();
            }
        }
    );
    
    // Going over all the SubMenus
    $(".menuItem a").each(
        function()
        {
            if($(this).attr("href") == sPage)
            {
                $(this).css("color", "Red");
                $(this).parent().css("display","block");
                // Changing the + to -
                $(this).parents(".MenuItemsSet").children("a span.menuStyle").find("span img").toggle();
                $(this).parent().parent()
                var fullId = $(this).parent().attr("id"); // Setting this menu item as the prev expanded menu, so it will be closed when another opened
                var splitString=fullId.split('_');
                prevId = splitString[1];
                var text = $(this).parents(".MenuItemsSet").children("a span.menuStyle").find("span").find("span").html();
                var link = $(this).parents(".MenuItemsSet").children("a").attr("href");
                
                // Adding the MenuItem
                SiteMap+=Seperator;
                SiteMap+= "<a href="+link+">"+text+"</a>"
                
                // Adding the SubMenuItem
                SiteMap+=Seperator;
                SiteMap+=$(this).html();
            }
        }
    );
    
    // If SiteMap is not empty, we overrifde the .NET's SiteMapPath
    if(SiteMap != "")
    {
        // Injecting the SiteMap to it's place
        $("#SiteMapPath").html(HomeNode+SiteMap);
    }
}

 

