﻿$(document).ready(function(){		
	createScroller();
});
var items = new Array();
var ulscroll;
function slide(el,prop,posX,t){	
	el.style.webkitTransitionProperty = prop;
	el.style.webkitTransitionDuration = t+'ms'
	el.style[prop]=posX+'px';	
}

var direction="left";
var rap=0;
var animTime=0;
function createScroller()
{

		$("#ulscroll>ul>li").each(function(index) 
		{
			$("#ulscroll").css({"width":$("#ulscroll").width()+$(this).width()+"px"})
		
			$(this).mouseover(function(event)
			{
				$("#"+event.target.id).css({"background-color":"#c00322"});
				$("#ulscroll").stop();
				rap=parseInt($("#ulscroll").css("left").split("px").join(""))/(-$("#ulscroll").width()+$("#scrollingnews").width())
			})
			$(this).mouseout(function(event)
			{
				$("#"+event.target.id).css({"background":"none"});
				if(direction=="left")animateScroller()
				else rewind();
			})

		});

	$("#ulscroll").css({"width":$("#ulscroll").width()+"px"})
	animTime=($("#ulscroll").width())*15;
	animateScroller();	
}
function animateScroller(){
		rap=1-rap;
		direction="left";
		$("#ulscroll").animate({
		left:-$("#ulscroll").width()+$("#scrollingnews").width()+"px"
		},parseInt(animTime*rap),'linear',function(){rap=1;rewind()})
}
function rewind(){
	direction="right";
	$("#ulscroll").animate({
		left:0+"px"
		},parseInt(animTime*rap),'linear',function(){rap=0;animateScroller()})
}
