/**
 * Helper "languages": language selection
 * 
 * @var jQuery container
 * @var jQuery current
 * @var bool   visible
 */
 
$(document).ready(function() {

var lang = new (go.Class({
    'NODE'       : ".language",    
    'SHOW_CLASS' : "lhover",

    'run': (function() {
    
        this.container = $(this.NODE).eq(0);
        this.current   = this.container.find("div").eq(0);    
        this.visible = false;
        
        this.current.find("a").click(this.onClickCurrentA);
        this.current.click(this.onClickCurrent);

        $(document.body).click(this.onClickBody);        
    }),
    
    /**
     * Click on current language (link) - nothing
     */
    'onClickCurrentA_bind': (function(e) {
        return e.preventDefault();
    }),
    
    /**
     * Click on current language (area) - selectbox
     */
    'onClickCurrent_bind': (function(e) {
        this.toggleSelectbox();
        return false;
    }),
    
    /**
     * Click on BODY - hide selectbox if it is opened
     */
    'onClickBody_bind': (function(e) {
        this.hideSelectbox();
    }),

    'showSelectbox': (function() {
        this.visible = true;
        this.container.addClass(this.SHOW_CLASS);
    }),
    
    'hideSelectbox': (function() {
        this.visible = false;
        this.container.removeClass(this.SHOW_CLASS);
    }),
    
    'toggleSelectbox': (function() {
        this.visible ? this.hideSelectbox() : this.showSelectbox();
    }),
    
    'eoc': null
}));
lang.run();
});
