if(typeof widgets=="undefined") widgets = new Object();
widgets.header = function(args)
{
	args = args | new Object();
	
	this.activeClass = "active";
	
	this.tansSpeed = "slow";
	this.delay = 15 * 1000;
	
	this.noConflict = args.noConflict | false;
	
	this.activeNum = 1;
	
	var me = this;
	var pre = ".slideshow ";
	var preInfo = "#headerInfo";
	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");
			outEl2 = jQ('.slidetoggle ' + ".active");
			inEl = jQ(pre + "#headerImg" + num);
			inEl2 = jQ('.slidetoggle ' + "#slideButton" + num);
			outEl.fadeOut(me.transSpeed, function() { outEl.removeClass(me.activeClass); });
			outEl2.removeClass(me.activeClass);
			inEl.addClass(me.activeClass);
			inEl2.addClass(me.activeClass);
			inEl.fadeIn(me.transSpeed);
			inEl2.fadeIn(me.transSpeed);
			
			outEl = jQ("div.slideshowInfo.active");
			if (outEl.length) {
				outElC = outEl.children('#headerInfoDefault');
				inEl = jQ(preInfo + num);
				inElC = inEl.children('#headerInfoDefault');
				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;
}
