(function($){
		  
	$.addMarquee = function(marqueeContainer,options)
	{
		var properties  = $.extend({
			speed :1,
			items_to_show:3
		}, options);
					
		var Marquee = function()
		{
			this.idDownTimeout = null;
		};
		Marquee.prototype.addBehaviourToLinks = function()
		{
			$("a",marqueeContainer).mouseover(function()
			{
				properties.speed = 0;
			});
			$("a",marqueeContainer).mouseout(function()
			{
				properties.speed = 1;
			});
		};
		Marquee.prototype.init = function()
		{
			var listHeight = parseInt($("ul",marqueeContainer).height(),10);
		
			var positionProductsContainer = $(marqueeContainer).offset();
			var averageHeight = parseInt(positionProductsContainer.top,10) + (parseInt($(".content_marquesina_portlet").height(),10)/2);
			var heightPerItem =  parseInt(listHeight/$("li",marqueeContainer).length,10);
			if($("li",marqueeContainer).length >= properties.items_to_show)
			{
				this._moveUp();
			}
		};
		Marquee.prototype._moveUp = function()
		{
			var height = parseInt($("ul li:eq(0)",marqueeContainer).height(),10)*-1;
			var marginTop = parseInt($("ul",marqueeContainer).css("margin-top"),10);
			$("ul",marqueeContainer).css("margin-top", (marginTop - properties.speed)+"px");
			if(marginTop <= height)
			{
				$("ul",marqueeContainer).append($("ul li:eq(0)",marqueeContainer));
				$("ul",marqueeContainer).css("margin-top","0px");
			}
			var moveUp = (function(oReference)
			{
				return function()
				{
					oReference._moveUp();
				};
			})(this);
			
			this.idDownTimeout = setTimeout(moveUp,10);
		};
		
		var oMarquee = new Marquee();
		oMarquee.addBehaviourToLinks();
		oMarquee.init();
	};
	
	
	$.fn.marquee = function(properties) {
		return this.each( function() {
			var marqueeContainer = this;
			$.addMarquee(marqueeContainer, properties);
		});
	};
	
})(jQuery);

