//JS Object : update the cart by ajax actions
var ajaxSearch = {
    // try to show search container
    show : function(){
        $("#search_block" + sTemplate).css('display', 'block');
    },
    
    // try to expand the search
    expand : function(bOverwrite){
        if ($('#search_block_list').hasClass('collapsed') || bOverwrite == true) {
            $('#search_block_expand').fadeOut('fast');
            $('#search_block_summary').slideUp(500, function() {
                $("#search_block" + sTemplate).addClass('search_block_pos').removeClass('search_block_pos2');
                $(this).addClass('collapsed').removeClass('expanded');
                $('#search_block_list').slideDown({
                    duration: 600,
                    complete: function(){
                        $(this).addClass('expanded').removeClass('collapsed');

                        // toogle the button expand/collapse button
                        $('#search_block_form').fadeIn('slow');
                        $('#search_block_collapse').fadeIn('slow');
                    }
                });
            });


            /* save the expand status in the user session
            // naaah, no need to save status. should be closed most of the time
            $.ajax({
                type: 'GET',
                url: 'includes/modules/mod_search_session.php',
                async: true,
                data: 'set_search=expand' + '&' + sSessionName + '=' + sSessionId + '&rand=' + new Date().getTime()
            });
            */
        }
    },
	
    // fix display when using back and previous browsers buttons
    refresh : function() {
        // return
        return true;
    },
	
    // try to collapse the cart
    collapse : function(bFast) {
        if ($('#search_block_list').hasClass('expanded')) {
            $('#search_block_collapse').fadeOut('fast');
            $('#search_block_form').fadeOut('fast');

            $('#search_block_list').slideUp('slow', function(){
                $("#search_block" + sTemplate).addClass('search_block_pos2').removeClass('search_block_pos');
                $(this).addClass('collapsed').removeClass('expanded');
                if(bFast == true) {
                    $('#search_block_summary').slideDown(50, function(){
                        $(this).addClass('expanded').removeClass('collapsed');
                        $('#search_block_form').fadeOut('fast');
                        $('#search_block_expand').fadeIn('slow');
                    });
                } else {
                    $('#search_block_summary').slideDown(700, function(){
                        $(this).addClass('expanded').removeClass('collapsed');
                        $('#search_block_expand').fadeIn('slow');
                    });
                }
            });
            
            /* save the expand status in the user session
            // naaah, no need to save status. should be closed most of the time
            $.ajax({
                type: 'GET',
                url: 'includes/modules/mod_search_session.php',
                async: true,
                data: 'set_search=collapse' + '&' + sSessionName + '=' + sSessionId + '&rand=' + new Date().getTime()
            });
            */
        }
    }
}

//when document is loaded...
$(document).ready(function(){
    // expand/collapse management
    $('#search_block_collapse').click(function(){
        ajaxSearch.collapse();
    });
    $('#search_block_expand').click(function(){
        ajaxSearch.expand();
    });
    ajaxSearch.show();
    if(sSearchStatus == 'expand') {
        ajaxSearch.expand(true);
    } else {
        ajaxSearch.collapse(true);
    }
    ajaxSearch.refresh();
});
