$().ready(function() {
	$('#slideshow').cycle({ 
	    fx:     'fade', 
	    speed: 800,
	    timeout: 16000, 
	    pause:  '1',
        next:   '#next', 
        prev:   '#prev',
        before: onBefore,
        after: onAfter
	});
	function onBefore(curr, next, opts) {
                    $(next).children(".slideText").children(".header").css("display","none");
		$(next).children(".slideText").children(".header").css("width","0");
		$(next).children(".slideText").children("p").css("display","none");
	}
	function onAfter() {
                    slide = $(this);
		headerTimer = setTimeout( "slide.children('.slideText').children('.header').animate({width: '216px'},'slow')",3000 );
		textTimer = setTimeout( "slide.children('.slideText').children('p').slideDown('slow')",5000 );
	}
	$("#slideshowNav").show();
	$("#slideshowNav a").click( function() {
	        if (headerTimer) clearTimeout(headerTimer);
	        if (textTimer) clearTimeout(textTimer);
	});

	if ($("#q").val()=="") {
		$("#searchLabel").css("visibility","visible");
	}
	$("#q").focus( function() {
		$("#searchLabel").css("visibility","hidden");
	});
	$("#q").blur( function() {
		if ($("#q").val()=="") {
			$("#searchLabel").css("visibility","visible");
		}
	});

	$('#sectionNav a').each(function() {
		var navlink = $(this).attr("href");
		if (navlink.toLowerCase()==location.href.toLowerCase()) {
			$(this).parent("li").addClass("selected");
		}
	});
	//$("img.uscPhotoCredit").each( function() {
	//	var imgWidth = $(this).width();
	//	$(this).after('<span class="caption" style="width:'+imgWidth+'px;">Philip Channing &copy; University of Southern California</span>');
	//});
	
	if ($("img.uscPhotoCredit").length > 0) {
		$("#main").append('<p class="caption">Photo credit: Philip Channing &copy; University of Southern California.</p>');
	}
	
	$("body.show_and_tell #main h2#page-title span").html('<img src="http://rossier.usc.edu/assets/images/dev/show-and-tell.png" alt="Show and Tell" />');
	
});