function isNetscape() {
	var agent = navigator.userAgent.toLowerCase();
	return agent.include('mozilla') && !agent.include('spoofer') && !agent.include('compatible')
	       && !agent.include('opera') && !agent.include('webtv') && !agent.include('hotjava')
	       && !agent.include('firefox');
}

function isNetscape6() {
	var version = parseInt(navigator.appVersion);
	return (version == 5) && isNetscape();
}

var Splash = {
	CONTENT_DIV_ID    : 'DivContent',
	SPLASH_DIV_ID     : 'DivSplash',
	MESSAGE_ID        : 'splashMessageDiv',
	ANIMATION_IMG_ID  : 'splashAnimationImg',
	ANIMATION_INTERVAL: 300,
	ANIMATION_IMG_ALT : 'Please wait...',

	getAnimationSrc: function(index) {
		return '/images/splash/animation_' + (index + 1) + '.gif';
	},

	loadPage: function(url, msg) {
		Splash.show(msg);
		loadPage(url);
	},

	show: function(msg) {
		if (!isNetscape6()) {
			var animation = new Splash.Animation();
			animation.show(msg);
			$(Splash.CONTENT_DIV_ID).hide();
			$(Splash.SPLASH_DIV_ID).show();
			animation.start();
		}
	},

	Animation: Class.create({

		initialize: function() {
			this._images = new Array(11);
			for (var i = 0; i < this._images.length; i++) {
				this._images[i] = this._createImage(i);
			}
			this._index = 0;
		},

		_createImage: function(index) {
			var image = document.createElement('img');
			image.src = Splash.getAnimationSrc(index);
			image.alt = Splash.ANIMATION_IMG_ALT;
			return image;
		},

		_diplayImage: function(index) {
			var img = $(Splash.ANIMATION_IMG_ID);
			img.src = this._images[index].src;
			img.alt = this._images[index].alt;
		},

		_animate: function() {
			this._index++;
			if (this._index == this._images.length) {
				this._index = 0;
			}
			this._diplayImage(this._index);
			setTimeout(this._animate.bind(this), Splash.ANIMATION_INTERVAL);
		},

		show: function(msg) {
			this._diplayImage(this._index);
			if (msg) {
				$(Splash.MESSAGE_ID).update(msg);
			}
		},

		start: function() {
			setTimeout(this._animate.bind(this), Splash.ANIMATION_INTERVAL);
		}
	})
};

// Deprecated
function SPLASH_loadPage(url, msg) {
	Splash.loadPage(url, msg);
}

// Deprecated
function SPLASH_show(msg) {
	Splash.show(msg);
}
