/* This version of FeaturedSlideshow uses jquery instead of mootools */
function FeaturedSlideshow(el, data, options)
{
	var obj = this;
	this.data = data;
	this.div = document.getElementById(el);
	this.img = this.div.getElementsByTagName('img')[0];
	this.img2 = this.div.getElementsByTagName('img')[1];
	this.index = 0;
	this.delay = 5000;
	this.captions = false;
	this.set_cookie = false;
	
	if (options) {
		if (options.index) this.index = options.index;
		if (options.delay) this.delay = options.delay;
		if (options.captions) this.captions = options.captions;
		if (options.set_cookie) this.set_cookie = options.set_cookie;
	}
	
	setTimeout(function(){ obj.transition(obj.img, obj.img2); }, obj.delay); 
}

FeaturedSlideshow.prototype = {
		transition: function(img, img2)
		{
			var obj = this;
			this.index++;
			if(this.index >= this.data.length)
			{
				this.index = 0;
			}
			
			if (this.set_cookie) {
				document.cookie = this.set_cookie + '=' + this.index;
			}

			var next = this.data[this.index];
			img.src = next.src;
			if (this.captions) {
				img.title = next.caption;
				img.alt = next.caption;
			}
			$j(img).bind('click', function(){ obj.clicked(next.href); });
			
			$j(img).fadeIn(3000);
			$j(img2).fadeOut(3000, function(){ obj.transitionFinish(img, img2) });
		},
		clicked: function(href)
		{
			window.location.href = href;
		},
		transitionFinish: function(img, img2)
		{
			var obj = this;
			setTimeout(function(){ obj.transition(img2, img); }, obj.delay); 
		}
}


