/**
 * Remplacement des boutons de formulaire par des liens qui garderont la même fonctionnalité
 * @author christian@konfiture.com
 */
function uniqId()
	{
		if ( typeof this.counter == 'undefined' )
			this.counter = 0;
		this.counter++;
		return this.counter;
	};

 (function($)
	{
		$.fn.arcadimButton = function(params)
			{

				var defaults =
					{
						showIcon: true,
						uiIcon: 'ui-icon-check',
						submitValue: 'Soumettre',
						submitTitle: 'Soumettre le formulaire',
						resetValue: 'Effacer',
						resetTitle: 'Réinitialiser les valeurs par défaut du formulaire'
					};

				var params = $.extend(defaults, params);

				this.each(function()
					{
						var isButton = this.tagName.toUpperCase().trim() == 'BUTTON';
						var isInput = this.tagName.toUpperCase().trim() == 'INPUT';
						var isReset = $(this).attr('type').toLowerCase().trim() == 'reset';
						var isSubmit = $(this).attr('type').toLowerCase().trim() == 'submit';

						var self = this;

						var value = isButton ? $(self).text() : $(self).attr('value');
						var title = $(self).attr('title');

						if ( ! value || value == undefined || value == '' )
							value = isSubmit ? params.submitValue : params.resetValue;

						if ( ! title || title == undefined || title == '' )
							title = isSubmit ? params.submitTitle : params.resetTitle;

						var iconHtml = '';
						if ( params.showIcon )
							{
								var iconHtml = params.uiIcon;
								iconHtml = '<span class="ui-icon ' + iconHtml + '"></span>';
							}

						var buttonId = $(self).attr('id') ? $(self).attr('id') : 'generated-button-' + uniqId();
						var buttonHtml = '<a id="' + buttonId + '" class="button" href="" title="'
							+ title	+ '">' + iconHtml + '<span class="button-text">' + value + '</span></a>';

						$(self).after(buttonHtml);
						$(self).remove();

						$('#' + buttonId)
							.data('buttonIsSubmit', isSubmit)
							.data('buttonIsReset', isReset)
							.tooltip(tooltipOpts)
							.click( function(event)
								{
									event.preventDefault();
									if ( $(this).data('buttonIsSubmit') ) {
										$(this).parents('form').first().submit();
									} else if ( $(this).data('buttonIsReset'))
										$(this).parents('form').first().get(0).reset();
								})
						; // $('#' + buttonId)

					});

			}
	})(jQuery);


$(document).ready( function()
	{
		$('#details').arcadimButton({
			uiIcon: 'ui-icon-circle-zoomin'
		});
		$('input:submit').not('.norestyle').arcadimButton();
		$('input:reset').not('.norestyle').arcadimButton();
		$('button').not('.norestyle').arcadimButton();

		if ( ! ie || ie > 7 )
			$('.button')
				.css('font-size', '14px');

		if (ie != 7)
			Cufon.replace('.button', {hover: true});

	});

