/*
 * AuthPopup
 * @author Gennadiy Ukhanov
 * @version 0.0.1
 * @build 2 (15/08/2011 15:18 AM)
 */
(function(_global){

    var $ = jQuery;
    /**
     * @namespace BackToTop
     * @name BackToTop
     */
    AuthPopup = {

        /**
         * @public
         * @param {_el} jquery dom link
         */
        create : function() {
            this._destroy();
            this._build();
            this._attach();
        },
		
        /**
         * @private
         * _build
         */
        _build : function () {

            this.popupTemplate
                .removeClass('hidden')
                .hide()
                .fadeIn(this.FADE_IN);

            if(this.isRemeberEmail) {
                this._rememberEmail();
            }
            
            this.popupBackground.removeClass('hidden').hide().fadeIn(this.FADE_IN);
        },

        _rememberEmail : function () {
            //console.log(this.popupTemplate.find('#email').val());
        },
		
        /**
         * @private
         * _attach
         */
        _attach : function () {
            jQuery('.b-close').click(jQuery.proxy(this, '_destroy'))
        },			

        /**
         * @private
         * Remove modificator
         */
        _destroy : function () {
            jQuery('.b-popup').hide();
            this.popupBackground.hide().addClass('hidden');
            return false;
        }
    }


    /**
     * Constructor
     */
    _global = AuthPopup;
    _global.body =  $('body');
    _global.popupBackground = $('.b-popup-wrap');
    _global.isRemeberEmail = false;
			

})(window || this);

jQuery.noConflict();
jQuery(document).ready(function(){
    
    AuthPopup.FADE_IN = 300;

    function createSignIn() {
        AuthPopup.popupTemplate = jQuery('.sign_in');
        AuthPopup.create()
        return false;
    }

    function createLogIn() {
        AuthPopup.popupTemplate = jQuery('.log_in');
        AuthPopup.create()
        return false;
    }

    function createForgotPassword() {
        var email = (jQuery('#email').val());
        AuthPopup.popupTemplate = jQuery('.forgot_password');
        AuthPopup.isRemeberEmail = true;
        AuthPopup.create()
        AuthPopup.popupTemplate.find('#email').val(email);
       
        return false;
    }

    jQuery('.sign_bar_key').bind('click', createSignIn);
    jQuery('.sign_bar_lock').bind('click', createLogIn);
    jQuery('.b-forget-pswd').bind('click', createForgotPassword);

    
});




