jQuery.noConflict();

(function($) {
    $(function() {
        $('#member_name').blur(function() {
            name = $(this).val();
            if($('#member_username').val() == '')
                $('#member_username').val(name);
        });
        
        //  block sending change pwd form
        $(window).load(function() {
            $('input.savepwd').attr('disabled', 'disabled');
            $('input.savepwd').css('cursor','default');
            $('.conf_check').hide();
            $('#change_old_password').focus();
        });
        
        // compare passwords
        $('#change_old_password, #change_password, #change_password_confirmation').keyup(function() {
            pwd_verification();
        });
        $('input.savepwd').click(function(){ pwd_verification(); });
        
        function pwd_verification() {
            //  strength w. feedback
            var feedback = passwordStrength($('#change_password').val(), $('#member_username').val());
            if($('#change_password').val().length > 0)
                $('#pwdcheck_result').attr('class','').text(feedback[1]).addClass(feedback[0]);
                            
            if(($('#change_old_password').val() !== '' && $('#change_password').val() !== '' && $('#change_password').val() == $('#change_password_confirmation').val()) && feedback[0] !== "short") {
                $('input.savepwd').removeAttr('disabled');
                $('input.savepwd').css('cursor','pointer');
            } else {
                $('input.savepwd').attr('disabled', 'disabled');
                $('input.savepwd').css('cursor','default');
            }            
        }
        
        //  confirmation is ok
        $('#change_password_confirmation').keyup(function() {
           if($(this).val() != $('#change_password').val() && $(this).val() != '') {
               $('.conf_check').show();
           } else {
               $('.conf_check').hide();
           }
        });
                
        //  clear old password mismatch message
        $('#change_old_password').keypress(function() {
            $(this).next('.error').hide();
        });
        
        
        //  bulletin
        $('form input[name="save_bulletin"]').click(function() {
            if($('#clipboard_upload_doc').val() != '' || $('#clipboard_upload_photo').val() != '' || $('#clipboard_upload_podcast').val() != '') {
                setTimeout(function () { $('div.save_footer').show(); }, 2000);
            }
        });
        
        //  limit title input
        $('textarea.title').keyup(function() {
            var limit = 200;
            var input = $(this).val();
            if(input.length > limit) {
                $(this).val(input.substring(0, limit));
            }
        });
        
        //  teaser site
        if($('.teaser #showbox').length > 0) {
            equalHeight($("#showbox").children());
            $('.teaser #showbox').innerfade({ 
                speed: 'slow', 
                timeout: 4000, 
                type: 'sequence', 
                containerheight: $('.show:first', this).height()
            });
        }

        function equalHeight(group) {
            tallest = 0;
            group.each(function() {
                thisHeight = $(this).height();
                if(thisHeight > tallest) {
                    tallest = thisHeight;
                }
            });
            group.height(tallest);
        }
        
    });
}) (jQuery);