$(document).ready(
	function () {
		$('a.minmax').bind('click', toggleContent);
		$('input.quantityfield').bind('keyup', runningTotal);
		runningTotal();
		swaptitle();
	}
);

var toggleContent = function(e)
{
	var targetContent = $('div.detail_view', this.parentNode);

	if (targetContent.css('display') == 'none') {
		targetContent.slideDown(300);
		$(this).html("Hide Details");
	} else {
		targetContent.slideUp(300);
		$(this).html("Show Details");
	}
	$(this).blur();
	return false;
};

var runningTotal = function()
{
  var targetValue;
  var runningTotal = 0;
	
	$('input.quantityfield').each(
		function(){
		  targetValue = $("div.siteprice", this.parentNode.parentNode.parentNode).text();
      runningTotal = Number(runningTotal) + (this.value * Number(targetValue.substring(1)));
		}
	)

	//runningTotal = Math.round(runningTotal*Math.pow(10,2))/Math.pow(10,2);
	
	
	
	$("span#running_total").html(cent(runningTotal));
};

var swaptitle = function()
 {
 $('input#ctl00_MainContentHolder_insertoffercode').val ($('input#OfferCode').attr('value'));
 $('span#insertoffertitle').html($('h3#insertoffername span').html());
  };

function cent(amount) {
	amount -= 0;
	amount = (Math.round(amount*100))/100;
	return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}
