/**
 * @author The One
 */

function scroller (way)
{
	way.css({marginLeft: '0px'});
	way.animate({marginLeft: -way.width()-way.parent().width()}, way.find('li').length*10000, 'linear', function(){scroller(way)});
}

function checkloaded (arr)
{	
	var res = true;
	for (var j = 0; j < arr.length; j++) 
	{
		if (!arr[j].loaded) {res = false; break;}
	} 
	if (res) {
		$('.partners').each(function()
		{
			var length = 0;
			$('li', $(this)).each(function(){
				length += $(this).width() + 35;
			});
			$(this).css({width: length});
			
			$(this).animate({left: $(this).parent().width()},500)
			scroller($(this));
			
		});
	}
}

$(document).ready(function()
{	
	var imagelist = [];
	
	imagelist.length = $('.partners img').length;
	
	for (var j = 0; j < imagelist.length; j++) {
		imagelist[j] = new Image();
		imagelist[j].loaded = false;
		imagelist[j].onload = function () {
			this.loaded = true;
			checkloaded(imagelist);
		}
		imagelist[j].src = $('.partners img').eq(j).attr("src"); 
	}

});
