/**
 * General javascript routines for DF/Manager
 */
$(function() {
	
	// convert prices to selected currency
	convertPrices();

	// apply tablegrid plugin
	$('table.thumbs').TableGrid();
});

function convertPrices() {
	$('span[rel=price]').each(function() {
		$this = $(this);
		if(currency_rate != $this.attr('data-rate')) {
			var rate = currency_rate / $this.attr('data-rate');
			$this
				.html('± ' + currency_sign + parseInt($this.attr('data-price') * rate).toFixed(2))
				.attr('title', 'Original price: ' + $this.attr('data-sign') + $this.attr('data-price'));
		}
	});
}

/**
 * Plugins
 */
(function( $ ){
	
	// tablegrid plugin applies width attribute 
	// depending on nr. of columns and screen width
	$.fn.TableGrid = function() {

		return this.each(function() {
			$this = $(this);
			var name_width = Math.floor($this.parent().innerWidth() / $this.find('tr.products:first>td').length) - 40;
			$this.find('.name').css('width', name_width + 'px');
		});

	};

})( jQuery );
