function textReplacement(input){
 var originalvalue = input.val();
 input.focus( function(){
  if( $.trim(input.val()) == originalvalue ){ input.val(''); }
 });
 input.blur( function(){
  if( $.trim(input.val()) == '' ){ input.val(originalvalue); }
 });
}

$(document).ready(function() {

	textReplacement($("#FormEntryQuestion-17"));
	textReplacement($("#FormEntryQuestion-18"));

if ($.browser.msie && $.browser.version.substr(0,1)<7) {
	// IE6 and fadeTo() don't mix... subsequent images weren't displaying

	var btnGoCount = $("div#numbers a").length;
	$(".carouselHolder .contentCarousel").jCarouselLite({
		btnGo: [".b1", ".b2", ".b3", ".b4", ".b5"],
    	visible: 1,
    	auto: 7000,
    	speed: 0,
    	afterEnd: function(i) {
    		current = $(i).index();	//get the index of the current li
    		current = (current > btnGoCount) ? 1 : current;	//adjust to first, if more than num buttons, due to circular
    		$('div#numbers a').each(function(index) {
    			realIndex = index + 1;	//this index is 0-based, above is 1-based
    			if(realIndex == current) {
    				$(this).addClass('current');
    			} else {
    				$(this).removeClass('current');
    			}
    		});
    	}

	});

} else {
	// use fadeTo() if >IE6 or any other browser

	var btnGoCount = $("div#numbers a").length;
	$(".carouselHolder .contentCarousel").jCarouselLite({
		btnGo: [".b1", ".b2", ".b3", ".b4", ".b5"],
    	visible: 1,
    	auto: 7000,
    	speed: 0,
    	beforeStart: function(a) {
				$(a).parent().fadeTo(600, 0);
    	},
    	afterEnd: function(i) {
    		$(i).parent().fadeTo(900, 1);
    		current = $(i).index();	//get the index of the current li
    		current = (current > btnGoCount) ? 1 : current;	//adjust to first, if more than num buttons, due to circular
    		$('div#numbers a').each(function(index) {
    			realIndex = index + 1;	//this index is 0-based, above is 1-based
    			if(realIndex == current) {
    				$(this).addClass('current');
    			} else {
    				$(this).removeClass('current');
    			}
    		});
    	}

	});

}
	
	$('input.quantity').attr('autocomplete', 'off');	//have to use keyboard
	$('input.quantity').keyup( function(event) {
		var product = jQuery.metadata.get(this);
		var amount = 0;
		var quantity = $(this).val();
		quantity = quantity.replace('$', '');	//get rid of dollar sign if they enter one
		quantity = quantity.replace(',', '');
		//product.price from class on input
		if(product.price > 0) {
			if(product.special_price) {
				amount = product.special_price * quantity;
			} else {
				amount = product.price * quantity;
			}
		} else {
			amount = quantity;	//donation
		}
		if(amount >= 0) {
			$(this).parents('td').next('td').html(amount).formatCurrency();			
		} else {
			$(this).parents('td').next('td').html('&nbsp;');
		}
		resetOrderTotal();
		event.preventDefault();
    });

});

function resetOrderTotal() {
	var order_total = 0;
	
	 $("input.quantity").each(function() {
	        var product = jQuery.metadata.get(this);
			var amount = 0;
			var quantity = $(this).val();
			quantity = quantity.replace('$', '');	//get rid of dollar sign if they enter one
			quantity = quantity.replace(',', '');
			
			//product.price from class on input
			if(product.price > 0) {
				if(product.special_price) {
					amount = product.special_price * quantity;
				} else {
					amount = product.price * quantity;
				}
			} else {
				amount = quantity;	//donation
			}
			
			if(amount > 0) {
				order_total = parseFloat(order_total) + parseFloat(amount);
			}
	    });
	 $('div.avorderTotal h3 span').text(order_total).formatCurrency();
}
