$(document).ready(function(){

	//get the current year for copyright information
	$("#theDate").each(function(){
		var year = new Date();
		$(this).text(year.getFullYear());
	});
	
	//remove the inline play with accessibility options from view
	$("#playOptions").addClass("outtaHere");

	//shove video bg images down
	$("#videos li").css("backgroundPosition", "0 338px");
	//add tabindex to #byLine and #registerNow
	$("#byLine, #registerNow").attr("tabindex","0");
	//temporarily hide lesson guide links
	$(".lesson-guide").css("visibility","hidden");
	//enable sliding catalog descriptions
	//push paragraphs down
	$("#videos li p").css("top","225px");
	//on hover, slide paragraph up
	$("#videos li h3 a").click(function(){
		var theP = $(this).parent("h3").parent("li").find("p");
		if ( !(theP.hasClass("active") ) ) {
			theP.css("visibility","visible");
			theP.animate({top: "0px"},200).addClass("active");
			$(this).css("backgroundImage", "url('images/video-h3-a-close.png')");
		} else {
			theP.animate({top: "225px"},200, function(){theP.css("visibility","hidden");}).removeClass("active");
			$(this).css("backgroundImage", "url('images/video-h3-a.png')");
		}
		return false;
	});

	
	
	//control scrolling social media links
	$("#social li").each(function(){
		var idx = $("#social li").index(this);
		$(this).find("a").css("background-position","-" + ( idx * 228 ) + "px -202px");
		$(this).hover(function(){
			//mouseover
			$(this).find("a").animate({backgroundPosition: "-" + ( idx * 228 ) + "px 0px"}, 150);
		},function(){
			//mouseout
			$(this).find("a").animate({backgroundPosition: "-" + ( idx * 228 ) + "px -202px"}, 100);
		});
		$(this).find("a").focusin(function(){$(this).parent("li").mouseover();}).focusout(function(){$(this).parent("li").mouseout()});
	});
	
	//get photo alt info and place it as a hover tip
	$("#photos li").each(function(){
		var altText = $(this).find("img").attr("alt");
		var theLink = $(this).find("a");
		$(this).append("<span style='position:absolute; left: 290px; top: 5px; display: block; padding: 5px; background: #ff9; color: #333; width: 268px; line-height: 130%; font-weight: bold; border: 1px solid #333; cursor: pointer;'>"+altText+"</span>");
		$(this).hover(function(){
			$(this).find("span").stop().animate({left: "5px"},200);
			$(this).addClass("activePhoto");
		},function(){
			$(this).find("span").stop().animate({left: "290px"},200);
			$(this).removeClass("activePhoto");
		});
		$(this).find("span").click(function(){theLink.click();});
	});
	$("#photos li a").focusin(function(){$(this).parent("li").mouseover();}).focusout(function(){$(this).parent("li").mouseout();});
	
	//show/hide dl items
	
	$("#quickFacts dt").each(function(){
		var def = $(this).next("dd");
		var defHeight = def.outerHeight();
		$(this).append("<span class='show-hide' tabindex='0'></span>");
		def.css("height","0px").css("visibility","hidden");
		$(this).find("span").addClass("show").click(function(){
			if ( $(this).hasClass("show") ) {
				def.animate({height: defHeight+"px"},150, function(){
					def.css("visibility","visible");
				});
				$(this).removeClass("show").addClass("hide");
			} else {
				def.animate({height: "0px"},150, function(){
					def.css("visibility","hidden");
				});
				$(this).removeClass("hide").addClass("show");
			}
		}).keypress(function(e){
			if (e.which == 13) {
				$(this).click();
			}
		}).mouseleave(function(){
			$(this).blur();
		});
	});

});
