/**
 * Simple Modal Window for RPX Login
 * @author  Viodele <viodele@gmail.com>
 **/
var esthetic = {
    window:     {
        open : function(data) {
            if(!data.layer) {
                return false;
            }
            var width       = data.width ? data.width : 320;
            var height      = data.height ? data.height : 320;
            var layer       = data.layer;
            var title       = data.title ? data.title : '';
            var code = Number(new Date()) + 'esth' + Math.floor(Math.random()*10000001);

            if($(layer).attr('title') != '') {
                title = $(layer).attr('title');
            }

            $(layer).addClass('source-of-' + code);
            var embedCode = $(layer).html();
            $(layer).html('');

            var embed = '<div class="esthetic-window-modality code-' + code + '"></div>';

            embed += '<div class="esthetic-window source-code-' + code + '" style="'
                + 'top:' + parseInt(($(document).height() - height) / 2) + 'px; '
                + 'left:' + parseInt(($(document).width() - width) / 2) + 'px; '
                + 'height:' + height + 'px; '
                + 'width:' + width + 'px; '
                + '">';

            embed += '<div class="esthetic-window-close code-' + code + '" onclick="esthetic.window.close(\'' + code + '\');" title="Close"></div>';
            embed += embedCode + '</div>';

            document.body.innerHTML += embed;

            $('.esthetic-window').animate({opacity: 0}, 0, 'easeOutBack').animate({opacity: 1}, 4000, 'easeOutBack');

            return code;
        },
        close : function(data) {
            try {
                $('.code-' + data).remove();
                
                var source = $('.source-code-' + data).html();
                $('.source-code-' + data).remove();

                $('.source-of-' + data).html(source);
                $('.source-of-' + data).removeClass('source-of-' + data);
            } catch (e) {
                return false;
            }
            return true;
        }
    }
}

var RPX_WINDOW_MODAL = false;

$(document).ready(function(e) {
    if(window.location.hash != '') {
        $('#loginfrm').append('<input type="hidden" name="hashed-direction" value="' + window.location.hash + '" />');
    }
    $('#rpxLoginAction').live('click', function() {
        window.RPX_WINDOW_MODAL = window.esthetic.window.open({
            layer:  '#rpx-entrance-form',
            width:  405,
            height: 325
        });
        return false;
    });
});


