// JavaScript Document

// Functions for changing font sizes
function set_font_from_cookie() {
	myfontsize = jimAuld.utils.cookies.get('gosafe_fontsize');
	if (myfontsize != null) {
		document.body.style.fontSize = myfontsize;
	}
}

function font_up() {
	curr_size = document.body.style.fontSize;
	curr_size = parseInt(curr_size);
	new_size = (curr_size+10)+"%";
	document.body.style.fontSize = new_size;
	jimAuld.utils.cookies.set('gosafe_fontsize',new_size);
	$('font_up').blur();
}

function font_down() {
	curr_size = document.body.style.fontSize;
	curr_size = parseInt(curr_size);
	new_size = (curr_size-10)+"%";
	document.body.style.fontSize = new_size;
	jimAuld.utils.cookies.set('gosafe_fontsize',new_size);
	$('font_down').blur();
}

// Test for cookies and only enable the font-size buttons if cookies are allowed:

function cookie_test() {
	if (jimAuld.utils.cookies.test() == true) {
		el = document.getElementById('fontlinks');
		el.style.display = 'block';
	}
}

var $SlideShow = {
	currentSlide: 0,
	Slides: Array(),
	slideTimer: null,
	slideTimeout: 2000,
	Init: function() {
		// Put all the background image elements into an array:
		this.Slides = $$('.image');
		// Randomize the order:
		this.Slides.sort(function() {
			return (Math.random()) > 0.5 ? 1 : -1;
		});
		// Show the first one:
		var myIndex = parseInt(this.Slides[0].getStyle("z-index"));
		var newIndex = myIndex+3000;
		this.Slides[0].setStyle({
			zIndex: newIndex
		});
		Effect.Appear(this.Slides[0].id,{duration: 2, afterFinish: function() {
			setTimeout("$SlideShow.Next();",($SlideShow.slideTimeout*2));
		}});
	},
	Next: function() {
		var lastSlide = this.currentSlide;
		// Move the last slide back down the z-order:
		var myIndex = parseInt(this.Slides[lastSlide].getStyle("z-index"));
		var newIndex = myIndex-3000;
		this.Slides[lastSlide].setStyle({
			zIndex: newIndex
		});
		this.currentSlide += 1;
		if (this.currentSlide == this.Slides.length) {
			this.currentSlide = 0;
		}
		// Now move the next slide to the top of the order and fade it in:
		var myIndex = parseInt(this.Slides[this.currentSlide].getStyle("z-index"));
		var newIndex = myIndex+3000;
		this.Slides[this.currentSlide].setStyle({
			zIndex: newIndex
		});
		Effect.Appear(this.Slides[this.currentSlide].id,{duration: 2, afterFinish: function() {
			// Hide the last slide:
			var lastSlide = $SlideShow.currentSlide-1;
			if (lastSlide < 0) {
				lastSlide = $SlideShow.Slides.length-1;
			}
			$SlideShow.Slides[lastSlide].hide();
			setTimeout("$SlideShow.Next();",$SlideShow.slideTimeout);
		}});
	}
}
