// JavaScript Document

$(document).ready(function() {
	$('.fancyFrame').fancybox({
		titleShow: false,
		opacity: true,
		padding: 0,
		margin: 0,
		type: 'iframe',
		width: 830,
		height: 530,
		autoDimensions: true,
		centerOnScroll: true
	});
	
	$('.fancy').fancybox({
		titleShow: false,
		opacity: true,
		padding: 0,
		margin: 0
	});
	
	removeButton();
});

function fetchPrices(url, target)
{
	$.post(url, {
		action: 'fetch'	
	}, function (data) {
		$('#' + target).html(data);
		setTimeout("fetchPrices('" + url + "', '" + target + "')", 30000);	
	});
}

function regenerateCaptcha()
{
	$('#captchaImage').attr('src', 'captcha/securimage_show.php?' + Math.random());
	return false;	
}

function redirect(url)
{
	window.location.href=url;	
}

function tabs(target)
{
  if (target == 'coins') {
    $('#goldprices').hide();
    $('#coins').slideDown(500);
  } else {
    $('#coins').hide();
    $('#goldprices').slideDown(500);
  }
}

function updateBasketPrice(url)
{
	$.post(url, {
		action: 'update'
	}, function(data) {
		$('#totalBasketPrice').html(data);
	});
}

function removeButton()
{
	setTimeout(function() {
		$('#submit2').hide();
	}, 60000);
}

function toggleCountry(trigger)
{
	var value = trigger.val();
	
	if (value == 2) {
		$('#countryField').slideDown(500);
	} else {
		$('#country').val('');
		$('#countryField').slideUp(500);
	}
}

function subscribeNewsletter()
{
	$.post('index.php?section=ajax/newsletter', {
		action: 'add',
		newsEmail: $('#newsEmail').val()
	}, function(data) {
		$('#newsResponse').html(data);
	});
}

