function MsnCarousel(carouselElementId, containerId, itemWidth, listItemsType, prevButtonId, nextButtonId, activeButtonClassName)
{
	var carousel = this;
	
	this.carouselElement = document.getElementById(carouselElementId);
	this.container = document.getElementById(containerId);
	this.itemWidth = itemWidth;
	this.listItemsType = listItemsType;
	this.prevButton = document.getElementById(prevButtonId);
	this.nextButton = document.getElementById(nextButtonId);
	this.activeButtonClassName = activeButtonClassName;
	
	this.left = 0;
	this.maxWidth = this.itemWidth * (this.carouselElement.getElementsByTagName(listItemsType).length - 1);
	this.moving = false;
	
	this.setActiveButtons = function()
	{
		if(carousel.left == 0)
		{
			carousel.prevButton.className = '';
		}
		else
		{
			carousel.prevButton.className = carousel.activeButtonClassName;
		}
		
		if(carousel.left == -carousel.maxWidth)
		{
			carousel.nextButton.className = '';
		}
		else
		{
			carousel.nextButton.className = carousel.activeButtonClassName;
		}
	}
	
	this.moveItems = function(prev_or_next)
	{
		if(this.moving == false)
		{
			var mover;
			if(prev_or_next == 'prev')
			{
				mover = new YAHOO.util.Anim(this.container, { left: { from: this.left, to: this.left + this.itemWidth } }, 0.2);
			}
			else
			{
				mover = new YAHOO.util.Anim(this.container, { left: { from: this.left, to: this.left - this.itemWidth } }, 0.2);
			}
			
			var setLeft = function()
			{
				carousel.left = parseInt(carousel.container.style.left.replace(/px/, ''));
				carousel.setActiveButtons();
				carousel.moving = false;
			}
			
			this.moving = true;
			mover.animate();
			mover.onComplete.subscribe(setLeft);
		}
	}
	
	this.prev = function()
	{
		if(this.left < 0)
		{
			this.moveItems('prev');
		}
	};
	
	this.next = function()
	{
		if(this.left > -this.maxWidth)
		{
			this.moveItems('next');
		}
	};
	
	this.initialize = function()
	{
		this.container.style.width = this.itemWidth * this.carouselElement.getElementsByTagName(listItemsType).length + 'px';
		this.setActiveButtons();
		this.nextButton.onclick = function()
		{
			carousel.next();
			return false;
		};
		this.prevButton.onclick = function()
		{
			carousel.prev();
			return false;
		}
	};
	
	this.initialize();
}

function blockTabButton(e)
{
	if(!e)
	{
		e = window.event;	
	}
	if(e.keyCode == 9)
	{
		return false;
	}
}

document.onkeydown = blockTabButton;

window.onload = function()
{
	var winks_carousel = new MsnCarousel('winks-carousel', 'winks-content', 230, 'span', 'winks-left', 'winks-right', 'active');
	var emoticons_carousel = new MsnCarousel('emoticons-carousel', 'emoticons-content', 230, 'span', 'emoticons-left', 'emoticons-right', 'active');
	var backgrounds_carousel = new MsnCarousel('backgrounds-carousel', 'backgrounds-content', 115, 'span', 'backgrounds-left', 'backgrounds-right', 'active');
}

function ThumbManager(id, thumblist, items_shown)
{
	var this_instance = this;
	
	this.images = eval(thumblist);
	this.image_elements = document.getElementById(id).getElementsByTagName('img');
	this.loaded_images = 0;
	this.total_images = this.image_elements.length;
	this.items_shown = items_shown;
	
	this.showNext = function()
	{
		var loaded_images = this_instance.loaded_images;
		for(var i = loaded_images; i < loaded_images + this_instance.items_shown; i ++)
		{
			if(this_instance.images[i])
			{
				this_instance.image_elements[i].src = this_instance.images[i];
				this_instance.loaded_images ++;
			}
		}
	}
	
	if(window.attachEvent)
	{
		document.getElementById(id.replace(/content/, 'right')).attachEvent('onclick', this_instance.showNext);
	}
	else
	{
		document.getElementById(id.replace(/content/, 'right')).addEventListener('click', this_instance.showNext, false);
	}
	
	this.showNext();
}
