$(document).ready(function(){

	$('.textContainer').cornerz({
				radius: 8,
				background: "#FFFFFF"
				
	});
	

	$("#nav a").hover(
		// over
		function(){
			var image = $(this).children(":first-child");
			
			// store the original image src
			image.data( "originalsrc" , image.attr("src") );
			
			// add -over to the image unless it is already -over
			if (!image.attr("src").match(/-over/) ) {
				image.attr( "src", image.attr("src").replace(/\./, "-over.") );
			}
			
		},
		
		// out
		function(){
			var image = $(this).children(":first-child");
			
			// replace the original src
			image.attr("src", image.data("originalsrc"));
			image.data("originalsrc", null);
		}
	);



	$("#nav a").click(function(e){
		e.preventDeafult;
		var theDiv = $(this).attr("href").substring(1);
		
		if ($("#" + theDiv).is(":visible")) { return };
		
		// reset nav
		$('#nav a').each(function() {
			$(this).children(":first-child").attr( "src", $(this).children(":first-child").attr("src").replace(/-over\./, ".") );
		});
		// set selected
		$(this).children(":first-child").attr( "src", $(this).children(":first-child").attr("src").replace(/\./, "-over.") );
		$(this).children(":first-child").data( "originalsrc" , $(this).children(":first-child").attr("src") );
		
		// show section
		$(".section:visible").fadeOut('slow', function(){
			$("#" + theDiv).fadeIn();
		});
		
		// track
		pageTracker._trackPageview("/" + theDiv + ".html");
		
	});
	
	
	$('.learnMore').click(function (e) {
		e.preventDefault();
		$.get("/learn_more.html", function(data){
			$.modal(data, {opacity : '75'});
		});
		
		// track
		pageTracker._trackPageview("/learn_more.html");
		
	});
	
	$('.video').click(function (e) {
		e.preventDefault();
		$.get("/video.html", function(data){
			$.modal(data, {opacity : '75'});
		});
		
		// track
		pageTracker._trackPageview("/video.html");
		
	});
	
	$('.video2').click(function (e) {
		e.preventDefault();
		$.get("/video2.html", function(data){
			$.modal(data, {opacity : '75'});
		});
		
		// track
		pageTracker._trackPageview("/video2.html");
		
	});
	
	
	

});

window.onload = function() {
	// preload
	$("#nav a img").each(
		function() {
			if (!$(this).attr("src").match(/-over/) ) {
				$("<img>").attr( "src", $(this).attr("src").replace(/\./, "-over.") );
			}
		}
	);
}
