if(typeof widgets=="undefined") widgets = new Object();
widgets.featured = function(args)
{
	args = args | new Object();
	
	this.activeClass = "active";
	
	this.tansSpeed = "slow";
	this.delay = 5 * 1000;
	
	this.noConflict = args.noConflict | false;
	
	this.activeNum = 1;
	
	var me = this;
	var pre = "#landing .slideshow ";
	var preInfo = "#landing #featuredInfo";
	var jQ;
	
	//Prevent prototype.js conflicts.
	if(this.noConflict)
	{
		jQ = jQuery;
		jQ.noConflict();
	}
	else
		jQ = $;
	
	jQ(document).ready(function()
	{
		me.count = jQ(pre + "img").length;
		if(me.count > 1)
			me.timeout = setTimeout(function() { me.showImg(2); }, me.delay);
	});
	
	this.showImg = function(num)
	{
		if(me.activeNum != num)
		{
			if(me.timeout)
				clearTimeout(this.timeout);
			
			outEl = jQ(pre + ".active");
			inEl = jQ(pre + "#featuredImg" + num);
			outEl.fadeOut(me.transSpeed, function() { outEl.removeClass(me.activeClass); });
			inEl.addClass(me.activeClass);
			inEl.fadeIn(me.transSpeed);
			
			outEl = jQ("#landing div.active");
			outElC = outEl.children('#featuredInfoDefault');
			inEl = jQ(preInfo + num);
			inElC = inEl.children('#featuredInfoDefault');
			if (outElC.length == 1 && inElC.length == 1) {
				inEl.show();
				inEl.addClass(me.activeClass);
				outEl.hide();
				outEl.removeClass(me.activeClass);
			} else {
				outEl.fadeOut(me.transSpeed, function() { outEl.removeClass(me.activeClass); });
				inEl.addClass(me.activeClass);
				inEl.fadeIn(me.transSpeed);
			}
			
			this.activeNum = num;
			
			me.timeout = setTimeout(function() { me.showImg(me.activeNum + 1 <= me.count ? me.activeNum + 1 : 1); }, me.delay);
		}
		return false;
	}
}

Number.prototype.pad = function(digits) {
	var n = this.toString();
	while (n.length < digits) {
		n = '0' + n;
	}
	return n;
}