/**
 * Shows elements inline or in a FancyBox if the <code>show</code> option is set to <code>true</code>.
 * @class dtShowBox
 **/

/**
 * Specifies the elements(s) which should be shown if the conditions are met.
 * @config selector
 * @type string
 **/

/**
 * Whether the content should be shown.
 * @config show
 * @type boolean
 **/

/**
 * Whether the link should be opened in a FancyBox.
 * @config useFancyBox
 * @type boolean
 **/

/*jslint strict:false, plusplus:false*/
/*global DT:false*/

DT.CORE.register('dtShowBox', function (io, $) {
    var my = {
        fancy: function (options) {
            $.fancybox({
                href: options.selector,
                onClosed: function () {
                    $(options.selector).hide();
                },
                onComplete: function () {
                    var box = $('#fancybox-content'),
						c = box.children('div');
                    if (box.width() >= c.width() && box.height() >= c.height()) {
                        c.css('overflow', 'hidden');
                    }
                }
            });
        }
    };
    return {
        initEach: function (options) {
            if (DT.TOOLKIT.isBE) {
                $(options.selector).show();
                return;
            }
            if (options.show) {
                $(options.selector).show();

                if (options.styleClasses != "")
                    $(options.selector).addClass(options.styleClasses);

                if (options.useFancyBox) {
                    my.fancy(options);
                }
            }
        }
    };
});
