/* =========================================================================
 * 
 * Troy McGinnis JavaScript Library
 * 
 * JavaScript Library designed and developed to be used with McGinnis
 * Berry Crops website. http://www.berrycrops.net
 *
 * Copyright 2011, Troy McGinnis
 * Date: Tues September 06, 2011
 *
 * ========================================================================= */

/* -------------------------------------------- */
/* 				 General functions	  			*/
/* -------------------------------------------- */

/*--- Preload Button Images ---**/
$(document).ready(function(){	
	//Image preload
	$.preload(
		 'images/inquire_banner_button_click.png'
		,'images/inquire_banner_button_click_small.png'
		,'images/inquire_banner_button_hover.png'
		,'images/inquire_banner_button_hover_small.png'
		,'images/send_inquiry_button_click.png'
		,'images/send_inquiry_button_hover.png'
		//,'images/content_repeat.png'
	);
	
	//Animate scroll to top
	$('a[href=#top]').click(function(){
		$('html, body').animate({scrollTop:0}, 'fast');
	});
	
	//Navigation hover sub-nav
	$("div.link-col a").hover(function(){
		$("div.sub-background").css("height", "37px");
		switch ($(this).text()) {
			case "Berries":
				$("div#berries-hover").slideDown('fast').show();
				break;
			case "About Us":
				$("div#about-hover").slideDown('fast').show();
				break;
			case "Contact":
				$("div#contact-hover").slideDown('fast').show();
				break;
		}; 
	}, function() {
		$("div.sub-background").slideUp(350);
	});
	
	$("div.sub-background").hover(function(){
		$("div.sub-background").stop();
		$("div.sub-background").css("height", "37px");
	}, function(){
		$("div.sub-background").slideUp(350);
	});
	
});

/* -------------------------------------------- */
/* 				Index page functions  			*/
/* -------------------------------------------- */

/*--- Showcase Functions ---**/
function runShowcase(){
	//Hide all the rollovers
	$(".rollover").hide();
	
	//Showcase image rotation
	$('.showcase-image-rotation').cycle({
		fx: 'fade',
		speed: 3000
	})
	
	//Link Left hover
	$("div#overlay-left").hover(function(){
		$("div.link-left").find('.rollover').stop().fadeTo(500, 1);
	}, function(){
		$("div.link-left").find('.rollover').stop().fadeTo(750, 0);
	})
	
	//Link Middle hover
	$("div#overlay-middle").hover(function(){
		$("div.link-middle").find('.rollover').stop().fadeTo(500, 1);
	}, function(){
		$("div.link-middle").find('.rollover').stop().fadeTo(750, 0);
	})
	
	//Link Right hover
	$("div#overlay-right").hover(function(){
		$("div.link-right").find('.rollover').stop().fadeTo(500, 1);
	}, function(){
		$("div.link-right").find('.rollover').stop().fadeTo(750, 0);
	})
}

/* -------------------------------------------- */
/* 			 Nutrition page functions  			*/
/* -------------------------------------------- */

/*--- Nutrition Table Highlight Functions ---**/
function nutritionTable() {
	//Table cell hover highlight
	$("div.col").hover(function(){
		$(this).toggleClass("col-hover");
	});
	
	//Table row hover highlight
	$("div.col.fruit").hover(function(){
		$(this).toggleClass("table header-hover");
		$(this).parent().toggleClass("row-hover");
	});
}

/* -------------------------------------------- */
/* 			Leadership page functions 			*/
/* -------------------------------------------- */

/*--- Nutrition Table Highlight Functions ---**/
function leadershipTable() {
	//Table cell hover highlight
	$("div.col").hover(function(){
		$(this).toggleClass("col-hover");
	});
	
	$("div.col.sub.header").hover(function(){
		$(this).toggleClass("table header-hover-light");
		$(this).parent().toggleClass("row-hover");
	})
}

/* -------------------------------------------- */
/* 			   Inquire page functions  			*/
/* -------------------------------------------- */

/*--- Validate Inquire Form Functions ---**/
function inquireValidation() {
	jQuery.validator.addMethod("notEqual", function(value, element, param) {
		return this.optional(element) || value != param;
	}, "Please enter your name.");
	
	$('#inquire-form').validate({
		rules: {
		    name: {
		        required: true,
		        notEqual: "Contact Name"
		    },
			email: {
				required: true,
				email: true,
				notEqual: "E-mail"
			},
			phone: {
				required: true,
				phoneUS: true,
				notEqual: "Phone"			
			}
		},
		messages: {
		    name: {
		        required: "A contact name is required."
		    },
			email: {
				required: "A valid e-mail address is required.",
				email: "Please enter a valid e-mail address."
			},
			phone: {
				required: "A valid phone number is required.",
				phoneUS: "Please enter a valid phone number."
			}
		},
		errorPlacement: errorPlacement
	});
	
	/* Error Placement Function for form validation  */
	function errorPlacement(error, element)
	{
		var name = element.attr("name");
    	error.insertAfter(element.parent());
	}
}


	

