$(document).ready(function() {
	
	$('#fancybox-content a.close-trigger').live('click', function(){
		$.fancybox.close();
		return false;
	});
}); // End Doc Ready


function callFancybox() {
	$.fancybox(
		$('#currencyDialogContainer').html(), {
			'modal': false,
			'showCloseButton': false,
			'hideOnContentClick': true,
			'overlayColor': '#ffffff',
			'overlayOpacity': 0.8,
			onComplete:function() {
				var $input = $('#fancybox-content .from-currency').first(),
					$dropdown = $('#fancybox-content .code-selector').first(),
					$label = $('#fancybox-content .to-currency').first();
					
					$input.focus();
					
					$input.keyup(function() {
						currencyConvert($input, $dropdown, $label);						
					});
					
					$dropdown.change(function() {
						currencyConvert($input, $dropdown, $label);
					})

			}
		});
}

function currencyConvert($input, $dropdown, $label) {
	var value = $input.val(),
		code = $dropdown.val();

		$.post('currency.php', {'value': value, 'code': code}, function(response) {
			$label.empty().html(response);
		});
}
