/*
File: Popup.js
Created: MNH-06/21/2010
Description: This file contains for pop-up related functions

Modification History
MNH-07/02/2010 - Modified to support popup top position by container div as well
*/

// Show the Popup menu 
function ShowPopupMenu(buttonId, popupId, directionTop, directionLeft)
{
    // Set the button style and show the popup div
    $(buttonId).attr("class", "hoverbutton");
    
    // If left direction is given
    var marginLeft = 35;
    var marginTop = 85;
    
    if (directionLeft)
        marginLeft = directionLeft;
    
    // MNH-07/02/2010 - Check if top edge is given, use it; else use the top margin
    if (!directionTop)
        directionTop = $(buttonId).position().top - marginTop;
        
    $(popupId).css("top", directionTop);
    $(popupId).css("left", $(buttonId).position().left + $(buttonId).width() - marginLeft);
        
    $(popupId).show();
}

// Hide the popup menu
function HidePopupMenu(buttonId, popupId)
{
    $(buttonId).attr("class", "simplebutton");
    $(popupId).hide();
}

//this method is used to bind mouse-over and mouse-out methods with button and popup div
function bindPopupMouseEvents(btnId, popupId, top, left)
{
    if(!left)
        left = null;

    //binding button mouse-over and mouse-out functions
    $(btnId).mouseover(function() {ShowPopupMenu(btnId,popupId, top, left)});
    $(btnId).mouseout(function() {HidePopupMenu(btnId,popupId)});
    
    //binding popup-div mouse-over and mouse-out functions
    $(popupId).mouseover(function() {ShowPopupMenu(btnId,popupId, top, left)});
    $(popupId).mouseout(function() {HidePopupMenu(btnId,popupId)});
}
