$(function() {
	/* Add input hint text */
	$("#s").inputHint({ className: "faded" });
	/* Convert Emails */
	$('.nospam').nospam();
	/* Prevent multiple submissions */
	$('.submitOnce').submitOnce();
	/* Banner Images */
	$('ul.banners').each(function(i) {
		var list = $(this), options = $('<ul />').addClass('bannerOptions').insertBefore(this);
		$('li > img', this).each(function(j) {
			var id = 'banners_'+i+'_'+j, b = $(this);
			var item = $('<li />')
				.append('<label for="'+id+'">'+b.attr('alt')+' <span class="faded">('+b.attr('width')+'x'+b.attr('height')+')</span></label>')
				.prepend('<input id="'+id+'" type="radio" name="banners_'+i+'" />')
				.appendTo(options)
			$('input', item).click(function() {
				$('li', list).hide().eq(j).show();
			});
		});
		$('input:first', options).click();
	});
	/* Pricing Packages */
	$('ol.pricing > li').mouseenter(function(e) {
		$(this).filter(':not(.recommended)')
			.stop(true, true)
			.addClass('recommended')
			.hide()
			.fadeIn('fast')
			.siblings()
			.removeClass('recommended');
	});
});

$.fn.moneyFormat = function() {
	return this.each(function() {
		var v = this.nodeName == 'INPUT' ? $(this).val() : $(this).html();
		var n = parseFloat($(this).val()).toFixed(2).split('.');
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(n[0])) {
			n[0] = n[0].replace(rgx, '$1' + ',' + '$2');
		}
		v = n[0] + (n.length > 1 ? '.' + n[1] : '');
		if (this.nodeName == 'INPUT') {
			$(this).val(v);
		} else {
			$(this).html(v);
		}
	});
};

$.fn.submitOnce = function() {
	return this.each(function() {
		var f = $(this).is('form') ? $(this) : $(this).closest('form'), t = false;
		f.submit(function(e) {
			if (t) {
				e.preventDefault();
			} else {
				t = setTimeout(function() { t = false; }, 1000);
			}
		});
	});
};