function createImage(src) {
    var img = new Image();
    img.src = src;
    return img;
}

//------------------------------------------------------------------------
// Broadcast centre display events
//------------------------------------------------------------------------
// Build display a list of destinations for a broadcast centre
function BC_MouseOver(element) {
    var $a = $(element);
    var $aContainer = $a.parent();
    var $img = $a.find("img");
    var hdnBcDestinations = $aContainer.find("input").val();

    var id = $a.find("img").attr("id").replace(/\D/g, '');
    var popupId = 'bcPop' + id;

    var popup = Popup.getById(popupId);

    var watcher = null;

    if (!popup) {
        var list = document.createElement("ul");

        var destinations = Sys.Serialization.JavaScriptSerializer.deserialize(hdnBcDestinations);

        for (var i = 1; i < destinations.length; i++) {
            var li = document.createElement("li");
            li.innerHTML = destinations[i];
            list.appendChild(li);
        }

        var disableOwnEvents = true;
        popup = new Popup(popupId, destinations[0] + ' ' + BCTitle, list, 500, disableOwnEvents);
    }

    var popupPosition = Sys.UI.DomElement.getLocation(element);
    popupPosition.y += element.offsetHeight;
    popup.show(popupPosition);

    var frames = [];
    var $popup = $("#" + popupId);
    var position = $aContainer.offset();
    frames.push({ id: "container", left: position.left, top: position.top, width: $aContainer.width(), height: $aContainer.height() });
    position = $popup.offset();
    frames.push({ id: "popup", left: position.left, top: position.top, width: $popup.width(), height: $popup.height() });

    if (popup.WatcherIntervalId) {
        clearInterval(popup.WatcherIntervalId);
    }

    popup.WatcherIntervalId = setInterval(function () {
        var mouseX = window.mouseXPos;
        var mouseY = window.mouseYPos;

        var framesLen = frames.length;

        for (var i = 0; i < framesLen; i++) {
            var frame = frames[i];
            var yTop = frame.top - 10;
            var yBottom = frame.top + frame.height + 10;
            var xLeft = frame.left - 10;
            var xRight = frame.left + frame.width + 10;


            var xOk = mouseX > xLeft && mouseX < xRight;
            var yOk = mouseY > yTop && mouseY < yBottom;
            if (xOk && yOk) {
                return;
            }
        }

        clearInterval(popup.WatcherIntervalId);
        Popup.setSourceToPopupTimeout(50);
    }, 1500);
}

// Handle the out on a BC img
function BC_MouseOut() {
    //Popup.setSourceToPopupTimeout(5000);
}

