/* Author: 

*/

// inFieldLabels Options:
// $("label").inFieldLabels({ optionName:value });
// OPACITY { fadeOpacity:0.5 }
// OPACITY { fadeDuration:300 }

//$("#searchform label").inFieldLabels({ fadeOpacity:0.3 });

$("label").inFieldLabels({ fadeOpacity:0.3 });

//On Hover Over
function megaHoverOver(){
    $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
	//$(this).find(".sub").stop().show(); //Find sub and show it
    (function($) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            $(this).find("ul").each(function() { //for each ul...
                rowWidth += $(this).width(); //Add each ul's width together
            });
        };
    })(jQuery); 

    if ( $(this).find(".row").length > 0 ) { //If row exists...

        var biggestRow = 0;	

        $(this).find(".row").each(function() {	//for each row...
            $(this).calcSubWidth(); //Call function to calculate width of all ul's
            //Find biggest row
            if(rowWidth > biggestRow) {
                biggestRow = rowWidth;
            }
        });

        $(this).find(".sub").css({'width' :biggestRow}); //Set width
        $(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin

    } else { //If row does not exist...

        $(this).calcSubWidth();  //Call function to calculate width of all ul's
        $(this).find(".sub").css({'width' : rowWidth}); //Set Width

    }
}
//On Hover Out
function megaHoverOut(){
  $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      $(this).hide();  //after fading, hide it
  });
}

//Set custom configurations
var config = {
     sensitivity: 5, // number = sensitivity threshold (must be 1 or higher)
     interval: 0, // number = milliseconds for onMouseOver polling interval
     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
     timeout: 100, // number = milliseconds delay before onMouseOut
     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
};

$("ul#nav li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
$("ul#nav li").hoverIntent(config); //Trigger Hover intent with custom configurations


/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
function mycarousel_initCallback(carousel) {
    jQuery('.spotlight-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });
 
    jQuery('#spotlightcarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });
 
    jQuery('#spotlightcarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};
 
// Ride the carousel...

jQuery("#spotlightcarousel").jcarousel({
	scroll: 1,
	auto: 15,
    wrap: 'last',
	initCallback: mycarousel_initCallback,
	// This tells jCarousel NOT to autobuild prev/next buttons
	buttonNextHTML: null,
	buttonPrevHTML: null
});


$('div.unevenheights').setAllToMaxHeight()

// ========================================== 
// VALIDATE THE COMMENTS FORM
// ==========================================
 
// First add the necessary classes
$("#email").addClass('required email');
$("#author").addClass('required');
$("#comment").addClass('required');
 
 	jQuery.validator.messages.required = "";
	jQuery.validator.messages.email = "";	
	
	$("#commentform").validate({
		
		
		errorPlacement: function(error,element) { 
                       return true; 
                    }, 

		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = 'Please correct the items highlighted above:';
				$("#errorMsg").html(message);
				$("#errorMsg").fadeTo('fast', 1).show();		
				//$("p.formDescription").hide();
			} else {
				$("#errorMsg").hide();
				//$("p.formDescription").show();
			}
		},
		onkeyup: false,
		//submitHandler: function(form) {

			
		//		$("div.errorMsg").hide();
				
		//		$("#gympassform").ajaxSubmit(options);
				
		//		$("div#passForm").hide();
				

				//return true; 	
		//},
//		messages: {
//			required: " ",

//			username: {
//				required: "Enter a username",
//				minlength: jQuery.format("Enter at least {0} characters"),
//				remote: jQuery.format("{0} is already in use")
//			},
//			password: {
//				required: "Provide a password",
//				rangelength: jQuery.format("Enter at least {0} characters")
//			},
//			password_confirm: {
//				required: "Repeat your password",
//				minlength: jQuery.format("Enter at least {0} characters"),
//				equalTo: "Enter the same password as above"
//			},
//			email: {
//				required: " ",
//				minlength: "Please enter a valid email address",
//				remote: jQuery.format("{0} is already in use")
//			},
//			dateformat: "Choose your preferred dateformat",
//			terms: " "
//		},
		debug:false
	});
 
 
// ========================================== 
// END VALIDATION
// ==========================================






















