jQuery(function( $ ){
	$("#images").hover(function() {
		$("ul#imagenav").animate({top: "0px"}, "slow");
		}, function() {
		$("ul#imagenav").animate({top: "-200px"}, "slow");
	})
	
	$("ul#imagenav li a:first").addClass('active'); //Create active class on image nav
	
	var resizeFunction = function(){
		$("#imageLarge").css({'width': 'auto'}); //Remove any height and width amounts set by stylesheets or previous changes
		$("#imageLarge").css({'height': 'auto'});
		var imgWidth = $("#imageLarge").width(); //Get height and width of image
		var imgHeight = $("#imageLarge").height();
		var imgRatio = (imgWidth / imgHeight).toPrecision(4); //Get the ratio of height to width and round to 4 digits
		if(imgRatio < 1){ //If height is greater than width
			var newWidth = parseInt(600 * imgRatio); //Multiply ratio by 600 to get new width
			$("#imageLarge").css({ 'height': '600px' }); //Set height
			$("#imageLarge").css({ 'width': newWidth }); //Set Width
		} else { //If width is greater than height
			var newHeight = parseInt(600 / imgRatio); //Divide 600 by ratio to get new height
			$("#imageLarge").css({'width': '600px' }); //Set height
			$("#imageLarge").css({'height': newHeight }); //Set Width
		}
	}
	
	$("ul#imagenav li a").click(function() { //Navigating to new image
		$("ul#imagenav li a").removeClass('active'); //Clear class name of image nav
		$(this).addClass('active'); //Add active class to clicked image
		var largePath = $(this).attr("href"); //Turn clicked URL into a variable
		var caption = $(this).attr("title");
		
		$("#imageLarge").fadeTo(500,0).delay(500,function(){ //Fade to 0 and wait until animation completes
			$("#images p").html(caption);
			$("#imageLarge").attr({ src: largePath }).delay(1000, function() { //Assign variable as image attribute and wait so next animation doesn't occur until image loads
				resizeFunction(); //Run function to resize images to restrict height and width to defined amount
				$("#imageLarge").fadeTo(1000,1); //Fade back to 100% visibility
			});
		});
		return false;
	});
	
	$("a.video").click(function() { //Function to display video
		var videoFile = $(this).attr("href"); //Gets URL to file
		var background = $("<div id='background'></div>"); //Creates new div for the black background
		var windowHeight = $(window).height(); //Gets height of window
		var videoHeight = parseInt((windowHeight/2)-130); //Finds halfway point of window to display video player
		var videoWrapper = $("<div id='videoWrapper'><div id='container' style='margin:0 auto;'><a href='http://www.macromedia.com/go/getflashplayer'>Get the Flash Player</a> to see this player.</div><script type='text/javascript' src='/js/swfobject.js'></script><script type='text/javascript'>var s1 = new SWFObject('/js/player.swf','ply','420','320','9','#FFFFFF'); s1.addParam('allowfullscreen','true'); s1.addParam('allowscriptaccess','always'); s1.addParam('flashvars','file=" + videoFile + "');	s1.addParam('skin', '/js/schoon.swf'); s1.write('container'); </script><a href='#' id='remove' return false;'>Close</a></div></div>"); //Creates HTML to display video and calls script to display video
		var documentHeight = $(document).height(); //Gets height of document for height of black background
		$("body").append(background); //Adds black background to document (at this point it has opacity of 0)
		$("#background").css({opacity:0, position:"absolute", top:0, left:0, right:0, bottom:0, height:"100%", width:"100%", background:"#ffffff"});
		$("body").append(videoWrapper); //Add video wrapper
		$("#videoWrapper").css({position:"fixed", top:0, left:0, width:"100%", "text-align":"center", opacity:0});
		$("#background").height(documentHeight); //Set height of black background
		$("#background").fadeTo(700,.8).delay(500, function(){ //Fade in black background with a little transparency
			$("#videoWrapper").css({top:videoHeight}); //Set video centered vertically
			$("#videoWrapper").fadeTo(500,1); //Fade in video
		});
		
		$("#remove").click(function(){ //Function to remove video
			$("#background").fadeTo(700,0); //Fade out black background
			$("#videoWrapper").fadeTo(500,0).delay(500, function(){ //Fade out video and wait to remove video until fade is complete
				$("#videoWrapper").remove(); //Remove video
				$("#background").remove(); //Remove black background
			});		
			return false;
		})
		
		return false;
	});
});