﻿$(document).ready(function(){
	
	$("html").addClass("js");
	
	$("ul li:first-child").addClass("first");
	
	// kludge for local copy
	$("img").each(function(){
		$(this).attr("src",$(this).attr("src").replace("localhost:8000\/","www."));
	});
	
	$("#external-links a").each(function(){
		$(this).html( $(this).text().replace(/sniff/,'<span>sniff</span>') );
	});
	
	// remove typographic widows
	$("h1,h2,h3").each(function(){
		var $current = ( $("a",this).length ) ? $("a",this) : $(this);
		$current.html( $current.text().replace(/ (\S+)$/,'&nbsp;$1') );
	});
	
	$("#logo a, #header .nav a[href=/]").hover(function(){
		$("#header .nav a[href=/]").css("color","#fff");
	},function(){
		$("#header .nav a[href=/]").css("color","#000");
	});
});

function setupCycle(container){
	if ( $("img",container).length > 1 ) {
		var maxheight = 0;
		$("img",container).each(function(){
			if ( $(this).height() > maxheight ) maxheight = $(this).height();
		});
		$("ul",container).cycle({
			fit: 1,
			height: maxheight,
			pause: 1,
			delay: 5000,
			timeout: 5000
		});
	}
}

$(window).load(function(){

	setupCycle($("#icit_taxonomical_listings-9"));
	setupCycle($("#icit_taxonomical_listings-10"));

	// masonry on home page
	if ( $("body").hasClass("home") ) {
		$("#content").masonry({ columnWidth: 30 });
	}
	
});
