$(document).ready(function() {
	var countitems = 0;
	var rangeofmotion = 0;
	var controls = false;
	var currentpos = 0;
	var currentleft =0;
	var newleft = 0;
	var newwidth =0;
	
	$('.newsitem').each(function(index) {
    countitems++;
  	});
	
	if (countitems > 4){
		$('.rightarrow').show();
		controls = true;
		rangeofmotion = countitems - 4;
		newwidth = countitems * 208;
		$('.newsslider').css({width: newwidth+'px'});
	}
	
	$('.rightarrow a').click( function(){ 
		
		currentleft = $('.newsslider').css('left').replace('px','');
		
		if (controls){
			controls = false;
			newleft = parseFloat(currentleft) - 208;
			$('.newsslider').animate({left: parseFloat(newleft)+'px'}, 500);
			currentpos++;
			if (currentpos >= rangeofmotion){
				$('.rightarrow').hide();	
			}
			if (currentpos >= 0){
				$('.leftarrow').show();	
			}
			setTimeout(function () { controls = true; }, 500);
		
		}
		return false;
	});
	
	$('.leftarrow a').click( function(){ 
		
		currentleft = $('.newsslider').css('left').replace('px','');
		
		if (controls){
			controls = false;
			newleft = parseFloat(currentleft) + 208;
			
			$('.newsslider').animate({left: parseFloat(newleft)+'px'}, 500);
			currentpos--;
			if (currentpos < rangeofmotion){
				$('.rightarrow').show();	
			}
			if (currentpos <= 0){
				$('.leftarrow').hide();	
			}
			setTimeout(function () { controls = true; }, 500);
		
		}
		return false;
	});
	
	
});
