/* Plugin Plus minus
author Nicolas Chardon, march 2008, for Eurostar.com 
Add the plus & minus buttons to a text field (usually a passenger number field)
*/
jQuery.fn.plus_minus = function() {
	return this.each(function(){
		// TODO : create a config section
		jQuery(this).before('<img src="/dimg/home/picto_minus.gif" width="17" height="17" class="minus_button" />').after('<img src="/dimg/home/picto_plus.gif" width="17" height="17" class="more_button"/>');
		jQuery(this).prev(".minus_button").css({"cursor":"pointer"}).click(function() {
			myInput = jQuery(this).next("input");
			// if input is disabled, the behavior too
			if(myInput.attr("disabled") != true) {
				minusMyInput = Number(myInput.attr("value"))-1;
				if (!isNaN(minusMyInput)&&minusMyInput>=0 ) {
					myInput.attr("value",minusMyInput);
				} else if (isNaN(minusMyInput)) {
					myInput.attr("value",0)
				};
			};
		})
		jQuery(this).next(".more_button").css({"cursor":"pointer"}).click(function() {
			myInput = jQuery(this).prev("input");
			// if input is disabled, the behavior too
			if(myInput.attr("disabled") != true) {
				plusMyInput = Number(myInput.attr("value"))+1;
				if (isNaN(plusMyInput)){
					myInput.attr("value",0)
				} else if (!isNaN(plusMyInput)&&plusMyInput>=0&&plusMyInput<=99 ) {
					myInput.attr("value",plusMyInput);
				};
			};
		})
	});
};
