$(document).ready(function() {

	// attach lighbox behavior...
	$('a.lightbox').lightBox({
		overlayBgColor: '#000',
		overlayOpacity: 0.8,
		imageLoading: '/images/lightbox/default/lightbox-ico-loading.gif',
		imageBtnClose: '/images/lightbox/default/lightbox-btn-close.gif',
		imageBtnPrev: '/images/lightbox/default/lightbox-btn-prev.gif',
		imageBtnNext: '/images/lightbox/images/default/lightbox-btn-next.gif',
		imageBlank: '/images/lightbox/images/default/lightbox-blank.gif',
		containerResizeSpeed: 350,
		txtImage: 'Imagem',
		txtOf: 'de'
	});

	// carbon calculator
	$('#submit input').click(function() {

		// get selected energy type
		var carbonCalc = $('#type-select').find("option:selected");

		// get entered amount saved (remove commas, spaces)
		var amountSaved = $('#amount')[0].value.replace(/\s/g,"").replace(/,/g,"");

		if(carbonCalc[0].value == 'electricity') {
			var constant = 0.000399;
		} else {
			var constant = 0.00544;
		}

		// carbon avoided
		var carbonResult = constant * amountSaved;

		// error checking
		if(amountSaved == '') {
			alert('Please enter the amount of energy saved.');
		} else if(isNaN(carbonResult)) {
			alert('Please enter the amount of energy saved as a number.');
		} else {
			// replace existing result	
			$('#co2-result span').text(carbonResult.toFixed(2) + ' tons');
		}

		return false;

	});

});