/**
 * Flash Stats Parser - v.1.04
 * Author ~ Niels Lyngsų
 */

function FlashStatsParser(sitecatalystAPI, HBLanguage) {
	
	this._scAPI = sitecatalystAPI;
	
	this._HBLang = HBLanguage;
	
	if (this._scAPI._reference != "") {
		this._appReference = this._scAPI._reference;
	} else {
		this._appReference = "";
	}
}


FlashStatsParser.prototype._scAPI;
FlashStatsParser.prototype._appReference;
FlashStatsParser.prototype._HBLang;


FlashStatsParser.prototype.isReady = function() {
	
	if (hbx.mlc) {
		return "true";
	}
	
	return "false";
}





// PAGES
FlashStatsParser.prototype.page = function(p) {

	
	
	this._scAPI.page(p);
	
	var index;
	
	//remove overview
	if (p.substr(-9, 9).toLowerCase() == ":overview") {
		index = p.lastIndexOf(":");
		p = p.substr(0, index);
	}
	
	// seperate page
	index = p.lastIndexOf(":")+1;
	var page = p.substr(index);
	
	var category = this._convertToHB(p.substr(0, index));
	
	_hbPageView(page, category);
}










// DOWNLOADS
FlashStatsParser.prototype.download = function(filepath) {

	this._scAPI.download(filepath);
	
	// no need for converting this.
	
	_hbDownload(filepath);
}









// HB Functions
FlashStatsParser.prototype._convertToHB = function(reference) {
	
	
	var singleRefItems = new Array();
	
	if (this._appReference != "") {
		singleRefItems.push(this._appReference);
	}
	
	singleRefItems.push(reference);
	
	
	var singleRef = "/content/"+(singleRefItems.join("/")).replace(/:/g,"/");
	
	
	return singleRef+";/"+this._HBLang+""+singleRef;
	
}


/*
	
	
	games:kids:home:overview
	
	games:kids:home
	
	games/kids/home
	
	/games/kids/home/
	
	;/deu 
	
	/content /games/kids/home/ ;/deu /content /games/kids/home/
	
	
	/content/games/kids/home/;/deu/content/games/kids/home/
	
	
	/content/games/kids/home/;/deu/content/games/kids/home/
	
	/content/games/kids/how to play/;deu/content/games/kids/how to play/
	
	*/






