// JAVASCRIPT

$(document).ready(function(){
						   
	// FANCYBOX**********************************************************************
	
	$(".fancybox").fancybox();
	$(".left").fancybox();
	$(".img-right").fancybox();
	$(".map").fancybox({'width' : '75%', 'height':'75%', 'autoScale' : false, 'transitionIn' : 'fade', 'transitionOut' : 'fade', 'type' : 'iframe'});

	
	// DUAL PLANT CALLOUT************************************************************

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);
	
	
	$("#plants").hoverIntent(
		function () {
			$('#plants_callout').fadeIn();
			},
			
		function () {
		});
	$("#close").click(function(){
		$('#plants_callout').fadeOut();
		});	

	// ACCORDION MENU***************************************************************
	
	$('.accordionButton').click(function() {
		$('.accordionButton').removeClass('on');
	 	$('.accordionContent').slideUp('normal');
		if($(this).next().is(':hidden') == true) {
			$(this).addClass('on');
			$(this).next().slideDown('normal');
		 } 
	 });
	  		
	$('.accordionContent').hide();
	
	
	// AUTOMATED SCROLLING***********************************************************
    
	$('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
    && location.hostname == this.hostname) {
      var $target = $(this.hash);
      $target = $target.length && $target
      || $('[name=' + this.hash.slice(1) +']');
      if ($target.length) {
        var targetOffset = $target.offset().top;
        $('html,body')
        .animate({scrollTop: targetOffset}, 1000);
       return false;
      }
    }
    });
	
	// FEATURE LIST******************************************************************
	
	$.featureList(
		$("#tabs li a"),
		$("#output li"), {
			start_item  :   0
		}
	);
	
	$('#thankyou').hide();
	
});

//CONTACT FORM VALIDATION***********************************************************

// Form Validate
$(function() {
		   
	$("#submit").click(function() {
									
		// validate and process form here
		var error = 'The following fields are required:\n\n';
		var invalid = 0;
		
		var name = $("input#name").val();
		if (name == "" || name == "Name *") {
		error += '- Name\n';
		invalid = 1;
		}
		var phone = $("input#phone").val();
		if (phone == "" || phone == "Phone Number *") {
		error += '- Phone\n';
		invalid = 1;
		}
		var email = $("input#email").val();
		var areaofinterest = $("textarea#areaofinterest").val();
		
		if(invalid == 1){
		alert (error);
		return false;
		}
		
		window.dataString = 'Name='+ name + '&Phone=' + phone + '&Email=' + email + '&Area of Interest=' + areaofinterest;
		
		//AJAX for Form Submission
		$.ajax({
		type: "POST",
		url: "form/process.php",
		data: window.dataString,
		success: function() {
		$("#form").hide();
		$("#thankyou").fadeIn("slow");
		}
		});
		return false;
	});
	
});

// Date*****************************************************************************
function date(get) {
	var mydate=new Date()
	var year=mydate.getFullYear()
	var day=mydate.getDay()
	var month=mydate.getMonth()
	var daym=mydate.getDate()
	var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
	if(get=="month"){document.write(montharray[month]);}
	if(get=="date"){document.write(daym);}
	if(get=="year"){document.write(year);}
}
