/**
 * Custom image slideshow / rotation
 * 
 * @date 2009-03-11
 * @author: theandystratton@gmail.com
 * @link http://theandystratton.com
 */

var __continue = true;
var __delay = 8000;
var __fadeDelay = 1000;
var __images = [];
var __index = 0;
var __preloadID = 0;

function rotate_next() {
	$(__images[__index]).fadeOut(__fadeDelay, function(){
		__index++
		if ( __index >= __images.length ) {
			__index = 0;
		}
		$(__images[__index]).fadeIn(__fadeDelay, function(){
			setTimeout("rotate_next();", __delay);
		});
	});
}


$(document).ready(function(){
	
	$("div.nav ul a").each(function(){
		$this = $(this);
		if ( $this.attr("href") == '#' ) {
			$this.fadeTo(0, .50);
			$this.click(function(){ return false; });
			$this.css("cursor","default");
		}
	});
	
	$("#snip_area ul li").hide();
	$("#snip_area ul li:first").show();
	
	$("#controls ul li a").click(function(){
		
		$this = $(this);
		
		$("#controls ul li a").removeClass('active');
		$this.addClass('active');
		
		$("#snip_area ul li.active").fadeOut(250, function(){
			$("#snip_area ul li").removeClass("active");
			$( $this.attr("href") ).fadeIn(750);
			$( $this.attr("href") ).addClass('active');
		});
		return false;
		
	});
	
	// slideshow stuff
	$("#gallery .canvas img:not(:first)").hide();
	$("#gallery .canvas img").each(function(){
		__images.push( $(this) );
	});
	if ( __delay < __fadeDelay * 2 ) {
		__delay = __fadeDelay * 2;
	}
	setTimeout("rotate_next();", __delay);
	
	$('a[rel="external"]').attr("target", "_blank");
});