(function($){
    function uinav() {
        var obj = $('.nav');

        if(obj.length > 0) {
            $('li', obj).hover(
                function() {
                    $('ul', $(this)).slideDown(0);
            },
                function() {
                    $('ul', $(this)).fadeOut(0);
                }
            );
        }
    }

    function uifooter() {
        var obj = $('#wrap');
        var minheight = 765;

        if(obj.css('min-height') > minheight) {
            obj.css('min-height', $(window).height());
        }
    }

    function uitoggle() {
        var obj = $('#moption-features');
        var clas = 'active';

        if(obj.length > 0) {
            $('dd', obj).hide();
            $('dt', obj).click(function(e) {
                e.preventDefault();
                if($(this).hasClass(clas)) {
                    $(this).removeClass(clas);
                }else {
                    $(this).addClass(clas);
                }
                $(this).next('dd').slideToggle();
            });
        }
    }

    function uistripe() {
        var obj = $('#moption-features');
        var clas ='stripe';

        if(obj.length > 0) {
            $('dt:odd', obj).addClass(clas);
        }
    }

    function uiwatermark() {
        var obj = {
            parent : $('#header form'),
            clear : $('#password-clear'),
            password : $('#password'),
            username : $('#Username')
        };

        if(obj.parent.length > 0) {
            obj.clear.show();
            obj.password.hide();
            obj.clear.focus(function() {
                $(this).hide();
                obj.password.show().focus();
            });
            obj.password.blur(function() {
                if($(this).val() == '') {
                    $(this).hide();
                    obj.clear.show();
                }
            });
            obj.username.focus(function() {
                if($(this).val() == $(this).attr('id')) {
                    $(this).val('');
                }
            });
            obj.username.blur(function() {
                if($(this).val() == '') {
                    $(this).val($(this).attr('id'));
                }
            });
        }
    }

    function uivalidate() {
        var obj = {
            form : $('#home-joinus form'),
            username : '#home-joinus #username',
            password : '#home-joinus #rpassword',
            cpassword : '#home-joinus #cpassword',
            email : '#home-joinus #email',
            aboutme : '#home-joinus #aboutme'
        }

        if(obj.form.length > 0) {
            /*
                $(obj.username + ',' + obj.aboutme + ',' + obj.password).blur(function() {
                    var clas = '.req';

                    if($(this).val() == '') {
                        $(this).next(clas).fadeIn();
                    }else {
                        $(this).next(clas).fadeOut();
                    }
                });

                $(obj.cpassword).blur(function() {
                    var clas = '.mis';

                    if($(this).val() != $(obj.password).val()) {
                        $(this).next(clas).fadeIn();
                    }else {
                        $(this).next(clas).fadeOut();
                    }
                });

                $(obj.email).blur(function() {
                        var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
                        var clas = '.inv';

                    if(filter.test($(this).val()) == false) {
                        $(this).next(clas).fadeIn();
                    }else {
                        $(this).next(clas).fadeOut();
                    }
                });
            */
        }
    }

    $(function(){
        uinav();
        uifooter();
        uitoggle();
        uistripe();
        uiwatermark();
        uivalidate();
    });
})(jQuery);
