// JavaScript Document

$(document).ready(function(){
	
		// remove link background images since we're re-doing the hover interaction below 
		// (doing it this way retains the CSS default hover states for non-javascript-enabled browsers)
		// we also want to only remove the image on non-selected nav items, so this is a bit more complicated
		$(".nav").children("li").each(function() {
			var current = "nav current-" + ($(this).attr("class"));
			var parentClass = $(".nav").attr("class");
			if (parentClass != current) {
				$(this).children("a").css({backgroundImage:"none"});
			}
		});	


		// create events for each nav item
		attachNavEvents(".nav", "home");
		attachNavEvents(".nav", "news");
		attachNavEvents(".nav", "picture");
		attachNavEvents(".nav", "video");
		attachNavEvents(".nav", "links");
		attachNavEvents(".nav", "donation");


		function attachNavEvents(parent, myClass) {
			$(parent + " ." + myClass).mouseover(function() {
				$(this).append('<div class="nav-' + myClass + '"></div>');
				$("div.nav-" + myClass).css({display:"none"}).fadeIn(200);
			}).mouseout(function() {
				$("div.nav-" + myClass).fadeOut(200, function() {
					$(this).remove();
				});
			}).mousedown(function() {
				$("div.nav-" + myClass).attr("class", "nav-" + myClass + "-click");
			}).mouseup(function() {
				$("div.nav-" + myClass + "-click").attr("class", "nav-" + myClass);
			});
		}

	});// end

$(document).ready(function(){
$(".navcredits").children("li").each(function() {
			var current = "navcredits current-" + ($(this).attr("class"));
			var parentClass = $(".navcredits").attr("class");
			if (parentClass != current) {
				$(this).children("a").css({backgroundImage:"none"});
			}
		});	


		// create events for each navcredits item
		attachNavEvents(".navcredits", "scratchedlens");
		attachNavEvents(".navcredits", "farlow");
		attachNavEvents(".navcredits", "visceral");
		attachNavEvents(".navcredits", "edgarlituma");
		attachNavEvents(".navcredits", "mikem");
		attachNavEvents(".navcredits", "tamcao");
		attachNavEvents(".navcredits", "supportsouthern");


		function attachNavEvents(parent, myClass) {
			$(parent + " ." + myClass).mouseover(function() {
				$(this).append('<div class="navcredits-' + myClass + '"></div>');
				$("div.navcredits-" + myClass).css({display:"none"}).fadeIn(200);
			}).mouseout(function() {
				$("div.navcredits-" + myClass).fadeOut(200, function() {
					$(this).remove();
				});
			}).mousedown(function() {
				$("div.navcredits-" + myClass).attr("class", "navcredits-" + myClass + "-click");
			}).mouseup(function() {
				$("div.navcredits-" + myClass + "-click").attr("class", "navcredits-" + myClass);
			});
		}
	});// end

$(document).ready(function(){
$(".tabnav").children("li").each(function() {
			var current = "tabnav current-" + ($(this).attr("class"));
			var parentClass = $(".tabnav").attr("class");
			if (parentClass != current) {
				$(this).children("a").css({backgroundImage:"none"});
			}
		});	


		// create events for each tabnav item
		attachNavEvents(".tabnav", "synopsis");
		attachNavEvents(".tabnav", "directorstatement");
		attachNavEvents(".tabnav", "productionnotes");


		function attachNavEvents(parent, myClass) {
			$(parent + " ." + myClass).mouseover(function() {
				$(this).append('<div class="tabnav-' + myClass + '"></div>');
				$("div.tabnav-" + myClass).css({display:"none"}).fadeIn(200);
			}).mouseout(function() {
				$("div.tabnav-" + myClass).fadeOut(200, function() {
					$(this).remove();
				});
			}).mousedown(function() {
				$("div.tabnav-" + myClass).attr("class", "tabnav-" + myClass + "-click");
			}).mouseup(function() {
				$("div.tabnav-" + myClass + "-click").attr("class", "tabnav-" + myClass);
			});
		}
	});// end



// Links Page Functions
$ (document).ready(function(){
							
			$(".rounded").hover(function() {
				$(this).stop().fadein(500);
				$(this).css('background-color','#ffffff');
			}, function(){
			              $(this).stop().fadeout(500);
						  $(this).css('background-color','#161616');
						 } 
			
			);					
							
});