var _fo =   {
    
    init: {
        _:  function() {
            this.validator._();
            this.nav._();
            this.changelang._();
            this.newsletter._();
        },
        
        nav: {
            _:  function() {
                
                this.on._();
            },
            
            on: {
                _:  function() {
                    
                    var l_search    =   true;

                    $('.supportmenu > a.nav').each(function(i_idx) {
                        
                        if (l_search) 
                        {
                            if (location.pathname.indexOf($(this).attr('href')) == 0) 
                            {
                                $(this).addClass('on');
                                l_search    =   false;
                            }
                        }
                    });
                    
                    if (!l_search) 
                    {
                        return;
                    }
                    
                    $('.supportmenu > .nav > a').each(function(i_idx) {
                        
                        if (l_search) 
                        {
                            if (location.pathname.indexOf($(this).attr('href')) == 0) 
                            {
                                $(this).parent().addClass('on');
                                l_search    =   false;
                            }
                        }
                    });
                }
            }
        },
        
        changelang: {
            _:  function() {
                
                $('#fo_page_header_changelang-form-submit').hide();
                
                $('#fo_page_header_changelang-form-lang').mSelect({eventClick: function(i_value, i_html) {
                        
                        $('#fo_page_header_changelang-form').each(function() {
                            
                            location.href   =   this.action += i_value;
                        });
                    }
                });
            }
        },
        
        newsletter: {
            _:  function() {

                this.subscribe._();
            },
            subscribe: {
                _:  function() {

                    $('.newsletter_subscribe').each(function() {
                        
                        var $_this  =   $(this);

                        $_this.validator({'lang': $('html').attr('lang')}).submit(function(i_event) {
                            
                            if (!i_event.isDefaultPrevented()) 
                            {
                                $.post('/', $_this.serialize() + '&ajax=on', function(i_fb) {

                                    if (i_fb.ok) 
                                    {
                                        _fo.alert(_l10n.newsletter.subscribe.ok);
                                    }

                                }, 'json');
                            }
                            return false;
                        });
                        
                        $_this.find('input[type=email]')
                            .focus(function() {
                                
                                $(this).val('');
                            })
                            .blur(function() {
                           
                                if ($(this).val() == '') 
                                {
                                    this.form.reset();
                                }
                            })
                            .keypress(function(i_e) {
                                
                                if((i_e.which ? i_e.which : i_e.keyCode) == 13) 
                                {
                                    $_this.submit();
                                    return false;
                                }
                                return true;
                            })
                        ;
                    });
                }
            }
        },
        validator: {
            _:  function() {
                var l_lang  =   $('html').attr('lang');
                
                switch(l_lang)
                {
                case 'fr':
                    $.tools.validator.localize('fr', {
                        '*'			: 'Invalide',
                        ':email'  	: 'E-mail invalide',
                        ':number' 	: 'Nombre invalide',
                        ':url' 		: 'URL invalide',
                        '[max]'	 	: 'Le nombre doit être supérieur à $1',
                        '[min]'		: 'Le nombre doit être inférieur à $1',
                        '[required]'	: 'Manquant'
                    });
                    break;
                
                case 'en':
                default:
                    break;
                }
                
                
//                $('form').livequery(function() {
//                    
//                    $(this).validator({
//                        'lang': l_lang
//                    });
//                });
  
            }
        }
    },
    
    alert: function(i_str) {
        
        alert(i_str);
    }
};

$(document).ready(function(){_fo.init._();});
