
// OnLoad actions
$().ready(function(){
    // Hide all synopsis
    var jSynopsises = $("div.arrowsynopsis");
    jSynopsises.children("div").hide();
    // Subscribe to synopsis links
    jSynopsises.children("a").click(function(eventObj){
        // Show/hide the div
        var isDivVisible = $(this).parent().children("div").is(":visible");
        if (isDivVisible)
        {
            CloseSynopsis(this);
        }
        else
        {
            OpenSynopsis(this);
        }
    });
    
    // Init the CloseAllSynopsisLink and OpenAllSynopsisLink
    var jCloseAllSynopsisLink = $("#CloseAllSynopsisLink");
    var jOpenAllSynopsisLink = $("#OpenAllSynopsisLink"); 
    if (jSynopsises.size() == 0)
    {
        jCloseAllSynopsisLink.hide();
        jOpenAllSynopsisLink.hide();
    }
    else
    {
        jCloseAllSynopsisLink.hide().click(function(eventObj){
            jSynopsises.each(function(){
                if ($(this).children("div.arrowsynopsiscontent").is(":visible"))
                {
                    $(this).children("a").click()
                }
            });
            jCloseAllSynopsisLink.hide();
            jOpenAllSynopsisLink.show();
        });
        jOpenAllSynopsisLink.hide().show().click(function(eventObj){
            jSynopsises.each(function(){
                if ($(this).children("div.arrowsynopsiscontent").is(":hidden"))
                {
                    $(this).children("a").click()
                }
            });
            jCloseAllSynopsisLink.show();
            jOpenAllSynopsisLink.hide();
        });
    }
    
    // Open synopsis if the url contains anchor inside synopsis
    OpenSynopsisWithNeedAnchor(document.location.href);
    
    $("a").add("area").click(function(eventObj){
        OpenSynopsisWithNeedAnchor(this.href);
    });
    
    // If the page is Interface Overview
    var jMapTextObjects = $("div.maptextobject");
    if (jMapTextObjects.size() > 0)
    {
        jMapTextObjects.filter(":eq(0)").show();
        jMapTextObjects.filter(":gt(0)").hide();
    }
})

////////////////////////////////////////////////////////
// Common function
/*
* Open synopsis with anchor that specify in url
*/
function OpenSynopsisWithNeedAnchor(url)
{
    var startPos = url.lastIndexOf("#");
    if (startPos == -1) 
    {
        return;
    }
    var anchorName = url.substring(startPos + 1, url.length);
    if (anchorName == "") 
    {
        return;
    }
    $("div.arrowsynopsis").each(function(){
        if ($(this).find("a[name=" + anchorName + "]").size() > 0)
        {
            OpenSynopsis($(this).children("a").get(0))
        }
    })
}

function OpenSynopsis(aElement)
{
    // Show/hide the div
    var isDivVisible = $(aElement).parent().children("div").show();
    // change img
    $(aElement).children("img").attr("src", "img/down.png");
}

function CloseSynopsis(aElement)
{
    // Show/hide the div
    var isDivVisible = $(aElement).parent().children("div").hide();
    // change img
    $(aElement).children("img").attr("src", "img/right.png");

}

/*
* Map onmouseover handler
*/
function Map_OnMouseOver(selectId, imgName)
{
    $("div.maptextobject").hide().filter("#" + selectId).show();
    $("img[name=" + imgName + "]").attr("src", "img/" + selectId + ".png");
}

/*
* Map onmouseout handler
*/
function Map_OnMouseOut(imgName)
{
    var jMapTextObjects = $("div.maptextobject");
    jMapTextObjects.filter(":eq(0)").show();
    jMapTextObjects.filter(":gt(0)").hide();
    $("img[name=" + imgName + "]").attr("src", "img/" + imgName + ".png");
}

