$(function(){
	var slideCount = $('#branding>ul>li').length;
	var firstHelf = $('#branding>ul>li').slice(0, Math.ceil(slideCount/2));
	var secondHelf = $('#branding>ul>li').slice(Math.ceil(slideCount/2));
	
	$('#branding>ul').empty().append(secondHelf).append(firstHelf);
	
	$('#branding>ul').append($('#branding>ul>li').clone());
	var loopChildrens = $('#branding>ul>li');
	
	$('#branding>ul').width($(loopChildrens).length*$(loopChildrens).width());
	$('#branding>ul>li').addClass('disableItem');
	
	
	var windowCenter = $('html, body').width()/2;
	var centerItemIdx = null;
	if($('#branding>ul>li').length%2 == 0){
		centerItemIdx = ($('#branding>ul>li').length/2)+1;
	} else {
		centerItemIdx = Math.floor($('#branding>ul>li').length/2);
	}

	centerItemIdx = 3;

	$('#branding>ul').css({
		left: -$(loopChildrens).width()*2+(($('html, body').width()-$('#branding>ul>li').width())/2)
	});

	$('#branding>ul>li:eq(2)').animate({
		// 'background-color': '#000',
		// opacity: 1
	}, 1500);

	$.each(loopChildrens, function(i){
		$(this).css({
			top: 0,
			left: $(this).width()*i
		});
	});

	var isFirst = true;
	setInterval(function(){
		$.each($('#branding>ul>li'), function(i){
			if($(this).position().left < -($(this).width())){
				$('#branding>ul').append($(this));
				$('#branding>ul>li:last').css({
					left: $(this).width()*($('#branding>ul>li').length-2)
				});
			}
			
			$('#branding>ul>li').removeAttr('id');
			if(isFirst){
				$('#branding>ul>li:eq(3)').attr('id', 'enableItem');
			} else {
				$($('#branding>ul>li').get(centerItemIdx+1)).attr('id', 'enableItem');
			}
			
			if($(this).attr('id') == 'enableItem'){
				$(this).animate({
					left: $(this).position().left-$(this).width(),
					// 'background-color': '#000'
					opacity: 1
				}, 1500);
			} else {
				$(this).removeAttr('id');
				$(this).addClass('disableItem');
				$(this).animate({
					left: $(this).position().left-$(this).width(),
					//'background-color': '"'+$('#branding li.disableItem').css('background-color')+'"'
					opacity: 0.5
				}, 1500);
			}
		});
		isFirst = false;
	}, 5000);
});

