/**
 * 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);
		});
	});
}


function oc(a)
{
	var o = {};
	
	for(var i=0;i<a.length;i++){o[a[i]]='';}
	return o;
}


$(document).ready(function(){
	$("img").rightClick(
				   function(){
					   alert("Images on this website are the property of GRUALBE.");
					   return false;
				   }
				   
				   );
	$("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.snippet").hide();
	$("#snip_area ul li.snippet: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;
		
	});
	
	
	
	DD_belatedPNG.fix('#header div.nav ul li a, #principles #tabs .buttons li a, body#principles h2#in-business, #header .logo a');
	
	// slideshow stuff
	$("#gallery-right .canvas-right img:not(:first)").hide();
	$("#gallery-right .canvas-right img").each(function(){
		__images.push( $(this) );
	});
	if ( __delay < __fadeDelay * 2 ) {
		__delay = __fadeDelay * 2;
	}
	setTimeout("rotate_next();", __delay);
	
	$('a[rel="external"]').attr("target", "_blank");
});