/*

 * (C) 2009 Foamshop.co.uk

 * Author: Christian Piper (Christian@design-desires.co.uk)

 */



/*

 * Avoid conflicts with prototype

 */

var $j = jQuery.noConflict();



/*

 * Setup the initial product view, we check teh values of fields due to the

 * fact FF retains the last values on a page reload, keeps things pretty :)

 */

$j(document).ready(function () {

	checkType();

	tickingPic();

	pingQuote();

});



/*

 * Fired when a select box value has changed

 */

function pingQuote() {

	var type = $j('[name=overlay]').val();

	var width = $j('[name=width]').val();

	var length = $j('[name=length]').val();

	var depth = $j('[name=depth]').val();

	var extras = $j('[name=extras]').val();

	var call = $j.ajax({

		type: "POST",

		url: "/tools/getoverlayprice.php",

		data: ({t: type, w: width, d: depth, l: length, e: extras}),

		cache: false,

		dataType: "html",

		success: function(foo, textStatus){

			$j('#price').html(foo);

		}

	});

}



function tickingPic() {

	var i = $j('[name=extras]').get(0).selectedIndex;

	switch(i){

		case 0:

			$('tickingimage').update('');

		break;

		case 1:

			$('tickingimage').update('<img src="/media/mattress1.jpg" style="float: right" class="cms-image" alt="" />');

		break;

	}

}



function checkType() {

	switch($j('[name=overlay]').get(0).selectedIndex){

		case 0:

			$('foamimage').update('<img src="/media/eggbox.jpg" alt="" style="float: right" class="cms-image" />');

			$('foam_choice_text').update('<p style="padding: 30px 20px 20px 0"><strong>Specifically designed in response to sleep related problems such as insomnia, the anatomical mattress topper is contoured to give your body vital support.</strong></p>');

		break;

		case 1:

			$('foamimage').update('<img src="/media/memory.jpg" alt="" style="float: right" class="cms-image" />');

			$('foam_choice_text').update('<p style="padding: 30px 20px 20px 0"><strong>This heat sensitive memory foam will mould to the contours of your body giving perfect support and the ultimate comfort all night long.</strong></p>');

		break;

		case 2:

			$('foamimage').update('<img src="/media/regal.jpg" alt="" style="float: right" class="cms-image" />');

			$('foam_choice_text').update('<p style="padding: 30px 20px 20px 0"><strong>This is by far our most popular, finest, high density high quality foam. This provides outstanding durability, with excellent recovery properties making it the obvious choice for everyday use.</strong></p>');

		break;

		case 3:

			$('foamimage').update('<img src="/media/latex.jpg" alt="" style="float: right" class="cms-image" />');

			$('tickingimage').update('<img src="/media/mattress1.jpg" alt="" style="float: right" class="cms-image" />');

			$('foam_choice_text').update('');

			$j('[name=extras]').val('2');

		break;

	}

	if($j('[name=overlay]').get(0).selectedIndex == 3) {

		$j('[name=extras]').attr("disabled", true);

	} else {

		$j('[name=extras]').attr("disabled", false);

	}

	if(($j('[name=overlay]').get(0).selectedIndex == 0) || $j('[name=overlay]').get(0).selectedIndex == 1) {

		$j('[name=depth]').val('2.00');

		$j('[name=depth]').attr("disabled", true);

	} else {

		$j('[name=depth]').attr("disabled", false);

	}

}
