/* JS common to minisites */

$(function() {

	$("a.fancy").fancybox();
	$('a.phone').fancybox({
		href : '/getnumber'
	});

	$('a#get-est').click(function() {
		$('#est-box').slideToggle('slow');
		return false;
	});

	$('.plnk').click(function() {
                $('.cbox').slideToggle('slow');
                return false;
        });

	$('#contact-answer').change(function() {
		var cval = $(this).val();
		if (cval == "y") {
			$('#contact-box').slideDown('slow');
		} else {
			$('#contact-box').slideUp('slow');
		}
	});
	$('#agent-answer').change(function() {
		var cval = $(this).val();
		if (cval == "y") {
			$('#agent-box').slideDown('slow');
		} else {
			$('#agent-box').slideUp('slow');
		}
	});


	$('#calc-sell').click(function(){
		var boxVal = $('#property-value').val();

		var comm;
		var back;

		// Hide any old results
		$('#selling-results').slideUp('slow');

		// Remove any money sep chars like comma & make into a number we can use
		boxVal = boxVal.replace(/\,/g,'');
		boxVal = parseInt(boxVal);

		if (boxVal == 0 || !boxVal) {
			alert('Please enter a value.');	// Cant read this!
		} else {
			// Do the calculations
			if (boxVal <= underLimit) {
				comm = underAmt;
				back = underAmt * sell_cb;
			} else if (boxVal >= overLimit) {
				comm = overAmt;
				back = overAmt * sell_cb;
			} else {
				comm = boxVal * sell_pc;
				back = comm * sell_cb;
			}
			var cbpc = sell_cb * 100;

			// Stuff them into place
			$('#sell_comm').text(Math.round(comm));
			$('#sell_back').text(Math.round(back));
			$('#sell_bpc').text(Math.round(cbpc));

			// Reveal the results
			$('#selling-results').slideDown('slow');
		}

		return false;
	});

	//



});
