/* This version of FeaturedSlideshow uses jquery instead of mootools */
function SlideShow(el, images)
{
	var obj = this;
	
	this.delays = [3000,4000,5000];
	this.images = new Array()
	//cache images
	for(var i = 0; i < images.length; i++)
	{
		var img = new Image();
		img.src = '/images/artwork/'+images[i];
		this.images[i] = img;
	}
	
	this.size = this.images.length;
	this.used = new Array(this.size);
	
	this.div = $('#'+el);
	this.div.css('cursor', 'pointer');
	this.div.bind('click', function(){ window.location.href = '/catalog/'; });
	this.div.hover(function()
	{
		$(obj.fade).fadeTo('fast', .5);
	},
	function()
	{
		$(obj.fade).fadeTo('fast', 0);
	});
	
	this.img = document.createElement("img");
	$(this.img).css('position', 'absolute').css('z-index', 1);
	
	
	var rand_no = Math.ceil(this.size*Math.random())-1;
	this.img2 = document.createElement("img");
	this.img2.src = this.images[rand_no].src;
	$(this.img2).css('position', 'absolute').css('z-index', 1);
	
	this.div.append(this.img);
	this.div.append(this.img2);
	
	this.fade = document.createElement('div');
	$(this.fade).css('height', '230px').css('width', '150px').css('background-color', '#333').css('z-index', 10).css('position', 'absolute').css('opacity', 0);
	this.div.prepend(this.fade);
	
	setTimeout(function(){ obj.transition(obj.img, obj.img2); }, this.getDelay()); 
}

SlideShow.prototype = {
	transition: function(img, img2)
	{
		var obj = this;
		var rand_no = Math.ceil(this.size*Math.random())-1;
		//alert(rand_no);
		img.src = this.images[rand_no].src;
		
		$(img).fadeIn(2000);
		$(img2).fadeOut(2000, 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); }, this.getDelay()); 
	},
	getDelay: function()
	{
		var rand_no = Math.ceil(this.delays.length*Math.random())-1;
		return this.delays[rand_no];
	}
}

