 // sticky footer plugin
      (function($){
       
	    var footer;
      
        $.fn.extend({
          
		  stickyFooter: function(options) {
            
			footer = this;
            
            positionFooter();
      
            $(window)
              
			  .scroll(positionFooter)
              
			  .resize(positionFooter);
      
            function positionFooter() {
              
			  var docHeight = $(document.body).height() - $("#sticky-footer-push").height();
              
			  if(docHeight < $(window).height()){
                
				var diff = $(window).height() - docHeight;
                
				if (!$("#sticky-footer-push").length > 0) {
                  
				  $(footer).before('<div id="sticky-footer-push"></div>');
               
			   	}
                
				$("#sticky-footer-push").height(diff);
              
			  }
            
			}
          
		  }
       
	    });
      
	})(jQuery);
	
	$(function(){
		
	
	$('#copilot-container').mouseenter(function() {
								  
		$(this).stop().animate({width: '167'},500);						  
								  
	}).mouseleave(function() {
						  
		$(this).stop().animate({width: '36'},500);	
		
	});
	
});

	
var newsletter_timer = 0;
var facebook_timer = 0;
var twitter_timer = 0;
var rss_timer = 0;
var mouseover = false;


 $(document).ready(function() {
	 	 
	  $.preloadCssImages();
	  
	  $('.info-box').css('height', '30px', 'display', 'block');
	  
	 //Newsletter popups
	 
	  $('#newsletter-popup').addClass('hidden');
	  
	  	$('#newsletter-popup').live({
		mouseover: function() {
			
			clearTimeout(newsletter_timer);
			
	
		},
		mouseout: function() {
		
			newsletter_timer = setTimeout(function() {
		
				$('#newsletter-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
					
			}, 1000);
		
		}
		
	});
	
	$('#newsletter-btn').live({
		mouseover: function() { 
	
			if ($('#newsletter-popup').hasClass('hidden') === true)
				
				$('#newsletter-popup').hide().removeClass('hidden').fadeIn(500);
				
			clearTimeout(newsletter_timer);
		
		},
		mouseout: function() {
			
			newsletter_timer = setTimeout(function() {
	
				$('#newsletter-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}, 1000);
		
		}
		
	});
	  
	//RSS FACEBOOK TWITTER Sidebar popups
	
	$('#facebook-popup').live({
		mouseover: function() {
			
			clearTimeout(facebook_timer);
			
		},
		mouseout: function() {
		
			facebook_timer = setTimeout(function() {
		
				$('#facebook-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
					
			}, 1000);
		
		}
		
	});
	
	$('#facebook-btn').live({
		mouseover: function() { 
	
			if ($('#facebook-popup').hasClass('hidden') === true)
				
				$('#facebook-popup').hide().removeClass('hidden').fadeIn(500);
				
			if ($('#rss-popup').hasClass('hidden') === false)
			{
	
				$('#rss-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}
			
			if ($('#twitter-popup').hasClass('hidden') === false)
			{
	
				$('#twitter-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}

			clearTimeout(facebook_timer);
		
		},
		mouseout: function() {
			
			facebook_timer = setTimeout(function() {
	
				$('#facebook-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}, 1000);
		
		}
		
	});
	
	$('#twitter-popup').live({
		
		mouseover: function() {
			
			clearTimeout(twitter_timer);
						
		},
		mouseout: function() {
		
			twitter_timer = setTimeout(function() {
		
				$('#twitter-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
					
			}, 1000);
		
		}
		
	});
	
	$('#twitter-btn').live({
		mouseover: function() { 
	
			if ($('#twitter-popup').hasClass('hidden') === true)
				$('#twitter-popup').hide().removeClass('hidden').fadeIn(500);
				
			if ($('#rss-popup').hasClass('hidden') === false)
			{
	
				$('#rss-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}
			
			if ($('#facebook-popup').hasClass('hidden') === false)
			{
	
				$('#facebook-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}

			clearTimeout(twitter_timer);
		
		},
		mouseout: function() {
			
			twitter_timer = setTimeout(function() {
	
				$('#twitter-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}, 1000);
		
		}
		
	});
	
		$('#rss-popup').live({
		mouseover: function() {
			
			clearTimeout(rss_timer);
			
		},
		mouseout: function() {
		
			rss_timer = setTimeout(function() {
		
				$('#rss-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
					
			}, 1000);
		
		}
		
	});
	
	$('#rss-btn').live({
		mouseover: function() { 
	
			if ($('#rss-popup').hasClass('hidden') === true)
				$('#rss-popup').hide().removeClass('hidden').fadeIn(500);
				
			if ($('#twitter-popup').hasClass('hidden') === false)
			{
	
				$('#twitter-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}
			
			if ($('#facebook-popup').hasClass('hidden') === false)
			{
	
				$('#facebook-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}
				
				

			clearTimeout(rss_timer);
		
		},
		mouseout: function() {
			
			rss_timer = setTimeout(function() {
	
				$('#rss-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}, 1000);
		
		}
		
	});
	

//Homepage popup 

$('#home-facebook-popup').live({
		mouseover: function() {
			
			clearTimeout(facebook_timer);
			
		},
		mouseout: function() {
		
			facebook_timer = setTimeout(function() {
		
				$('#home-facebook-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
					
			}, 1000);
		
		}
		
	});
	
	$('#home-facebook-btn').live({
		mouseover: function() { 
	
			if ($('#home-facebook-popup').hasClass('hidden') === true)
				
				$('#home-facebook-popup').hide().removeClass('hidden').fadeIn(500);
				
			if ($('#home-rss-popup').hasClass('hidden') === false)
			{
	
				$('#home-rss-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}
			
			if ($('#home-twitter-popup').hasClass('hidden') === false)
			{
	
				$('#home-twitter-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}

			clearTimeout(facebook_timer);
		
		},
		mouseout: function() {
			
			facebook_timer = setTimeout(function() {
	
				$('#home-facebook-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}, 1000);
		
		}
		
	});
	
	$('#home-twitter-popup').live({
		
		mouseover: function() {
			
			clearTimeout(twitter_timer);
						
		},
		mouseout: function() {
		
			twitter_timer = setTimeout(function() {
		
				$('#home-twitter-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
					
			}, 1000);
		
		}
		
	});
	
	$('#home-twitter-btn').live({
		mouseover: function() { 
	
			if ($('#home-twitter-popup').hasClass('hidden') === true)
				$('#home-twitter-popup').hide().removeClass('hidden').fadeIn(500);
				
			if ($('#home-rss-popup').hasClass('hidden') === false)
			{
	
				$('#home-rss-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}
			
			if ($('#home-facebook-popup').hasClass('hidden') === false)
			{
	
				$('#home-facebook-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}

			clearTimeout(twitter_timer);
		
		},
		mouseout: function() {
			
			twitter_timer = setTimeout(function() {
	
				$('#home-twitter-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}, 1000);
		
		}
		
	});
	
		$('#home-rss-popup').live({
		mouseover: function() {
			
			clearTimeout(rss_timer);
			
		},
		mouseout: function() {
		
			rss_timer = setTimeout(function() {
		
				$('#home-rss-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
					
			}, 1000);
		
		}
		
	});
	
	$('#home-rss-btn').live({
		mouseover: function() { 
	
			if ($('#home-rss-popup').hasClass('hidden') === true)
				$('#home-rss-popup').hide().removeClass('hidden').fadeIn(500);
				
			if ($('#home-twitter-popup').hasClass('hidden') === false)
			{
	
				$('#home-twitter-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}
			
			if ($('#home-facebook-popup').hasClass('hidden') === false)
			{
	
				$('#home-facebook-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}
				
				

			clearTimeout(rss_timer);
		
		},
		mouseout: function() {
			
			rss_timer = setTimeout(function() {
	
				$('#home-rss-popup').fadeOut(500,function() {
					
					$(this).addClass('hidden');
					
				});
				
			}, 1000);
		
		}
		
	});
	
	//sticky footer locks footer to bottom of the page
	
	$("#footer-container").stickyFooter();
	
	//maintain a hover state for clicked map elements
	
		$(function(){
			
			$('.map-location').click(function() {
				
				$('.map-location').removeClass('map-selected');
				
				$(this).addClass('map-selected');

			});
		
		});
		
	//switch statement and set vars for map
	
	  $('#map').jMapping({
	  
	  	default_point:{lng: -95.677068, lat: 37.0625},
		
		info_window_max_width: 250, 
		
		force_zoom_level: 7,
		
		default_zoom_level: 7,
		
		category_icon_options: function(category){
			
			switch (category) {

				case 'farm1':
				
					return new google.maps.MarkerImage('/wp-content/themes/cfam/images/map-point1.png');
			  
			  	break;
				
				case 'farm2':
				
					return new google.maps.MarkerImage('/wp-content/themes/cfam/images/map-point2.png');
			  
			  	break;
				
				case 'farm3':
				
					return new google.maps.MarkerImage('/wp-content/themes/cfam/images/map-point3.png');
			  
			  	break;
				
				case 'farm4':
				
					return new google.maps.MarkerImage('/wp-content/themes/cfam/images/map-point4.png');
			  
			  	break;
				
				case 'farm5':
				
					return new google.maps.MarkerImage('/wp-content/themes/cfam/images/map-point5.png');
			  
			  	break;
				
				case 'farm6':
				
					return new google.maps.MarkerImage('/wp-content/themes/cfam/images/map-point6.png');
			  
			  	break;
				
				case 'farm7':
				
					return new google.maps.MarkerImage('/wp-content/themes/cfam/images/map-point7.png');
			  
			  	break;
				
				case 'farm8':
				
					return new google.maps.MarkerImage('/wp-content/themes/cfam/images/map-point8.png');
			  
			  	break;
				
				case 'farm9':
				
					return new google.maps.MarkerImage('/wp-content/themes/cfam/images/map-point9.png');
			  
			  	break;
				
				case 'farm10':
				
					return new google.maps.MarkerImage('/wp-content/themes/cfam/images/map-point10.png');
			  
			  	break;
				
				case 'farm11':
				
					return new google.maps.MarkerImage('/wp-content/themes/cfam/images/map-point11.png');
			  
			  	break;
				
				case 'farm12':
				
					return new google.maps.MarkerImage('/wp-content/themes/cfam/images/map-point12.png');
			  
			  	break;
				
				case 'farm13':
				
					return new google.maps.MarkerImage('/wp-content/themes/cfam/images/map-point13.png');
			  
			  	break;
				
				case 'farm14':
				
					return new google.maps.MarkerImage('/wp-content/themes/cfam/images/map-point14.png');
			  
			  	break;
				
				case 'farm15':
				
					return new google.maps.MarkerImage('/wp-content/themes/cfam/images/map-point15.png');
			  
			  	break;
				
				case 'farm16':
				
					return new google.maps.MarkerImage('/wp-content/themes/cfam/images/map-point16.png');
			  
			  	break;
			  
			  }

		}
		
	});
	
});


