jQuery.NiceJForms = {
	options : {
		imagesPath               : "/images/"
	}
};

jQuery.preloadImages = function()
{
	var imgs = new Array();
	for(var i = 0; i<arguments.length; i++)
	{
		imgs[i] = jQuery("<img>").attr("src", arguments[i]);
	}
	
	return imgs;
}

jQuery(document).ready(function($){
	
	jQuery.NiceJForms.preloads = jQuery.preloadImages(jQuery.NiceJForms.options.imagesPath + "button_left_xon.gif", jQuery.NiceJForms.options.imagesPath + "button_right_xon.gif");

	$('input[@type=submit]').add($('input[@type=button]')).add($('input[@type=reset]')).each(function(i){
		$(this).addClass("buttonSubmit");
		var buttonLeft = document.createElement('img');
		jQuery(buttonLeft).attr({src: jQuery.NiceJForms.options.imagesPath + "button_left.gif"}).addClass("buttonImg");
		$(this).before(buttonLeft);
		
		var buttonRight = document.createElement('img');
		jQuery(buttonRight).attr({src: jQuery.NiceJForms.options.imagesPath + "button_right.gif"}).addClass("buttonImg");
		
		if($(this).next()) {$(this).after(buttonRight)}
		else {$(this).parent().append(buttonRight)};
		
		$(this).hover(
			function(){$(this).attr("class", $(this).attr("class") + "Hovered"); $(this).prev().attr("src", jQuery.NiceJForms.options.imagesPath + "button_left_xon.gif"); $(this).next().attr("src", jQuery.NiceJForms.options.imagesPath + "button_right_xon.gif")},
			function(){$(this).attr("class", $(this).attr("class").replace(/Hovered/g, "")); $(this).prev().attr("src", jQuery.NiceJForms.options.imagesPath + "button_left.gif"); $(this).next().attr("src", jQuery.NiceJForms.options.imagesPath + "button_right.gif")}
		);
	});
});