
// init items's start
var itemtrue = true, itemfalse = false;
var currMedia = "news";

function autoScroller(contentDiv, obj, speed, stop)
{
    contentDiv = "#" + contentDiv + obj;
    scrollSpeed = (speed==null) ? 5 : parseInt(speed);
    
            
    // double make sure the autoScroller-container has the correct css position and overflow property
    var parentDiv = $(contentDiv).parent();
    var parentDivHeight = parentDiv.height();
    
    parentDiv.css({position:'relative',overflow:'hidden'});
    
    
    // set contentDiv style
    $(contentDiv).css({position:'absolute',top: obj ? 0 : parentDivHeight});
    // get contentDiv height
    contentDivHeight = $(contentDiv).height();
    
	// no need to scroll
	if(parentDivHeight >= contentDivHeight) return;
    
    
    if(stop) 
    {
		$(contentDiv).stopTime();
		itemtrue = true;
		itemfalse = false;
		return;
	}
    
    
	// call periodical
	$(contentDiv).everyTime(40, function()
	{
		if(!eval("item" + obj))
		{
			$(contentDiv).css({display:'none'});
			return;
		}
		else
		{
			$(contentDiv).css({display:'block'});
		}
			
		// start oposite object
		if (parseInt($(this).css('top'))<(contentDivHeight*(-1)) + parentDivHeight) eval("item" + !obj + " = true");
					
		if (parseInt($(this).css('top'))>(contentDivHeight*(-1)))
		{	// move scroller upwards
			offset = parseInt($(this).css('top'))-scrollSpeed+"px";
			$(this).css({'top':offset});
		}
		else
		{	
			// stop current object
			eval("item" + obj + " = false");
			
			// reset to original position
			$(this).css({'top':parentDivHeight});
		}
	});
	

	// on mouse over event, pause the scroller
	$(contentDiv).mouseover(function ()
	{
		if(scrollSpeed != 0) speed = scrollSpeed; 
		scrollSpeed = 0;       
	});

	// on mouse out event, start the scroller
	$(contentDiv).mouseout(function ()
	{
		scrollSpeed = speed;
	});
}



