/**
 * @author Alberto Cobas
 */
aol_favs_localization = new function() {

	this._localeMap = {".*\\.aol\\.com$": "en_US", ".*\\.aol\\.co\\.uk$": "en_GB", ".*\\.aol\\.ca$": "en_CA"};
	this._brandMap = {"^hp-consumer\\..*": "hp-consumer", "^hp-commercial\\..*": "hp-commercial", "^compaq-consumer\\..*": "compaq-consumer", ".*\\.aol\\.\\w+$": "aol", ".*\\.aol\\.\\w+\\.\\w+$": "aol"};
	
	/**
	 * Return locale matching the provided domain using regexps in map
	 * If the domain is null, the current domain is extracted from the location object.
	 * @param {Object} domain
	 */
	this.getLocale = function(domain) {
		
		var re = null;
		var pattern = null;
		var match = false;
		var locale = null;
		
		if (domain == null) {
			domain = location.hostname;
		}
	
    	// Get first locale matching domain. If none is found, use en_US.
		for (pattern in this._localeMap) {
			re = new RegExp(pattern, "i");
			match = re.test(domain);
			if (locale == null && match) {
				locale = this._localeMap[pattern];
			}
		}
		if (locale == null) {
			locale = "en_US";
		}
		return locale;
	};
	
	/**
	 * Return brand matching the provided domain using regexps in map
	 * If the domain is null, the current domain is extracted from the location object.
	 * @param {Object} domain
	 */
	this.getBrand = function(domain) {
		
		var re = null;
		var pattern = null;
		var match = false;
		var brand = null;
		
		if (domain == null) {
			domain = location.hostname;
		}
	
    	// Get first locale matching domain. If none is found, use aol.
		for (pattern in this._brandMap) {
			re = new RegExp(pattern, "i");
			match = re.test(domain);
			if (brand == null && match) {
				brand = this._brandMap[pattern];
			}
		}
		if (brand == null) {
			brand = "aol";
		}
		return brand;
	};
	
	/**
	 * Return relative path to resources for provided locale and brand
	 * @param {Object} locale
	 * @param {Object} brand
	 */
	this.getPathToResources = function(locale, brand) {
		return locale + "/" + brand;		
	};

	/**
	 * Return relative path to resources for provided domain.
	 * @param {Object} domain
	 */
	this.getPathToResources = function(domain) {
		return this.getLocale(domain) + "/" + this.getBrand(domain);
	};
}
