﻿var CameraWidget = {

    _showImage: function(obj, sourceName, sourceLinkUrl) {
        ///<summary>
        /// Method used to display a camera image
        ///</summary>
        var imageUrl = obj.src;
        var elem = CameraWidget._createImageDiv(imageUrl, sourceName, sourceLinkUrl);
        LightBox.Show(elem, { top: 0, left: 0 });
    },

    _createImageDiv: function(imageUrl, sourceName, sourceLinkUrl) {
        ///<summary>
        // Creates the DIV used to display the image from one
        // of the road cameras.
        ///</summary>
        ///<param name="imageUrl">The URL to the image from the road camera</param>
        var leftPos = parseInt((document.viewport.getWidth() / 2) - 320);
        var topPos = parseInt((document.viewport.getHeight() / 2) - 240 + document.viewport.getScrollOffsets().top);

        // Fixes an error with lightbox positioning
        $("lightboxFrame").style.top = "0px";

        var newDiv = new Element('div', {
            'id': 'roadImage',
            'style': 'position: absolute; left: ' + leftPos + 'px; top: ' + topPos + 'px;'
        });

        newDiv.innerHTML = '<img style="width: 640px; height: 480px; border: solid black 1px;" src="' + imageUrl + '" alt=""/>' +
            '<div style="width: 642px; background: black; float:left; color: #F96A28;">' +
            '<div style="margin-left: 5px; float:left;">Kilde: <a style="color: #F96A28;" href="' + sourceLinkUrl + '" target="_blank">' + sourceName + '</a></div>' +
            '<div class="button" style="float:right; margin-right: 0px;">' +
            '<a href="#" class="button" onclick="LightBox.Hide(\'roadImage\', null); $(\'roadImage\').remove(); return false;"><span>Lukk</span></a>' +
            '</div>' +
            '</div>';

        return newDiv;
    }
}
