if (!Ext.EMC) {
	Ext.namespace('Ext.EMC');
}
 
/**
 * @class Ext.EMC.CufonReplace Class in charge of executiong Cufon.replace properly
 * @extends Ext.util.Observable
 **/
Ext.define('Ext.EMC.CufonReplace', {
    extend: 'Ext.util.Observable',
    localizationProperties: {
    	    // TODO: load full list 
    	    'af_ZA' : { cufon : true },
    	    'ar_ME' : { cufon : true },
    	    'bs_BA' : { cufon : true },
    	    'cs_CZ' : { cufon : true },
    	    'da_DK' : { cufon : true },
    	    'de_AT' : { cufon : true },
    	    'de_CH' : { cufon : true },
    	    'de_DE' : { cufon : true },
    	    'de_DE' : { cufon : true },
    	    'el_GR' : { cufon : true },
    	    'en_AF' : { cufon : true },
    	    'en_AU' : { cufon : true },
    	    'en_BE' : { cufon : true },
    	    'en_CA' : { cufon : true },
    	    'en_GB' : { cufon : true },
    	    'en_HK' : { cufon : true },
    	    'en_NZ' : { cufon : true },
    	    'en_SG' : { cufon : true },
    	    'en_US' : { cufon : true },
    	    'es_AR' : { cufon : true },
    	    'es_CL' : { cufon : true },
    	    'es_CO' : { cufon : true },
    	    'es_ES' : { cufon : true },
    	    'es_MX' : { cufon : true },
    	    'es_PE' : { cufon : true },
    	    'es_PR' : { cufon : true },
    	    'es_VE' : { cufon : true },
    	    'et_EE' : { cufon : true },
    	    'fi_FI' : { cufon : true },
    	    'fr_AF' : { cufon : true },
    	    'fr_CA' : { cufon : true },
    	    'fr_CH' : { cufon : true },
    	    'fr_FR' : { cufon : true },
    	    'hr_HR' : { cufon : true },
    	    'hu_HU' : { cufon : true },
    	    'id_ID' : { cufon : true },
    	    'il_IL' : { cufon : true },
    	    'in_IN' : { cufon : true },
    	    'it_IT' : { cufon : true },
    	    'ja_JP' : { cufon : false },
    	    'ko_KR' : { cufon : false },
    	    'lt_LT' : { cufon : true },
    	    'lv_LV' : { cufon : true },
    	    'me_ME' : { cufon : true },
    	    'mk_MK' : { cufon : true },
    	    'ms_MY' : { cufon : true },
    	    'nl_LU' : { cufon : true },
    	    'nl_NL' : { cufon : true },
    	    'no_NO' : { cufon : true },
    	    'pl_PL' : { cufon : true },
    	    'pt_BR' : { cufon : true },
    	    'pt_PT' : { cufon : true },
    	    'ro_RO' : { cufon : true },
    	    'ru_RU' : { cufon : false },
    	    'ru_UA' : { cufon : false },
    	    'sk_SI' : { cufon : true },
    	    'sk_SK' : { cufon : true },
    	    'sq_AL' : { cufon : true },
    	    'sr_SR' : { cufon : true },
    	    'sv_SE' : { cufon : true },
    	    'th_TH' : { cufon : true },
    	    'tl_PH' : { cufon : true },
    	    'tr_TR' : { cufon : true },
    	    'zh_CN' : { cufon : false },
    	    'zh_TW' : { cufon : false }
    	},
    constructor: function(config){
    	// Call our superclass constructor to complete construction process.
        Ext.EMC.CufonReplace.superclass.constructor.call(this, config);

        var self = this;

        // obtain current language code
        var lc = '';
        var wrapper = Ext.query('.emc-wrapper > div');
        if (wrapper.length && wrapper[0]) { 
            var matches = /locale-(\w{2}_\w{2})/gi.exec(wrapper[0].className);
            if (matches && matches[1]) { lc = matches[1] }
        }
        
        // defaults to en_US
        var conf = self.localizationProperties[lc] !== undefined ? self.localizationProperties[lc] : self.localizationProperties['en_US'];
        
        // apply cufon if required:
        if ( conf.cufon ) {
            Cufon.replace('.breadcrumb a', {hover:true, fontFamily:'Meta-Bold'});
            Cufon.replace('.solution-title h1', {hover:true, fontFamily:'Meta-Normal'});
            Cufon.replace('.authentication-title h1', {hover:false, fontFamily:'Meta-Normal'});
			Cufon.replace('.lead-space h1', {hover:false, fontFamily:'Meta-Normal'});
            Cufon.replace('.benefit-detail-nav a', {hover:true, fontFamily:'Meta-Bold'});
            Cufon.replace('.close-page a', {hover:true, fontFamily:'Meta-Bold'});
        }
    }
});


Ext.onReady(function(){
	var cufonReplace = new Ext.EMC.CufonReplace();
});
