﻿var ll = null;

function showLockLayer(showHandler, clickHandler) {
    ll = Ekina.UI.createLockLayer(50, "black", function() {
        if (clickHandler) clickHandler();
    }, function() {
        if (showHandler) showHandler();
    }, true, .25);
};

function hideLockLayer() {
    if (!ll) return;

    ll.hide(.25);
};

function position(div, top) {
    div.style.left = ((window.document.body.offsetWidth / 2) - (div.offsetWidth / 2)) + "px";
    div.style.top = (document.documentElement.scrollTop + (top || 50)) + "px";
};

function showFlashDialog(swf, width, height) {
    showLockLayer(function() {
    _showFlashDialog(swf, width, height);
}, hideFlashDialog);
}

var flash_dialog;
var flash_content;
var flash_dialog_body;
//function _showImage(src, desc) {
function _showFlashDialog(swf, width, height) {

    flash_dialog = $("flash_dialog");
    flash_dialog_body = $("flash_dialog_body");
    flash_dialog.style.display = "block";

    flash_content = $('<div id="flash_content"></div>').appendTo(flash_dialog_body);

    swfobject.embedSWF(swf, flash_content.id, width, height, "9.0.0");
    

//    if ($("galleryFlash"))
//        swfobject.removeSWF("galleryFlash");
//    else
//        $('<div id="galleryFlash"></div>').appendTo($('largeImg_inner'));

//    if (el.href.contains(".flv")) {

//        swfobject.embedSWF("/_images/videoplayer.swf?path=" + el.href, "galleryFlash", "465", "261", "9.0.0");
//    } else {
//        swfobject.removeSWF("galleryFlash");
//        swfobject.embedSWF(el.href, "galleryFlash", "465", "262", "9.0.0");
//    }

    var flash_footer = $("flash_footer");
    
    flash_dialog.css("width", width + "px");
    flash_dialog.css("height", height + flash_footer.offsetHeight + "px");

    flash_dialog.fadeIn(100, .25);

    //var p = div.parentNode;

    position(flash_dialog);

    window.onresize = function() {
        position(flash_dialog);
    };
};

function hideFlashDialog() {
        
    flash_dialog.fadeOut(0, .25, function() {
        flash_dialog.hide();
        if (flash_dialog)
            swfobject.removeSWF(flash_content.id);
        hideLockLayer();
    });
    
    return false;
};

Ekina.Events.register(window, "ondomready", function() {

    // Create DIV Image markup
    var divDialog = $('<div id="flash_dialog"></div>').appendTo(document.body);
    var divContent = $('<div id="flash_dialog_body"></div>').appendTo(divDialog);
    //var divFlash = $('<div id="flash_content"></div>').appendTo(divContent);
    var divFooter = $('<div id="flash_footer"></div>').appendTo(divDialog);
    var closeLink = $('<a href="#" title="" onclick="hideFlashDialog();"><img src="/_images/closelabel.gif" alt="" /></a>').appendTo(divFooter);
    //$('<a href="#" onclick="return hideImage();"></a>').appendTo(divControls); //.innerHTML = "CLOSE";
});