// Window width functionality

function adjustWindowWidth(){
	var windowWidth = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth)
	if(windowWidth >= widthPadding){
		$('scroll_right').hide();
		$('scroll_container').setStyle({width:'auto', minWidth:width+'px'});
	} else {
		$('scroll_right').show();
		$('scroll_container').setStyle({width:width+'px'});
	}
}

// Scrolling functionality

var target = 0
var scrollRange = 0
var imageWidth = 5
var frame = 0
var imageMargin = 0;


function setScrollRange(){
		scrollRange = $('scroll_container').getWidth() - document.viewport.getWidth()
	}
	
function setTarget(pe){
	// Set target in order by frame
	frame+=1
	target = frame*(imageWidth+imageMargin)
	
	if (target > scrollRange){
		target = 0
		frame = 0
		pe.stop();
	}	
	
	
}

function initWindowVariables(pe){
	setScrollRange()
	setTarget(pe)
}


function scrollWindow(pe){

	//var xposition = document.viewport.getScrollOffsets()[0]
	//var delta=target-xposition
	//var newPosition = Math.floor(xposition + delta/1)
	
	window.scrollTo(target, 0)
	setTarget(pe)
	
	//if(Math.abs(delta)<30){
	//	setTarget()
	//}
}


function autoScroll(){
	var pe = new PeriodicalExecuter(function(pe){
		scrollWindow(pe
		);
		

	
	}, .03);
	initWindowVariables(pe);

}