/* jLightBox (using jQuery library).
*--------------------------------------------*
*  @author : ukhome ( ukhome@gmail.com | ntkhoa_friends@yahoo.com )
*--------------------------------------------*
*  @released : 24-Mar-2009 : version 1.0
*--------------------------------------------*
*  @revision history : ( latest version : 1.0 )
*--------------------------------------------*
*      + 24-Mar-2009 : version 1.0
*          - released
*--------------------------------------------*
*/

/* package $lightbox.IframeControl
*/

/*
* parent = $lightbox object
*/

$lightbox.IframeControl = function (parent, hash) {
    parent.popup.addClass("LightBoxPopupLoading");
    var iframe = jQuery("<iframe class=\"ContentLoader\"></iframe>");
    var url = parent.options.externalContent.replace(hash, "");
    if ( hash.toString().match(/width=[\d]+/) != null ) {
        var width = hash.toString().match(/width=[\d]+/).toString().match(/[\d]+/);
    }
    else { //120 : width/height not defined, so use the width/height of window screen minus 120
        var width = jQuery(window).width() - 120;
    }
    if ( hash.toString().match(/height=[\d]+/) != null ) {
        var height = hash.toString().match(/height=[\d]+/).toString().match(/[\d]+/);
    }
    else {
        var height = jQuery(window).height() - 120;
    }
    parent.popup.css({
        width: width + "px",
        height: height + "px"
    });
    iframe.attr({
        width: width,
        height: height,
        frameBorder: 0,
        scrolling: "auto",
        allowtransparency: "yes",
        src: url
    });
    iframe.css({
        visibility: "hidden"
    });
    parent.popupContent.empty().html(iframe);
    iframe.bind("load", function () {
        parent.popup.removeClass("LightBoxPopupLoading");
        iframe.css({
            visibility: "visible"
        });
    });
    if ( parent.options.closeBtn != null ) {
        parent.popup.prepend(parent.options.closeBtn);
        parent.options.closeBtn.bind("click", function () {
            parent.hideLightBox();
            return false;
        });
    }
    parent.overlays.show();
    parent.popup.show().center();
}