(function($){
	
	$.mskI18n = new function(){
		
		this._options = {
			uri: '/ajax/tr'
		};
		
		this._cache = {};
		
		this.cache = function( data ){
			if( typeof data == 'object' ){
				this._cache = $.extend({},this._cache,data);
			}
		return this._cache; 
		} 
		
		this.options = function( options ){
			
			if( typeof options == 'object' ){
				this._options = $.extend({},this._options,options);
			}
			
		return this._options;
		}	
	}
	
	function translate( $element, type ){
		var msg = $element[type]();
		var cache = $.mskI18n.cache();
		
		if( cache[msg] ){
			$element[type]( cache[msg] );
		} else {
			$.post($.mskI18n.options().uri,{message:msg},function( data ){
					var tmp = {};
					tmp[msg] = data;
					$.mskI18n.cache( tmp );
					
					$element.mskI18n( type );
				},'json');
		}
	}
	
	$.fn.mskI18n = function( type ){
		return this.each(function(){ translate( $(this), type ); } ); 
	}
	
})(jQuery);

