function LeoDistribution(id_input, id_border, id_distrib_button){
    this.focus_mail = 0;
    this.id = id_input;
    this.id_border = id_border;
    this.id_distrib_button = id_distrib_button;
    this.default_text = 'E-mail';
    var context = this;

    var jloader_distrib = new JLoader({
        onGetData : function(data){
           if(!data.error){
               //$('#ok_distrib').find('.window_title h1').html('Спасибо!');
               //$('#ok_distrib').find('.window_text').html('Вы успешно подписались на обновления.');
               $('#ok_distrib').fadeIn("slow", function(){
                   $(this).delay(3000);
                   $(this).fadeOut("slow");
               });
                //hint.showMessage("Спасибо!", "Вы успешно подписались на обновления11.");
           }else
                hint.showMessage('Ошибка!', 'Ошибка подписки!');
        }                    
    }, "");
    
    this.applyDistr = function(){
        var conf = new Object;
        conf.text = $("#"+id_input).attr('value');
        
        $("#"+id_input).attr('value', 'E-mail');
        context.fadeEffectForMail();
        
        jloader_distrib.getSomeData(conf, "scripts/add_mail.php", null);
    }
    
    this.cancelDistr = function(){
        $("#"+id_input).attr('value', 'E-mail');
        context.fadeEffectForMail();
    }
    
    var hint = new ContextPanels(this.applyDistr, this.cancelDistr);
    this.hint = hint;
    
    $("#"+this.id).attr('value', this.default_text);
    
    $('#'+this.id).bind('focus', {eto : this}, HFocusDistribution);
    $('#'+this.id).bind('blur', {eto : this}, HBlurDistribution);
    $('#'+this.id_distrib_button).bind('click', {eto : this}, HClickDistribution);
    
    $('body').delegate("#"+this.id, "hover", {eto : this}, function(eventObj){
        if(eventObj.type === 'mouseenter'){
            $(this).stop().animate({color : 'white'}, 1000);
        }else{
            if(eventObj.data.eto.focus_mail == 1)
                return;
            if(($(this).attr('value') != "") && ($(this).attr('value') != eventObj.data.eto.default_text))
                return;
            $(this).stop().animate({color : '#393939'}, 1000);
        }            
    });

    $('body').delegate("#"+this.id_border, "hover", {eto : this}, function(eventObj){
        if(eventObj.type === 'mouseenter'){
            if(($("#"+eventObj.data.eto.id).attr('value') != "") && ($("#"+eventObj.data.eto.id).attr('value') != eventObj.data.eto.default_text))
                return;
            $(this).stop().css({backgroundPosition : 'left -31px', opacity : '0.3'}).animate({opacity : '1'}, 2000);
        }else{
            eventObj.data.eto.fadeEffectForMail();
        }
    });
    
    $('#'+this.id_distrib_button).hover(function(){
        $(this).stop().css({backgroundPosition : 'left -25px', opacity : '0.3'}).animate({opacity : '1'}, 2000);
    }, function(){
        $(this).stop().css({backgroundPosition : 'left -25px', opacity : '1'}).animate({opacity : '0'}, 2000, 
            function(){
                $(this).css({backgroundPosition : 'left 0px', opacity : '0.1'}).animate({opacity : '1'}, 1000);
            });
    });
    
    function HClickDistribution(eventObj){
        var text = $("#"+eventObj.data.eto.id).attr('value');        
        if(!((text != "") && (text != eventObj.data.eto.default_text) && isValidEmailAddress(text))){
            eventObj.data.eto.hint.showMessage('Ошибка!', 'Вы не ввели собственный почтовый адресс либо он некорректный!');
            return;
        }else{
            eventObj.data.eto.hint.showQuestionPanel("Подписка на обновления", "Вы точно хотите подписаться на обновления по e-mail?");
        }  
    }
        
    function HFocusDistribution(eventObj){
        if($(this).attr('value') == eventObj.data.eto.default_text)
            $(this).attr('value', "");
        eventObj.data.eto.focus_mail = 1;
    }
    
    function HBlurDistribution(eventObj){
        if($(this).attr('value') == ""){
            $(this).attr('value', eventObj.data.eto.default_text);
            $(this).stop().css({color : '#393939'});
        }
        eventObj.data.eto.focus_mail = 0;
        eventObj.data.eto.fadeEffectForMail();
    }
    
    this.fadeEffectForMail = function(){
        if(($("#"+this.id).attr('value') != "") && ($("#"+this.id).attr('value') != this.default_text))
            return;
        if(this.focus_mail)
            return;
        $("#"+this.id_border).stop().css({backgroundPosition : 'left -31px', opacity : '1'}).animate({opacity : '0.2'}, 2000, function(){
            $(this).css({backgroundPosition : 'left 0px', opacity : '0.8'}).animate({opacity : '1'}, 2000);
        });
    }
}
