$(document).ready(function(){
	$('#top-cats .top-cat, #bottom-cats .bottom-cat').click(
		function(){
			var toAddress = $(this).children('.ninjaLink').html();
			if (toAddress.length > 0) {
				document.location=$(this).children('.ninjaLink').html();
			}
		}
	);
});

/*
 * ImageFader 1
 *
 * Copyright (c) 2008 Robertson Marketing Group Inc. (robertsonmarketing.com)
 *
 * $Date: 2008-06-25 14:22:17 -0400 (Wed, 25 June 2008) $
 * $Rev: 8 $
 */

var cells = ['#rotation1', '#rotation2', '#rotation3'];

var initialSpeed = 8000; // how many milliseconds between pictures
var pauseTime = 8000; // how long to wait when a stop is clicked

var fadeInSpeed = 2000; // how long it takes the picture to fade in
var fadeOutSpeed = 2010; // how long it takes a picture to fade out

// dont change anything below this line!
var okayGo = false;
var checkI;
var activeCell = 0;

//This prototype is provided by the Mozilla foundation and
//is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
if (!Array.prototype.forEach) {
	Array.prototype.forEach = function(fun /*, thisp*/) {
		var len = this.length;
		if (typeof fun != "function")
			throw new TypeError();
		var thisp = arguments[1];
		for (var i = 0; i < len; i++) {
			if (i in this)
				fun.call(thisp, this[i], i, this);
		}
	};
}

// fire the page events when the DOM is ready
$(document).ready(
	function() {
		initFader();
	}
);

// runs imgFader() once every x amount of seconds
function initFader() {
	checkI = setInterval('imgFader()',initialSpeed);
	okayGo = true;
}

var hideAllCells = function(x) {$(x).fadeOut(fadeOutSpeed);}

function imgFader() {
	cells.forEach(hideAllCells); // hide all the cells
	(activeCell == (cells.length-1)) ? activeCell = 0 :	activeCell++; // set the active cell to the next one in the array, if at the end of the array, go back to 0
	$(cells[activeCell]).fadeIn(fadeInSpeed); // fade in the next cell
}

function pauseAt(x) {
	if (okayGo == true) {
		okayGo = false;
		if (activeCell == x) {
			clearInterval(checkI); // stop the pictures from changing
			setTimeout('initFader()', pauseTime); // set the loop to start again after x amount of seconds
		} else {
			clearInterval(checkI); // stop the pictures from changing
			cells.forEach(hideAllCells); // hide all the cells
			activeCell = x; // set the active cell
			$(cells[activeCell]).fadeIn(fadeInSpeed); // fade in the preferred cell
			setTimeout('initFader()', pauseTime); // set the loop to start again after x amount of seconds
		}
	}
}
