if(!jsEnhancements) { var jsEnhancements = new Object(); }

jsEnhancements = {
	init: function(){
  		// do basic form features
		jsEnhancements.formInit();
  	},
  	
 	/**
 	 * This function well add an onclick event for every <a class="button">
 	 * element within the form tag which will submit the form.
	 */ 	
  	formInit: function(){
		// init vars
		var buttonHtml = '<a class="button" href="#"><b>&nbsp;</b><span>{innerText}</span><i>&nbsp;</i></a>';

		$('form').each(function(){
  			// init vars
			var formId = $(this).attr('id');
			
			// formId is valid
			if(formId != '') {
				// loop every button to be replaced
				$('#' + formId + ' .replaceWithLink').each(function(){
					// get the value of the button - this will become the inner html of the link
					var innerText = $(this).children('input:submit').val();
	
					// replace everything in this element with the above html
					$(this).html(buttonHtml.replace('{innerText}', innerText));
				});
	
				// add onclick event for button
				$('#' + formId + ' a.button').each(function () {
					$(this).bind("click", function(e) {
						e.preventDefault();
						$('#'+formId).submit();
					});
				});
			}
		});
	}
};

$(document).ready(function() {
	// init enhancements
	jsEnhancements.init();
	
	// Last child (fix missing selector support for IE6, IE7, ..)
	$('.spotlight:last-child, table.datagrid tr:last-child, #blog .article:last-child, #subnavigation li:last-child').addClass('lastChild');

	// First child (fix missing selector support for IE6, IE7, ..)
	$('#navigation li:first-child, #subnavigation li:first-child').addClass('firstChild');

	// If first navigation item is selected
	// Fixing missing double class support for IE6
	$('#navigation li.selected:first-child').addClass('firstChildSelected');
	
	// Equal height cols on homepage
	var highestCol = Math.max($('#categories .first').height(),$('#categories .last').height());
	$('#categories .spotlight').height(highestCol);
	
	// Append classes for rounded corners instead of messing up the templates
	$('.roundImage').append('<div class="rcTL">&nbsp;</div><div class="rcTR">&nbsp;</div><div class="rcBL">&nbsp;</div><div class="rcBR">&nbsp;</div>');

	// Fix focus
	$('input, textarea').bind('focus', function(e) { $(this).addClass('focus'); })
	$('input, textarea').bind('blur', function(e) { $(this).removeClass('focus'); });
	$('#searchForm input[type="text"], #newsletterSignupForm input[type="text"]').bind('click', function(e) { $(this).select(); });
});

