    var popupWidth;
    var popupHeight;
    var popupMarginLeft;
    var popupMarginTop;
    
    var buzzIndex = 0;
    
    var buzzVisible = false;
    var iconPopVisible = false;
    var backgroundDisabled = false;
    
    function showPopup(mediaId)
    {
        //Look up the media infomation
        var params = "mediaId=" + mediaId;
        myAjax = new Ajax.Request("/PopupContent.action", {method: 'post', parameters: params, asynchronous: false, onComplete: displayPopupData});
    }
    
    function showBuzz(mediaId)
    {
        var params = "mediaId=" + mediaId + "&coupons=true";
        myAjax = new Ajax.Request("/PopupContent.action", {method: 'post', parameters: params, asynchronous: false, onComplete: displayBuzzPopup});
    }

    function displayPopupData(request)
    {
        var response = request.responseText.evalJSON();
        var result = response.ajaxResult;
        if (result == 'error') 
        {
            alert("Error retrieving icon data.");
            return;
        }
        else
        {
            //If not already, display disabledBackground
            if (!backgroundDisabled)
            {
                //If IE6, hide <select> elements
                var browser = new BrowserObj;
                if (browser.client == "IE" && browser.version == "6")
                    showOrHideAllDropDowns("hidden");
                toggleBackground();
            }
            //Else, reset the disabledBackground IN FRONT of buzzworthy
            else    
                resetBackgroundZIndex(1002);
            
            //Reset popupwrapper
            var wrapperObj = document.getElementById("popup");
            wrapperObj.style.left = "50%";
            wrapperObj.style.top  = "50%";
            
            var width = response.width;
            var height = response.height;
      
            var htmlToDisplay = response.html;

            setDivCoordinates(width,height);
            var popupObj;
            
            popupObj = document.getElementById("popup");
            //Center the popup over the screen
            document.getElementById("infoPopup").style.width = popupWidth + "px";
            document.getElementById("infoPopup").style.height = popupHeight + "px";
            
            popupObj.style.position   = "fixed";
            popupObj.style.width      = popupWidth + "px";
            popupObj.style.height     = popupHeight + "px";
            popupObj.style.marginLeft = "-" + popupMarginLeft + "px";
            popupObj.style.marginTop  = "-" + popupMarginTop + "px";
            
            //Do some special stuff for IE6 (What's new)
            var is_ie6 = (window.external && typeof window.XMLHttpRequest == "undefined");
            if (is_ie6)
            {
                popupObj.style.position = "absolute"; 
                var relativeY = document.documentElement.scrollTop;
                popupObj.style.top = relativeY + (document.documentElement.clientHeight /2) + "px";
            }
            
            var popupContentObj = document.getElementById("innerPopupContent");
            popupContentObj.innerHTML = htmlToDisplay;
            popupObj.style.display = "block";
            iconPopVisible = true;
        }
    }
    
    function displayBuzzPopup(request)
    {
        var response = request.responseText.evalJSON();
        var result = response.ajaxResult;
        if (result == 'error') 
        {
            alert("Error retrieving Buzzworthy data.");
            return;
        }
        else
        {
            if (!backgroundDisabled)
            {
                //If IE6, hide <select> elements
                var browser = new BrowserObj;
                if (browser.client == "IE" && browser.version == "6")
                    showOrHideAllDropDowns("hidden");
                toggleBackground();
             }
            
            var width = response.width;
            var height = response.height;
      
            var htmlToDisplay = response.html;

            setDivCoordinates(width,height);
            var popupObj;
            
            popupObj = document.getElementById("buzzPopup");
            //Center the popup over the screen
            document.getElementById("buzzInfoPopup").style.width = popupWidth + "px";
            document.getElementById("buzzInfoPopup").style.height = popupHeight + "px";
            
            var buzzIcon = document.getElementById("buzzmore" + buzzIndex);
            
            popupObj.style.position   = "absolute";
            //Add 30 px for arrow graphic and talk-indicator
            popupObj.style.left      = (getXCoordinate(buzzIcon) + 38) + "px";
            popupObj.style.top       = (getYCoordinate(buzzIcon) - (popupHeight/2)) + "px";
            
            popupObj.style.width      = popupWidth + "px";
            popupObj.style.height     = popupHeight + "px";
            
            var popupContentObj = document.getElementById("innerBuzzContent");
            popupContentObj.innerHTML = htmlToDisplay;
            popupObj.style.display = "block";
            
            var talkObj = document.getElementById("talk");
            talkObj.style.left = (getXCoordinate(buzzIcon) + 20) + "px"; 
            talkObj.style.top = getYCoordinate(buzzIcon) + "px";
            talkObj.style.display = "block";
            buzzVisible = true;
        }
    }
        
    //****************************************************
    //  Moves the z-index reference of the disabled background
    //  in front or behind other objects, based on value provided.
    // ***************************************************
    function resetBackgroundZIndex(zindex)
    {
        var disabledPopup = document.getElementById("backgroundDisabled");
        disabledPopup.style.zIndex = zindex;
    }
    
    //****************************************************
    //  Does the math to figure out how big and where the
    //  the popup div should be.
    // ***************************************************
    function setDivCoordinates(width, height)
    {
        //Add 10px buffer on each side (for borders)
        popupWidth = parseInt(width) + 10 + 10;
        popupHeight = parseInt(height) + 10 + 10;
        
        //Add some height to accommodate for "close" link;
        popupHeight += 14;
        
        //Now, figure out margin adustments
        popupMarginLeft = (popupWidth / 2);
        popupMarginTop = (popupHeight / 2);
        
        return;
    }
    
    function closeIconPopup()
    {
        if (document.getElementById("popup") != null)
            document.getElementById("popup").style.display = "none";
        
        iconPopVisible = false;
        
        //If buzzworthy is up, dont re-enable background
        if (!buzzVisible)
        {
            //If IE6, re-show <select> elements
            var browser = new BrowserObj;
            if (browser.client == "IE" && browser.version == "6")
                showOrHideAllDropDowns("visible");
            toggleBackground();
        }
        //Else, reset the disabledBackground BEHIND buzzworthy
        else
            resetBackgroundZIndex(1000);
        
    }
    
    function closeBuzzPopup()
    {
        //If a coupon was added while buzzworthy was open, refresh the page
        if (aCouponWasAdded)
            document.location.reload();

        if (document.getElementById("buzzPopup") != null)
            document.getElementById("buzzPopup").style.display = "none";                
            
        if (document.getElementById("talk") != null)
            document.getElementById("talk").style.display = "none";
    
         buzzVisible = false;
    
        //If buzzworthy is up, dont re-enable background
        if (!iconPopVisible)
        {
            //If IE6, re-show <select> elements
            var browser = new BrowserObj;
            if (browser.client == "IE" && browser.version == "6")
                showOrHideAllDropDowns("visible");
            toggleBackground();
         }
    }
    
    function popupZipCode()
    {
        alert("By providing your zipcode, you may be entitled to even more discounts.");
    }
