var currency = {

	inited: false,

	table: null,

	selectElement: '',

	init: function( callback ){

		if( currency.inited == false ) {
			$.post(
				base_url+'ajax.php',
				{ module: 'currency' },
				function( data ){
					currency.setTable( jQuery.parseJSON( data ) );
					currency.inited = true;

					if( callback != undefined ) {
						callback( currency );
					}
				}
			);
		}
	},

	getSelect: function(){
		return currency.selectElement;
	},

	insertSelect: function( selector ){
		//$(selector).html( currency.selectElement );
	},

	setTable: function( obj ) {
		this.table = obj;
	},

	changeToHuf: function( value , from ) {

		for( var i=0; i<this.table.length; i++ ) {
			if( this.table[i].curr == from ) {
				return parseFloat(this.table[i].value) * value;
				break;
			}
		}

	},

	changeTo: function( value , to ) {

		for( var i=0; i<this.table.length; i++ ) {
			if( this.table[i].curr == to ) {
				return value / parseFloat(this.table[i].value) * parseInt( this.table[i].unit );
				break;
			}
		}

	}


};
