cfe.module.langSelect = new Class({
	
    Extends: cfe.module.select,
    type: "Selector",
    selector: "#sitelanguage",
    
    build: function()
    {
        /* build the select element showing the currently selected item */
        this.a.addClass("js"+this.type+this.options.instanceID);
		
        this.arrow = new Element("img",{
            "class": "js"+this.type+"Arrow",
            "src": this.options.spacer,
            "styles": {
                "float":"right",
                "display":"inline"
            }
        }).injectInside(this.a);
		
        this.ai = new Element("span").addClass("js"+this.type+"Slide").injectInside(this.a).adopt(this.arrow);
        
        this.activeEl = new Element("span",{
            "class": "jsOptionSelected" + (this.origOptions[0].getProperty('class')?" "+this.origOptions[0].getProperty('class'):''),
            "styles": {
                "float":"left",
                "display":"inline"
            }
        }).set('html', this.origOptions[0].get("text") ).injectBefore(this.arrow);
			
        /* build container which shows on click */
        this.buildContainer();
       
        // select default option
        this.selectOption(this.selectedIndex, false, true);
    },
    
    selectOption: function(index,stayOpenAfterSelect, dontScroll)
    {
        index = index.limit(0,this.origOptions.length-1);

        this.highlightOption(index, dontScroll);

        var oldIndex = this.selectedIndex; 
        
        this.selectedIndex = index;

        this.activeEl.set('html', (this.aOptions[index]).innerHTML);
        
        if(this.activeEl.hasClass(this.origOptions[oldIndex].getProperty('class')))
        {
        	this.activeEl.removeClass(this.origOptions[oldIndex].getProperty('class'));
        }
        this.activeEl.addClass(this.origOptions[index].getProperty('class'));
        
        if( !$chk(stayOpenAfterSelect) ) this.hideContainer();
    }
    
    /*,
    
    buildOption: function(el, index)
    {
    	var oOptHtml = el.innerHTML;
    	if(this.selectedIndex != index)
    	{
    		oOptHtml = '<a href="' + conf['page_url'] + '?newLanguage=' + el.get('value') + '">' + oOptHtml + '</a>'
    	}
    	
        var oOpt = new Element("div",{
            "class": "jsOption jsOption"+index+(el.getProperty('class')?' '+el.getProperty('class'):''),
            "events":{
                "mouseover": this.highlightOption.pass([index,true],this),
                "mouseout": this.highlightOption.pass([index,true],this)
            }
        }).set('html', oOptHtml);

        oOpt.index = index;
        oOpt.disableTextSelection();

        return oOpt;
    }*/
});

cfe.module.select.implement({selector: "select:not(select[multiple]):not([id=sitelanguage])"});