﻿$(function () {
    $('#mainmenu a').live('mouseenter', function () {
        $(this).stop(true, true)
               .animate({ marginRight: '18px' }, 'fast')
               .parent().width(function (i, w) {
                   return w;
               });
    }).live('mouseleave', function () {
        $(this).stop(true, true)
               .animate({ marginRight: '8px' }, 'fast');
    });



    /* top dropdown menu */
    $('.dropdown > dt > a').click(function () {
        // Change the behaviour of onclick states for links within the menu.
        var toggleId = '#' + this.id.replace(/^link/, 'ul');

        // Hides all other menus depending on JQuery id assigned to them
        $('.dropdown dd ul').not(toggleId).hide();

        //Only toggles the menu we want since the menu could be showing and we want to hide it.
        $(toggleId).toggle();

        //Change the css class on the menu header to show the selected class.
        if ($(toggleId).css('display') == 'none') {
            $(this).removeClass('selected');
        } else {
            $(this).addClass('selected');
        }
        return false;
    });


    $('#linkglobal').one('click', function () {
        $('#accountinfo').text('تحميل..')
                             .load('/profile');
        return false;
    });


    $('.dropdown dd ul li a').click(function () {

        // This is the default behaviour for all links within the menus
        var text = $(this).html();
        $('.dropdown dt a span').html(text);
        $('.dropdown dd ul').hide();
    });

    $(document).bind('click', function (e) {

        // Lets hide the menu when the page is clicked anywhere but the menu.
        var $clicked = $(e.target);
        if (!$clicked.parents().hasClass('dropdown')) {
            $('.dropdown dd ul').hide();
            $('.dropdown dt a').removeClass('selected');
        }

    });
    //http://sammaye.wordpress.com/2010/01/23/facebook-style-css-jquery-drop-down-menus/
    /* end top dropdown menu */


    $('div.success')
        .live('click', function () {
            $(this).slideUp(function () {
                $(this).remove();
            });
        })
        .slideDown('fast');

    $('div.formentry').live('mouseenter', function () {
        $(this).css({ backgroundColor: '#f5f5f5' });
    }).live('mouseleave', function () {
        $(this).css({ backgroundColor: '#fff' });
    });
    $('textarea.noline').live('keypress', function (e) {
        if (e.which == 13) return false;
    });

    $('a', 'ul.listprofiles').live('mouseenter', function () {
        $('span', this).stop(true, true).slideDown('fast');
    }).live('mouseleave', function () {
        $('span', this).slideUp('fast');
    });








    $('#commentsform textarea').each(function () {
        var $that = $(this);
        if (!Modernizr.input.placeholder &&
            $that.val() == '' &&
            $that.attr('placeholder') != '')
            $that.val($that.attr("placeholder"));
        $that.focus(function () {
            if ($that.val() == $that.attr('placeholder') || $that.val() == '') {
                if (!Modernizr.input.placeholder) $that.val('');
                $that.stop(true, true).animate({ height: '60px' }, 'fast');
                $that.parent().find('input:submit').stop(true, true).fadeIn('fast');
            }
        }).blur(function () {
            if ($that.val() == '') {
                if (!Modernizr.input.placeholder) $that.val($that.attr('placeholder'));
                $that.stop(true, true).animate({ height: '30px' }, 'fast');
                $that.parent().find('input:submit').stop(true, true).fadeOut('fast');
            }
        });
    });

});
