

setTimeout(function(){

var slider = $('#adwrap');

var numberofslides = $('.adPanel').length;
var slideWidth = 820;
var currentPos = 0;
var limit = numberofslides - 2;
var delayBy = 4500;

function resetSlide(){
	slider.animate({
	    left: 0
	}, 1000, function() {
		currentPos = 0;
	});
}

function resetToLast(){
	slider.animate({
		left: slideWidth * (limit) * -1
	}, 1000, function() {currentPos = limit});
}


function prevSlide(){
	slider.animate({
	    left: currentPos * slideWidth * -1
	}, 1000, function() {	});
}

function nextSlide(){
	slider.animate({
	    left: currentPos * slideWidth * -1
	}, 1000, function() {	});
}

var masterInterval = setInterval(function(){
	if(currentPos < limit){currentPos++;nextSlide();}
	else {clearInterval(masterInterval);resetSlide();}
},delayBy);

$('#btnAdRight').click(function(){
	if(masterInterval)clearInterval(masterInterval);
	if(currentPos < limit){
		currentPos++;
		nextSlide();
		
	}
	else {resetSlide();}
	
});

$('#btnAdLeft').click(function(){
	if(masterInterval)clearInterval(masterInterval);
	if(currentPos > 0){
		currentPos = currentPos-1;
		prevSlide();
		
	}
	else {resetToLast();}
});

},400);



