/**
	Run Onload
**/
$(document).ready(function()
{
	// Date picker - is too slow in IE6
	var datebox = $('.date');
	if( datebox.length && !( $.browser.msie && $.browser.version < 7 ) )
		datebox.datepicker({ showButtonPanel: true, dateFormat: 'yy-mm-dd', constrainInput:true, duration: 'fast' });
		
	// Apply rounded corners
	var rules = {};
	$('.rounded').each(
		function()
		{
			var reg = new RegExp(/rounded-(\d+?px)/);
			var matches = reg.exec( $(this).attr('class') );

			if( rules[ matches[0] ] == null )
			{
				DD_roundies.addRule( '.' + matches[0], matches[1], true );
				rules[ matches[0] ] = true;
			}
		}
	);
	delete rules;

	// Apply shadows
	// $('.shadowed').dropShadow({left: 5, top: 5, opacity: 0.3, blur: 4});

	var tabs = $("ul.tabs");
	if( tabs.length )
		tabs.tabs("div.panes > div", { history: true }); 
		
	
	if( $('#detailsform').length ) {

		// Form Validation
		$('#detailsform').validate({

		// Fade In/Out to capture attention
			highlight: function(element, errorClass) {
				 $(element).fadeOut(function() {
					 $(element).fadeIn();
					 $(element).addClass('badinput');
				 });
			},

		// This hides the error message itself as it's tough to place them properly in an address form
			errorPlacement: function(error, element) {
				error.hide();
			},

		// Plugin defaults to 'error'.  this uses the current hamilton form error class.
			errorClass: 'badinput',

			invalidHandler: function() {
				return false;
			},

		// Check every field, every time it loses focus.
			onfocusout: function(element) {
				if ( !this.checkable(element) ) {
					this.element(element);
				}
			},

		// Do not validate every keystroke
			onkeyup: false,

		// Remove the 'badinput' class while you are editing a field that had an error in it.
			focusCleanup: true
			
		});	
	}
					
});
