var Currency={
	obj_id: '#ablv-currency',
	customize_id: '#ablv-currency-customize',

	init: function(){
		$(this.obj_id).find('.options .pseudo-href').click(function(){ Currency.showCustomizer(); });
		$(this.customize_id).find('input[type="button"]').click(function(){ Currency.update(); });
		$(this.customize_id).hide();
	},

	showCustomizer: function(){
		$(this.customize_id).slideDown('normal');
	},

	hideCustomizer: function(){
		$(this.customize_id).slideUp('normal');
	},

	/** collect all currency relations */
	collect: function(){
		var a=[];
		$(this.obj_id).find('select').each(function(){
			a.push(this.name+'='+this.value);
		});
		return a;
	},

	save: function(){
		var data = this.collect();

		//make request url
		var query_url = '/ajax/rates?CACHE='+Math.random();

		//save relations in cookies
		$.each(data, function(i, n){
			var r=n.split('=');
			$.cookie(r[0], r[1], {path: '/', expires: 30});
		});

		//update currency table using AJAX
		$(this.obj_id).find('.rates-data:first tbody').load(query_url);
	},

	update: function(){
		this.hideCustomizer();
		this.save();
	}
};

$(function(){ Currency.init(); });