


function setPageOn(page) {
	$(".nav a").removeClass("On");
	$(".nav a[href="+page+"]").addClass("On");
	window.location.hash = page;
	$(".bottomSection").animate({ opacity: 0 },250,function(){
		$("a.overClicker").show();
		$(".bottomSection").css({ visibility: "hidden" });
		$(page).children("a.overClicker").hide().nextAll(".bottomSection").css({ visibility: "visible" }).animate({ opacity: 1 },250);
	});
}

$(document).ready(function(){

	VideoJS.setupAllWhenReady({
		controlsBelow: false, // Display control bar below video instead of in front of
		controlsHiding: true, // Hide controls when mouse is not over the video
		defaultVolume: 0.85, // Will be overridden by user's last volume if available
		flashVersion: 9, // Required flash version for fallback
		linksHiding: true // Hide download links when video is supported
	});

	if ($.browser.mozilla) {
		$("#contentFrame").css("overflow-x","scroll");
	}

	var winW = $(window).width();
	var winH = $(window).height();
	var floW = 0;
	var tempH = 0;
	var contentH = $("#content div").height();
	var numN = $("#header .nav a").size()-1;
	var navW = 0;
	var hashLocation = document.location.hash;

	$("#contentFrame").css({ width: winW, height: winH-200 }).scroll(function(){
		if ($("#contentFrame").scrollTop() > 0) {
			$("#shadow").fadeIn(200);
		}
		else {
			$("#shadow").fadeOut(150);
		}
	});

	$("#content div.page").each(function(){
		floW += $(this).width() + 150;
		tempH = $(this).height();
		if (tempH > contentH) {
			contentH = tempH;
		}
	});

	$("#content").css({ width: floW });

	$("#shadow").css({ width: winW - 15 });

	$("a.overClicker").css({ height: contentH });

	$("#header .nav a").each(function(){
		navW += $(this).width();
	}).css({ marginRight: (750-navW)/numN });

	if (hashLocation) {
		$("#contentFrame").stop().scrollTo(hashLocation,500,{
			offset: -100,
			axis: 'x'
		});
		setPageOn(hashLocation);
	}
	else {
		hashLocation = "#Home";
		window.location.hash = hashLocation;
		$("#content div:first-child").children("a.overClicker").hide();
		setPageOn(hashLocation);
	}


	$(".nav a,a.overClicker,#logoNav,a[href*=#]").click(function(e){
		if (window.location.hash != this.hash) {
			$("#contentFrame").stop().scrollTo(this.hash,500,{
				offset: -100,
				axis: 'x'
			});
			setPageOn(this.hash);
		}
        e.preventDefault();
	});

	$(".socnet img").hover(function(){
		var src = $(this).attr("src").match(/[^\.]+/) + "-o.png";
		$(this).attr("src", src);
	},function(){
		var src = $(this).attr("src").replace("-o", "");
		$(this).attr("src", src);
	});

	$("#storyForm input[name=snaim], #storyForm input[name=semail], #storyForm textarea").defaultvalue(
		"Full Name",
		"Email Address",
		"Your Story"
	);
	$("#storyForm").validate({
		errorLabelContainer: $("#feedback"),
		submitHandler: function(form) {
			$(form).ajaxSubmit({
				success: function(){
					$("#feedback").html("Thanks for sharing your story.").show();
					$(form).resetForm();
					$("#storyForm input[name=snaim], #storyForm input[name=semail], #storyForm textarea").defaultvalue(
						"Full Name",
						"Email Address",
						"Your Story"
					);
				}
			});
		}
	});

	$('.defaultValue').each(function(){
		var default_value = this.value;
		$(this).focus(function() {
			if (this.value == default_value) {
				$(this).val('').css({ color: '#555044', fontStyle: 'normal' });
			}
		});
		$(this).blur(function() {
			if (this.value == '') {
				$(this).val(default_value).css({ color: '#838277', fontStyle: 'italic' });
			}
		});
	});
	
	$('div.page').last().find('.topSection').css({ marginRight: '3000px' });

});

$(window).resize(function(){

	var winW = $(window).width();
	var winH = $(window).height();
	var floW = 0;

	$("#contentFrame").css({ width: winW, height: winH-200 });
/*	$("#content div").each(function(){
		floW += $(this).width() + 25;
	});
	$("#content").css({ width: floW });*/
	$("#shadow").css({ width: winW - 15 });

});



