$(document).ready(function() {

	$("#menu a").prepend('<div></div>');

	$("#menu img").each(function(i,v) {

		if($(this).attr("data-hover") && !$(this).parent().parent().hasClass("selected")) {
		
			var obj = this,
				src = $(obj).attr("src");
			
			$(this).parent().parent().hover(function() {
				$(obj).attr("src", $(obj).attr("data-hover"));
				$(this).addClass("hover");
			}, function() {
				$(obj).attr("src", src);
				$(this).removeClass("hover");
			});
			
		}
		
		if($(this).parent().parent().hasClass("selected")) {
			$(this).attr("src", $(this).attr("data-hover"));
		}
	
	});
	

		// Cybernautic Form Input Labeler v1.0 //
		

		$(".inField").each(function(i,v) {
		
					
			var theInput = $(this).attr("data-label");  // Default search input text
			$(this).val(theInput);			
		
			// When search input is focused, clear default value
			$(this).focus(function() {
			
				if($(this).val() == theInput) {
				
					theInput = $(this).val();
					$(this).val("");
				
				}
			
			});
			
			// When search input is unfocused and blank, return to default state
			$(this).focusout(function() {
			
				if($(this).val() == "") {
					$(this).val(theInput);
				}
			
			});
			

		});

});








	// CND Image Slider
	//////////////////////////////////////////////////////////////////////////////////////
	
	$(document).ready(function() {
	
	
			
		var cndSlider = $("#smallSlider"), // DIV that contains slider Images
		cndMenu = $("#sliderMenu"), // DIV that contains slider info
		delay = 10000, // Delay between automatic advancement
		cndCnt = 0, // Initialize Counter
		cndVisible = 0, // Default visible image (index)
		interval = null,
		changing = false;
		  
		  
		function onChange() {
					
			changing = false;
			
			$(".bullet").removeClass("current");
			$(".bullet").eq(cndVisible).addClass("current");
			
		}    
								  
			  
			  
		function nextPic(d) {
		
			changing = true;
				  
			  
				$("img", cndSlider).eq(cndVisible).fadeOut("slow", function() {  // Hide current image before advancing
					  
					// If we've reached the end, wrap back to the beginning
					if(d == 'r') { 
						if((cndVisible - 1) < 0) { var feq = (cndCnt - 1); } else { var feq = (cndVisible - 1); }
					} else {  
						if((cndVisible + 1) == cndCnt) { var feq = 0; } else { var feq = (cndVisible + 1); }
					}
				  
					// Bring in next image
					$("img", cndSlider).eq(feq).fadeIn("slow", function() {
						  				 	  
						cndVisible = feq; // Set index of new visible image
						onChange(); // Refresh information panel
					  
					}); 
					  
		  
					  
				});
			
				
		}
			                               
										   
		  
		// Count Slider Images
		$("img", cndSlider).each(function(i,v) {
			  
			cndCnt++;

						  
			// Show default image
			if(i == cndVisible) {
				$(this).show();
			}
			  
		});
		  
		  

						  
		if(cndCnt > 1) {  // Only setup timer if there are multiple images loaded
			
			
			for(var z = 0; z < cndCnt; z++) {
				cndMenu.append('<div class="bullet">&nbsp;</div>');
			}
			
			$("div", cndMenu).each(function(i,v) {
				$(this).click(function() {

					clearInterval(interval);
				
						changing = true;
							  
						  
							$("img", cndSlider).eq(cndVisible).fadeOut("slow", function() {  // Hide current image before advancing
												  
								// Bring in next image
								$("img", cndSlider).eq(i).fadeIn("slow", function() {
														  
									cndVisible = i; // Set index of new visible image
									onChange(); // Refresh information panel
									interval = setInterval(nextPic, delay);
								  
								}); 
								  
					  
								  
							});
				
				
				});
			});
			
			interval = setInterval(nextPic, delay); // Set timer
			onChange();  // Initialize information panel
			  
		}
		
		

		 
		// This will stop the slideshow when the window/tab is not focused, 
		// and then it will start again when the window/tab is focused.
		  
		var blurred = false; 
			
		$(window).focus(function(){
		  
			if(blurred) {
				setTimeout(function() { nextPic(); }, delay);
			}
			  
		});
		  
		$(window).blur(function(){
		  
			 blurred = true;
			 clearInterval(interval);
			   
		});
			
			
	
	
	});
	
	
	
	
	

	// CND Image Slider (Large)
	//////////////////////////////////////////////////////////////////////////////////////
	
	$(document).ready(function() {
	
	
			
		var cndSliderLarge = $("#sliderLarge"), // DIV that contains slider Images
		cndMenuLarge = $("#sliderMenuLarge"), // DIV that contains slider info
		banner = $("#slider .banner"), // DIV that contains slider info
		delayLarge = 10000, // Delay between automatic advancement
		cndCntLarge = 0, // Initialize Counter
		cndVisibleLarge = 0, // Default visible image (index)
		intervalLarge = null,
		changingLarge = false;
		  
		  
		function onChangeLarge() {
					
			changingLarge = false;
			
			$(".bullet", cndMenuLarge).removeClass("current");
			$(".bullet", cndMenuLarge).eq(cndVisibleLarge).addClass("current");
			
			var caption = $("img", cndSliderLarge).eq(cndVisibleLarge).attr("alt");
			banner.html(caption).fadeIn();
			
		}    
								  
			  
			  
		function nextPicLarge(d) {
		
			changingLarge = true;
				  
				banner.fadeOut("slow", function() { 
				
					$("img", cndSliderLarge).eq(cndVisibleLarge).fadeOut("slow", function() {  // Hide current image before advancing
						  
						// If we've reached the end, wrap back to the beginning
						if(d == 'r') { 
							if((cndVisibleLarge - 1) < 0) { var feq = (cndCntLarge - 1); } else { var feq = (cndVisibleLarge - 1); }
						} else {  
							if((cndVisibleLarge + 1) == cndCntLarge) { var feq = 0; } else { var feq = (cndVisibleLarge + 1); }
						}
					  
						// Bring in next image
						$("img", cndSliderLarge).eq(feq).fadeIn("slow", function() {
												  
							cndVisibleLarge = feq; // Set index of new visible image
							onChangeLarge(); // Refresh information panel
						  
						}); 
							
					}); 
					
				});
			
				
		}
			                               
										   
		  
		// Count Slider Images
		$("img", cndSliderLarge).each(function(i,v) {
					  
			cndCntLarge++;
  
			// Show default image
			if(i == cndVisibleLarge) {
				$(this).show();
			}
			  
		});
		  
		  

						  
		if(cndCntLarge > 1) {  // Only setup timer if there are multiple images loaded
			
			
			for(var z = 0; z < cndCntLarge; z++) {
				cndMenuLarge.append('<div class="bullet">&nbsp;</div>');
			}
			
			$("div", cndMenuLarge).each(function(i,v) {
				$(this).click(function() {

					clearInterval(intervalLarge);
				
						changingLarge = true; 
							  
						  
							$("img", cndSliderLarge).eq(cndVisibleLarge).fadeOut("slow", function() {  // Hide current image before advancing
												  
								// Bring in next image
								$("img", cndSliderLarge).eq(i).fadeIn("slow", function() {
														  
									cndVisibleLarge = i; // Set index of new visible image
									onChangeLarge(); // Refresh information panel
									intervalLarge = setInterval(nextPicLarge, delayLarge);
								  
								}); 
								  
					  
								  
							});
				
				
				});
			});
			
			intervalLarge = setInterval(nextPicLarge, delayLarge); // Set timer
			onChangeLarge();  // Initialize information panel
			  
		}
		
		

		 
		// This will stop the slideshow when the window/tab is not focused, 
		// and then it will start again when the window/tab is focused.
		  
		var blurredLarge = false; 
			
		$(window).focus(function(){
		  
			if(blurredLarge) {
				setTimeout(function() { nextPicLarge(); }, delayLarge);
			}
			  
		});
		  
		$(window).blur(function(){
		  
			 blurredLarge = true;
			 clearInterval(intervalLarge);
			   
		});
			
			
	
	
	});
		
	
	
