$(function(){

	if ( ($.browser.msie && $.browser.version > 6) || !$.browser.msie )
	{
		$('.corners').prepend('<span class="tl"></span><span class="tr"></span>');
		$('.corners').not('.noBottom').prepend('<span class="bl"></span><span class="br"></span>');
	}
	
	// Animate in a wave
	$('#navHome ul').hover(function(){
		var li = $(this).children('li');
		li.addClass('active');
		
		li.each(function(index){
			$(this).animate({
				height: '100%'
		    }, 300 + (index * 50), "swing");
		});
	}, function(){
		var li = $(this).children('li');
		li.removeClass('active');
		
		li.each(function(index){
			$(this).animate({
				height: '30px'
		    }, 300 + (index * 50), "swing");
		});
	});

});



jQuery.fn.perfectForm = function(options)
{
	var settings = {
    	overlap: true				
    }

    if(options) {
        jQuery.extend(settings, options);
    };

	this.each(function(){
		var input = $(this).next('input');
		var label = $(this);
		
		// first check all inputs for values, then hide it's label if it has a value
		if( settings.overlap ) {
			label.addClass('overlap');
		}
		
		if( settings.overlap && input.val() != '' ) {
			label.hide();
		}
		
		label.click(function(){
			label.hide();
			input.focus();
		}, function(){
			if( input.val() == '' ) {
				label.show();
			}
		});
		
		// then add a focus event to all inputs to hide their labels when focused on, 
		// and remain hidden on blur if a value is entered
		input.focus(function(){
			label.hide();
		}).blur(function(){
			if( $(this).val() == '' ) {
				label.show();
			}
		});
		
		// do the same thing for elements added to the DOM after page load. jQuery 1.3 has the
		// 'live' method, but doesn't support focus or blur yet, so use livequery for now.
		input.livequery('focus', function(){
			label.hide();
		}).livequery('blur', function(){
			if( $(this).val() == '' ) {
				label.show();
			}
		});
	});
}		

jQuery.fn.autoWidth = function(options) 
{
    var settings = {
    	minWidth   : false,
        limitWidth  : false,
        ignore	: ''
    }

    if(options) {
        jQuery.extend(settings, options);
    };

    var maxWidth = 0;

	this.not(settings.ignore).each(function(){
        if ($(this).width() > maxWidth){
        	if(settings.limitWidth && maxWidth >= settings.limitWidth) {
        		maxWidth = settings.limitWidth;
        	} 
        	else if(settings.minWidth && maxWidth <= settings.limitWidth)
        	{
        		maxWidth = settings.minWidth;
        	} 
        	else 
        	{
        		maxWidth = $(this).width();
        	}
        }
	});	 

	this.not(settings.ignore).width(maxWidth);
}