// JavaScript Document
// Copyright 2000-2011, DataCom/OTA, Inc.
        
// Setup
var theImages = new Array()
theImages[0] = "/media/web/index/gallery01.jpg"
theImages[1] = "/media/web/index/gallery02.jpg";
theImages[2] = "/media/web/index/gallery03.jpg";
theImages[3] = "/media/web/index/gallery04.jpg";
theImages[4] = "/media/web/index/gallery05.jpg";

var i = theImages.length;
var whichImage = Math.round(Math.random()*(i-1));
var nextImage = (whichImage == (i-1)) ? 0 : whichImage+1;
var preBuffer = new Array()
preBuffer[whichImage] = new Image()
preBuffer[whichImage].src = theImages[whichImage]

// Choose picture
function picPic() {
	var obj = document.getElementById('picImg');
	document['picImg'].src=theImages[whichImage];
	obj.style.opacity = 1;
	isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? obj.style.filter = "alpha(opacity=100)" : "";
	document.getElementById('picBox').style.backgroundImage="url("+theImages[nextImage]+")";
	setTimeout(function(){fadeOut('100')}, 3000);
}

// Picture fader
function fadeOut(pos) {
	var obj = document.getElementById('picImg');
	var pos = pos <= 100 ? pos : 100;
	var css = eval(pos*.01);
	obj.style.opacity = css;
	isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? obj.style.filter = "alpha(opacity="+pos+")" : "";
	pos = pos-5;
	if (pos>-1) {
		setTimeout(function(){fadeOut(pos)}, 50);
	} else {
		setTimeout(function(){swapImg()}, 1);
	}
}

function swapImg() {
	whichImage = (whichImage == (i-1)) ? 0 : whichImage+1;
	nextImage = ((whichImage+1) == i) ? 0 : nextImage+1;
	setTimeout(function(){picPic()}, 1);
}


