Ext.ux.LanguageCycleButton = Ext.extend(Ext.CycleButton, {
									 
	languageItems: this.languageItems || [
		{language: 'es', text: 'Español&nbsp;', checked: true, iconCls: Ext.ux.iconMgr.getIcon('resources/ux/Ext.ux.iconMgr/flags/', 'es')},
		{language: 'al', text: 'Alemán&nbsp;', iconCls: Ext.ux.iconMgr.getIcon('resources/ux/Ext.ux.iconMgr/flags/', 'al')},
		{language: 'en', text: 'Inglés&nbsp;', iconCls: Ext.ux.iconMgr.getIcon('resources/ux/Ext.ux.iconMgr/flags/', 'england')},
		{language: 'ch', text: 'Chino&nbsp;', iconCls: Ext.ux.iconMgr.getIcon('resources/ux/Ext.ux.iconMgr/flags/', 'ch')},
		{language: 'ar', text: 'Arabe&nbsp;', iconCls: Ext.ux.iconMgr.getIcon('resources/ux/Ext.ux.iconMgr/flags/', 'ar')},
		{language: 'tu', text: 'Turco&nbsp;', iconCls: Ext.ux.iconMgr.getIcon('resources/ux/Ext.ux.iconMgr/flags/', 'tc')}
	],
	languageVar: this.languageVar || 'lang',
	
	initComponent: function() {
		Ext.apply(this, {
		    showText: true,
			prependText: '&nbsp;',
   			items: this.languageItems
		});
		if(Ext.state.Manager){ 
        	var selectedLanguage = Ext.state.Manager.get(this.languageVar); 
            if(selectedLanguage){ 
				for(var i=0; i<this.items.length;i++){
					if (this.items[i].language == selectedLanguage){
						this.items[i].checked = true;
						break;
					}
				}
            } 
        } 
		Ext.ux.LanguageCycleButton.superclass.initComponent.apply(this, arguments);
	},
	
	changeHandler: function(o, i){
        if(Ext.state.Manager.getProvider()) {
            Ext.state.Manager.set(this.languageVar, i.language);
        }
		//window.location.href = window.location.protocol + '//' + window.location.host + window.location.pathname + '&l=' + i.language;
		var aux = '';
		if(window.location.href.split('&l=')[1]){
			if(window.location.href.split('&l=')[1].split('&')[1]){
				aux = '&' + window.location.href.split('&l=')[1].split('&')[1];
			}
		}
		Ext.Msg.alert('Alert', 'Not implemented in static web page like this. RedirectTo: ' + window.location.href.split('&l=')[0] + '&l=' + i.language + aux);
		//window.location.href = window.location.href.split('&l=')[0] + '&l=' + i.language + aux;
	}
	        
});

Ext.reg('themecyclebutton', Ext.ux.LanguageCycleButton);