/* Global Items */
$(document).ready(function() {



	// Dump the default button, but if they've got JS turned on, stick a new one in.
	$("#historyExplorer input.submit").remove();
	$("#historyExplorer .fields").append('<input class="submit" type="image" alt="Search" value="Search" src="/ourstory/i/links/explorer_search.gif" />');



	// hover switch
	$("input[type='image']").rolloverSubmit();

	// firsts & lasts
	$("#footer li:first").addClass("first");
	$("dl.awards dd:last").addClass("last");
	$(".activitiesMarquee li:last").addClass("last");
	$(".side_options li:last").css("background","none");
	$(".indepth-about .essayBody p:eq(1)").addClass("first");








	
	// history explorer keyword search field
	$("#keywords").addClass("labeled").val("");
	$("#keywords").focus(function() {
		$(this).removeClass("labeled");
	}).blur(function(){
		if ($(this).val() == "")
			$(this).addClass('labeled');
	});

	if ( $("#keywords").val() != "")
		$("#keywords").removeClass('labeled');








	// cycle
	$("#galleryImages") 
	.before('<div id="galleryImagesNav">')
	.cycle({ 
	    fx:     'fade', 
	    speed:  'slow',
		before: onBefore,
		after: onAfter,
	    timeout: 10000, 
	    pager:  '#galleryImagesNav'
	});



	function onBefore() { 
		$('.gallery_desc p').css('display', 'none');
//		alert(this.attr('id'));
		$('.gallery_desc p.'+this.id).css('display','block');
	}
		function onAfter() { 
//	    $('.gallery_desc p').html("Scrolling image:<br>" + this.alt);
		}


	// gallery paragraphs
	/*
	$("#galleryImagesNav a:eq(0)").click(function() {
		$(".gallery_desc p").css("display","none");
		$(".gallery_desc #galleryp1").css("display","block");
	});
	$("#galleryImagesNav a:eq(1)").click(function() {
		$(".gallery_desc p").css("display","none");
		$(".gallery_desc #galleryp2").css("display","block");
	});
	$("#galleryImagesNav a:eq(2)").click(function() {
		$(".gallery_desc p").css("display","none");
		$(".gallery_desc #galleryp3").css("display","block");
	});
	$("#galleryImagesNav a:eq(3)").click(function() {
		$(".gallery_desc p").css("display","none");
		$(".gallery_desc #galleryp4").css("display","block");
	});
	$("#galleryImagesNav a:eq(4)").click(function() {
		$(".gallery_desc p").css("display","none");
		$(".gallery_desc #galleryp5").css("display","block");
	});
	*/
	
	// give the links some context
	$("#galleryImagesNav a:eq(0)").attr("title","Learn about the Great Women of Our Past activity");
	$("#galleryImagesNav a:eq(1)").attr("title","Learn about the second activity");
	$("#galleryImagesNav a:eq(2)").attr("title","Learn about the third activity");
	$("#galleryImagesNav a:eq(3)").attr("title","Learn about the fourth activity");
	$("#galleryImagesNav a:eq(4)").attr("title","Learn about the fifth activity");
	

	// dropPick
	var dropTrigger = $(".side_options h4");
	$(dropTrigger).css("cursor","pointer");
	$(dropTrigger).mouseover(function() {
		$(this).addClass("hovered");
	});
	$(dropTrigger).mouseout(function() {
		$(this).removeClass("hovered");
	});
	$(dropTrigger).click(function() {
		$(".dropPick").toggleClass("dropPick-on");
	});
	$(".side_options h4 a").focus(function() {
		$(this).css("border","1px dotted blue");
		$(this).css("padding","2px 2px 2px 0");
	});
	$(".side_options h4 a").blur(function() {
		$(this).css("border","none");
		$(this).css("padding","0");
	});


	// "Skip" links for accessibility
	$("#skipToContent a").focus(function() {  $(this).addClass("focused");  });
	$("#skipToContent a").blur(function() {  $(this).removeClass("focused");  });
	$("a#skipGallery").focus(function() {  $(this).addClass("focused");  });
	$("a#skipGallery").blur(function() {  $(this).removeClass("focused");  });



	// dropPick
	$(".dropPick a").focus(function() {
		$(this).css("outline","1px dotted #b76a8a");
		$(this).css("background","#f4cddd");
		$(this).css("color","#7f3654");
	});
	$(".dropPick a").blur(function() {
		$(this).css("outline","none");
		$(this).css("background","none");
		$(this).css("color","#b76a8a");
	});


 
	// Lightbox!
	$('a.lightBox').lightBox(); // Select all links with lightbox class


	// Flash activities
	var flashvars = {learnMore:"/ourstory/activities/sodhouse/"};
	swfobject.embedSWF("/ourstory/f/sodhouse.swf", "flashActivity", "735", "320", "8.0.0", false, flashvars);


	// How tall is the .bookfeature panel?
	if ( $(".bookfeature").length > 0 ) { /* Only do it on pages where this element exists */
		$(".readthis").height(($(".bookfeature").height()) + 50); /* Inject height into grandparent, plus 50px */
	}

});


