/* Xoopla tools */
(function(){
	var instance = null;
	function _Tools(){};
	
	_Tools.prototype = {
		/* Stop action/propagation d'un evenement */
		/* @argument - (Obj) evt : evenement */
		/* @return - (Obj) evt : evenement */
		stopEvent: function(evt){
			if(window.event){ //IE
				evt = window.event;
				evt.returnValue = false;
			}
			try {
				evt.cancelBubble = true;
				if(evt.preventDefault) evt.preventDefault();
				if(evt.stopPropagation) evt.stopPropagation();
				if(evt.stopped) evt.stopped = true;
			} catch(e) {
				/* console.log(e.message); */
			}		
			return evt;
		},
		
		/* Retourne l'Url depuis l'Url map du site */
		/* @argument - (String) key : token de l'url */
		/* @return - (String) url : url */
		getUrl: function(key){
			var url = null;
			if(!pib.urlmap[key]) throw 'Url: ' + key + ' doesn\'t exist in website url map!';
			else url = pib.urlmap[key];
			return url;
		},
		
		/* Retourne une traduction dictionaire */
		/* @argument - (String) key : token du dictionaire */
		/* @return - (String) translation : terme du dictionaire */
		translate: function(token){
			var translation;
			if(pib.labels[token]) translation = pib.labels[token];
  		else translation = token + '-' + heap.config['current_language'];
			return translation;			
		},
		
		/* Heritage Class */
		extendClass: function(childClass, parentClass){
			var F = function(){};
			F.prototype = parentClass.prototype;
			childClass.prototype = new F();
			childClass.prototype.constructor = parentClass;
			childClass.parentClass = parentClass.prototype;
			if(parentClass.prototype.constructor == Object.prototype.constructor){
				parentClass.prototype.constructor = parentClass;
			}
		}
	};
	
	/* Singleton - getInstance */
	var getInstance = function(){
		instance = (!instance)? new _Tools() : instance;
		return instance;		
	};
	
	window.pib = window.pib || {};
	window.pib.tools = window.pib.tools || getInstance();		
})();
