
	$(document).ready(function() {
	
		$("#menu a").prepend('<span class="gradient"></span>');
		$("h1.silver").prepend('<span class="gradient"></span>');
	
	});
	
	
	
	
	
	
	// CND Image Slider
	//////////////////////////////////////////////////////////////////////////////////////
	
	$(document).ready(function() {
	
	
			
		var cndSlider = $("#slider"), // DIV that contains slider Images
		cndText = $("#sliderInfo"), // DIV that contains slider Images
		delay = 10000, // Delay between automatic advancement
		cndCnt = 0, // Initialize Counter
		cndVisible = 0, // Default visible image (index)
		interval = null,
		changing = false;
		  
		  
		function onChange() {
		

			var text = $("img", cndSlider).eq(cndVisible).attr("data-text");
			
			if(text != "") {
				cndText.html(text).show("blind", { direction: "horizontal" }, 1000, function() { changing = false; });
			}
			
		}    
								  
			  
			  
		function nextPic(d) {

			changing = true;
				  
			cndText.hide("blind", { direction: "horizontal" }, 1000, function() {
			  
				$("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++;
			
			$(this).wrap('<a href="' + $(this).attr("data-url") + '"></a>');
			  
			// Show default image
			if(i == cndVisible) {
				$(this).show();
			}
			  
		});
		  
		  

						  
		if(cndCnt > 1) {  // Only setup timer if there are multiple images loaded
			  		  
			interval = setInterval(nextPic, delay); // Set timer
			onChange();  // Initialize information panel
			  
		}
		
		
		$("#feature .left").click(function() {
		
			if(!changing) {
			
				nextPic('r');
			
			}
		
		});
		
		$("#feature .right").click(function() {
		
			if(!changing) {
			
				nextPic('f');
			
			}
		
		});	  
		 
		// 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);
			   
		});
			
			
	
	
	});
	
	
	
	
	
