var debug = false;
var splasher = {
	init: function() {
		splasher.fadetime = 900;
		splasher.waittime = 5000;
		splasher.splashes = new Array(
			'/images/rotation/offroad.jpg',
			'/images/rotation/ag.jpg',
			'/images/rotation/generator.jpg',
			'/images/rotation/shop.jpg'
		);
						
		splasher.splashon = 0;
		splasher.splashnext = 1;
		splasher.splashtoB = true;
		splasher.waitload = false;
		splasher.missedswap = false;
		// splasher.imgbuffer = '/images/blank.png';
		splasher.preloader = new Element('img');
		//splasher.preloader.src = splasher.imgbuffer;
		splasher.preloader.addEvent('load', splasher.preloaded);
		$('imgB').setOpacity(0);
		splasher.loadnext();
	},
	loadnext: function() {
		splasher.splashnext = splasher.splashon + 1;
		if (splasher.splashnext >= splasher.splashes.length) splasher.splashnext=0;
		if (debug) console.log('loadnext: ' + splasher.splashnext + ' : ' + splasher.splashes[splasher.splashnext]);
		splasher.waitload = true;
		splasher.preloader.src = splasher.splashes[splasher.splashnext];
		splasher.swap.delay(splasher.waittime);
	},
	preloaded: function() {
		if (debug) console.log('preloaded: ' + splasher.preloader.src);
		//if (splasher.preloader.src==splasher.imgbuffer) {
		//	console.log('skip');
		//	return false;
		//}
		splasher.waitload = false;
		if (splasher.missedswap) splasher.swap();
	},
	swap: function() {
		if (debug) console.log('swap');
		if (splasher.waitload) {
			splasher.missedswap = true;
			return false;
		}
		splasher.missedswap = false;
		if (splasher.splashtoB) {
			$('imgB').src = splasher.preloader.src;
			$('imgB').effect('opacity', { duration: splasher.fadetime }).start(1);
		} else {
			$('imgA').src = splasher.preloader.src;
			$('imgB').effect('opacity', { duration: splasher.fadetime }).start(0);
		}
		splasher.splashtoB = !splasher.splashtoB;
		splasher.splashon = splasher.splashnext;
		//splasher.preloader.src = splasher.imgbuffer;
		splasher.loadnext();
	}
};
window.addEvent('load', splasher.init); // purposely load and not domready

function textbox_loader() {
	$('weldtalkemail').addEvent('click', function() {
		if (this.getValue()=='e-mail address') this.value = '';
	});
	$('weldtalkemail').addEvent('blur', function() {
		if (this.getValue()=='') this.value = 'e-mail address';
	})
}
// window.addEvent('domready', textbox_loader);