/*

trippyimages.js

chapmanradio.com

Adam Borecki

*/

var startImg = 1;
var lastImg = 4;
var shuffleDelay = 4800; // milliseconds
var replaceSpeed = "slow";


$(document).ready(function(){
	startAutoshuffle();
});

if(typeof(eid)=="undefined")
	eid = function(w) {return document.getElementById(w);};

var isShuffling = true;
var tempDisable = false;
var curOpen = startImg;
function autoshuffle() {
	if(!isShuffling)
		return;
	imgClose(curOpen);
	curOpen++;
	if(curOpen > lastImg)
		curOpen = startImg;
	imgOpen(curOpen);
	startAutoshuffle();
}

function imgClose(num) {
	$("#img"+num).hide(replaceSpeed);
	hoverOut(eid("jump"+num));
}

function imgOpen(num) {
	$("#img"+num).show(replaceSpeed);
	hoverOver(eid("jump"+num));
}

function hoverOver(thing) {
	if(!thing)
		return;
	thing.style.backgroundPosition = "bottom left";
}

function hoverOut(thing) {
	if(!thing)
		return;
	thing.style.backgroundPosition = "top left";
}

function jumpTo(num) {
	isShuffling = false;
	if(num == curOpen)
		return;
	imgClose(curOpen);
	curOpen = num;
	imgOpen(curOpen);
}

function startAutoshuffle() {
	isShuffling = true;
	setTimeout("autoshuffle();", shuffleDelay);
}