TryItLinkControlMulti = function() {
    // CONSTRUCTOR: Sets event handlers.
    // DO NOTHING
}

TryItLinkControlMulti.prototype = {

    // Initializes the bookmarking control.
    Initialize: function(parent, control, projectName) {

        if ($.browser.safari) {
            // Safari bug fix: Delay resize event to give the page a chance to update.
            $(window).resize(
    function() {
        if (typeof (control) != 'undefined')
            window.setTimeout(control.Reposition, 1);
    }
   );
        } else {
            $(window).resize(function() {
                if (typeof (control) != 'undefined')
                    control.Reposition(control, projectName);
            });
        }

        $(document).click(
   function() {
       if (typeof (control) != 'undefined') {
           if (!control.hasFocus)
               control.TogglePopup("hide", control, projectName);
       }
   }
  );
        $(document).keypress(
   function(eventObject) {
       if (typeof (control) != 'undefined') {
           if (eventObject.keyCode == 27) // 'Esc' key.
               control.TogglePopup("hide", control, projectName);
       }
   }
  );

        $("#cdTryItPopup_" + projectName).hover(
   function() {
       control.hasFocus = true;
   },
   function() {
       control.hasFocus = false;
   }
  );


        //        $("#cdTryItExpandLink").click(
        //   function() {
        //       $("#cdTryItMinimizeButton").show();
        //       $("#cdTryItExpandButton").hide();
        //       $("#cdTryItExpandedSites").slideDown("normal");
        //   }
        //  );
        //        $("#cdTryItMinimizeLink").click(
        //   function() {
        //       $("#cdTryItExpandedSites").slideUp("normal", function() {
        //           $("#cdTryItMinimizeButton").hide();
        //           $("#cdTryItExpandButton").show();
        //       });
        //   }
        //  );

        // Clone the bookmarking control, and place it into the parent element.
        control.elem = $("#cdTryIt_" + projectName).clone();
        control.elem.appendTo(parent);

        // Initialize the bookmarking control events.
        control.elem.click(
    function(eventObject) {
        control.elem = $(this);
        control.TogglePopup("", control, projectName);
    }
   );
        control.elem.hover(
    function() {
        control.hasFocus = true;
    },
    function() {
        control.hasFocus = false;
    }
   );

        // Initialize the show/hide states of the control.
        //        $("#cdTryItExpandedSites").hide();
        //        $("#cdTryItMinimizeButton").hide();
        //        $("#cdTryItExpandButton").show();

        control.elem.css("display", "inline");
    },

    // Toggles the popup.
    TogglePopup: function(state, control, projectName) {
        if (!control.toggling) {
            control.toggling = true;

            if (typeof (state) == 'undefined' || (state != "show" && state != "hide"))
                state = "toggle";

            var newLeft = control.hideLeft;
            if ($("#cdTryItPopup_" + projectName).css("display") == "none") {
                control.Reposition(control, projectName);
                newLeft = control.showLeft;
                $("#cdTryItPopup_" + projectName).css("left", control.hideLeft);
            }

            $("#cdTryItPopup_" + projectName).animate({
                left: newLeft,
                height: state,
                width: state,
                opacity: state
            }, "normal", function() { control.toggling = false; });
        }
    },

    // Re-position the bookmarking popup to line-up with the bookmarking button.
    Reposition: function(control, projectName) {
        var links = control.elem;
        if (typeof (links) != 'undefined') {
            var popup = $("#cdTryItPopup_" + projectName);
            var c = $("#cdTryItControl_" + projectName);

            // make sure popup was found on page
            if (null == popup || typeof (popup) == 'undefined') {
                return;
            }

            popup.css("position", "absolute");

            var offset = popup.offset();
            var popupWidth = popup.width();

            control.showLeft = offset.left + 230;
            control.hideLeft = offset.left + 230;
           
            if (navigator.userAgent.match(/firefox/i)) {
                control.showLeft = c.offset().left - 230;
                control.hideLeft = c.offset().left - 230;

                popup.css("left", control.showLeft);
                popup.css("top", c.offset().top + 13);
            }
            else if (navigator.userAgent.match(/safari/i)) {
                if (popup.css("display") != "none")
                    popup.css("left", control.showLeft);

                popup.css("top", c.offset().top - 47);
            }
            else {
                if (popup.css("display") != "none")
                    popup.css("left", control.showLeft);

                popup.css("top", c.offset().top - 60);
            }
        }
    },

    // Move the control to the specified parent, and set a new bookmarking asset.
    Reset: function(parent) {
        this.Initialize(parent);
    }
}