/*                                                      *
 *             Custom components with jQuery            *
 *                                                      *
 ********************************************************/

//########################################################
//                    Selectbox
//########################################################

$(function(){
    
    $('.selectbox').each(function(i){
        
        $(this).click(function(){      
            
            $('.isopen').not($(this)).each(function(i){
                $(this).find('.slideMenu').slideUp('fast');
                $(this).removeClass('isopen');    
            });
            
            $(this).toggleClass("isopen");
            
            $(this).find('.slideMenu').slideToggle('fast', jQuery.proxy(function(){
                
                $(this).bind('click', function(event){
                    
                    var value = $(event.target).find('input').val();
                    var text  = $(event.target).text();
                    
                    $(this).parent().find('.selected').val(value);
                    $(this).parent().find('.label').text(text);
                    
                    $(this).slideUp('fast', function(){
                        $(this).parent().removeClass("isopen");
                        $(this).unbind('click');
                        $(this).parent().trigger('changeList', [value, 'event']);
                    });
                    
                    return false;
                });
                
            }), $(this).find('.slideMenu'));
            
            return false;
        });
        
        // init : select first item
        
        $(this).children('.selected').val($(this).find('.slideMenu ul li:first-child input').val());
        $(this).children('.label').text($(this).find('.slideMenu ul li:first-child').text());  
    });
    
    
    $('span.loader').each(function(){
        
        $(this).html('<img src="/medias/images/common/loader.gif" alt="" />');
        
    })
    
    
});