$(document).ready(function() {
	$("#nav a, #teasers a").hover(
				// over
				function(){
					// store the original image src
					$(this).children(":first-child").attr( "originalsrc" , $(this).children(":first-child").attr("src") );
					
					// add -over to the image unless it is already -over
					if (!$(this).children(":first-child").attr("src").match(/-over/) ) {
						$(this).children(":first-child").attr( "src", $(this).children(":first-child").attr("src").replace(/\./, "-over.") );
					}
					
				},
				
				// out
				function(){
					// replace the original src
					$(this).children(":first-child").attr(
						"src", $(this).children(":first-child").attr("originalsrc")
					);
					
					$(this).children(":first-child").attr(
						"originalsrc", null
					);
				}
			);
	
	
	// accordian
	$(".subsections div").hide();
	$(".head").not(".external").click(function(){
	
		var isCurrent;
		if ( $(this).next().is(":visible") ) {
			isCurrent = true;
		}
	
		$(".subsections div:visible").slideUp("fast");
		$(".head img").attr("src", "/images/layout/arrow_right.gif");
		
		if (isCurrent) {
			return false;
		}
		
		$(this).next().slideDown("fast");
		$(this).children(":first-child").attr("src", "/images/layout/arrow_down.gif");
		return false;
	});

	// show by parameter
	var hashClean = location.hash.substr(1);
	if (hashClean) {
		$(".subsections div#" + hashClean).slideDown("fast");
		$(".subsections div#" + hashClean).prev().children(":first-child").attr("src", "/images/layout/arrow_down.gif");
	}
	
});

window.onload = function() {
		// preload
		$("#nav a img, #teasers a img").each(
			function() {
				$("<img>").attr( "src", $(this).attr("src").replace(/\./, "-over.") );
			}
		);
}


