function email_focus() {
	if ($(this).val() == 'your@email.com') {
		$(this).val('')
		$(this).removeClass('faded');
	}
}

function email_blur() {
	if ($(this).val() == '') {
		$(this).val('your@email.com')
		$(this).addClass('faded');
	}	
}

function subscribe_submit() {
	email = $('#email_field').val();

	$.post('subscribe.php?json=1', $('#subscribe_form').serialize(), subscribe_result, 'json');
	$('#subscribe_button').attr("disabled","disabled");
	$('.form_message').fadeOut('fast');
	$('#loading').fadeIn('fast');
	return false;
}

function subscribe_result(data) {
	$('#loading').hide();
	if (data.error) {
		display_message(data.error);
	} else {
		display_message(data.info, 'info')
	}
	$('#subscribe_button').removeAttr("disabled");
}

function display_message(msg, type) {

	if (!type) type = 'error';

	if (type == 'error') {
		$('#error_message').html(msg).fadeIn('slow');
		setTimeout('hide_error()', 4000);
	} else {
		$('#error_message').hide();
		$('#info_message').html(msg).fadeIn('slow');
	}
}

function hide_error() {
	$('#error_message').fadeOut('slow');
}
function switchVariation(id){
	var key = id.split("-")
	$(".description").css("display","none");
	$("#desc"+key[0]).css("display","");
	$(".prices").css("display","none");
	$("#price"+key[0]).css("display","");
	$(".promoPrices").css("display","none");
	$("#promoPrice"+key[0]).css("display","");
	addExtra();
}
function addExtra(){
	var price = parseFloat($(".prices:visible > .initPrice").text());
	var promoPrice = parseFloat($(".promoPrices:visible > .initPrice").text());
	$(".extra:checked").each(function(){
		var extra = $(this).attr("id").split("-");
		price += parseFloat(extra[1]);
		if(!isNaN(promoPrice)){
			promoPrice += parseFloat(extra[1]);
		}
	});
	$(".extra option:selected").each(function(){
		var extra = $(this).val().split("-")
		price += parseFloat(extra[1]);
		if(!isNaN(promoPrice)){
			promoPrice += parseFloat(extra[1]);
		}
	});
	
	$(".prices:visible > .calcPrice").text(price.toFixed(2));
	if(!isNaN(promoPrice)){
		$(".promoPrices:visible > .calcPrice").text(promoPrice.toFixed(2)+"лв.");
	}
}
