var Main = (function () {

    function initContact() {
        var libelle_contact = $('libelle_contact')
        if(libelle_contact) {
            Element.show(libelle_contact);
            Event.observe(libelle_contact, 'click', showSimpleOrAdvancedContactForm)
        }       
    }

    function initMapLinks()
    {
        $$('#agencies .map a').each(function(link) {
            link.observe('mouseover', function() {
                link.previous().style.display = 'inline';
            });
            link.observe('mouseout', function() {
                link.previous().style.display = 'none';
            });
            link.observe('click', function(event) {
                var div = $('agency');
                if (!div) {
                    div = $(document.createElement('DIV'));
                    div.id = 'agency';
                    $('agencies').appendChild(div);
                }
                if (!link.href.match(/#$/)) {
                    new Ajax.Request(link.href, {
                        method: 'get',
                        onComplete: function(transport) {
                            div.update(transport.responseText);
                            new Effect.ScrollTo('agency');
                            initResourceEditors($$('#agencies .resource'));
                        }
                    });
                } 
                Event.stop(event);
                link.blur();
            });
        });
    } // initMapLinks

    function init()
    {
        initContact();
        initMapLinks();
    } // init

    return {
        'init': init,
		'showSimpleOrAdvancedContactForm' : showSimpleOrAdvancedContactForm
    }
    
    function showSimpleOrAdvancedContactForm(e) {
        var span                = $('libelle_contact')      
        var simple_contact_form = $('simple_contact_form')
        var full_contact_form   = $('full_contact_form')
        
        if( "none" == simple_contact_form.style.display) {
            Element.hide(full_contact_form);
            Element.show(simple_contact_form)
            span.firstChild.data = "Cliquez ici si vous n'avez jamais contacté LMI."
        } else {
            Element.hide(simple_contact_form);
            Element.show(full_contact_form)
            span.firstChild.data = "Cliquez ici si vous avez déjà contacté LMI."         
        }
    }

})();

Event.observe(window, 'load', Main.init);