$(document).ready(function(){
    $('#user-menu li a').click(function(){
        var which = $(this).attr('id');
        if($(this).hasClass('active')){ //same link, close it
            $('#wrap_user-panel').animate({
                top: -160
            }, 300, function(){
                $(this).removeClass('extended');
                $('#' + which).removeClass('active');
            });
        }else{  // different link
            if($('#wrap_user-panel').hasClass('extended')){
                $('#user-menu li a').each(function(){
                    $(this).removeClass('active');
                })
                $('#' + which).addClass('active');
                //////////// load data /////////////////////////////
                var url =  '/sparty/index/panel';
                var data = '';

                    $.ajax({
                       type: 'GET',
                       url: url,
                       data: data,
                       timeout: 5000,
                       success: function(content){
                           alert('Returning from ajax!');
                       },
                       error: function (XMLHttpRequest, textStatus, errorThrown) {
                               alert('Connectivity Issue : '+textStatus + ' Error : '+errorThrown + ' Response : '+XMLHttpRequest.responseText);
                       }
                    });
                /////////////// end load data
            }else{
                // drop down
                $('#wrap_user-panel').animate({
                    top: 54
                }, 600, function(){
                    $(this).addClass('extended');
                    $('#' + which).addClass('active');
                    //////////// load data /////////////////////////////
                var url =  '/sparty/index/panel';
                var data = '';

                    $.ajax({
                       type: 'GET',
                       url: url,
                       data: data,
                       timeout: 5000,
                       success: function(content){
                           alert('Returning from ajax!');
                       },
                       error: function (XMLHttpRequest, textStatus, errorThrown) {
                               alert('Connectivity Issue : '+textStatus + ' Error : '+errorThrown + ' Response : '+XMLHttpRequest.responseText);
                       }
                    });
                /////////////// end load data
                });
            }
        }
    });
});
