$(function(){
	if ($.cookie('item_added') == 1)
	{
		$.cookie('item_added', null, {path: '/'});

		var left = ($(window).width() - $('#cart-popup').width()) / 2;
		var top = ($(window).height() - $('#cart-popup').height()) / 2;

		$('#cart-popup').css('left', left);
		$('#cart-popup').css('top', top);

		$('#cart-popup').fadeIn(1000)//.delay(3000).fadeOut(1000);
	}
	
	$('#currency_switch').change(select_currency);

	var name = $('#currency_switch option').first().html();
	update_currency(1, name);
});

function select_currency()
{
	var option = $(this).children('option[value='+$(this).val()+']');
	var dest = option.attr('rate');
	var primary = $('#currency_switch option').first().attr('rate');
	var name = option.html();
	
	update_currency(dest / primary, name)
}

function update_currency(rate, name)
{
	var cost = parseInt($('#delivery-sum').attr('raw')) * rate;
	$('#delivery-sum').val(cost + ' ' + name);
	
	var update_price = function(){
		$(this).val($(this).attr('raw') * rate);
	}
	
	$('.price-box').each(update_price);
	$('.cost-box').each(update_price);
}
