var SCROLLING = false;


function adjustDownloads(){
	//(viewPort('height') >= 400 && scrollOffset() >= viewPort('height') * .20)
	//? offset = viewPort('height') / 6
	//: offset = 0;
	(viewPort('height') >= 500 && scrollOffset() >= 500)
	? offset = scrollOffset() - 440 
	: offset = 0;

//	var value =  scrollOffset()+offset + 'px';	
	var value =  offset + 'px';	
	$('mydownloads').morph('margin-top:'+value,{ duration:1, transition:Effect.Transitions.EaseFromTo });	
}

function afterScroll(){
	var baseId = 0;
	var scrollId = new Date().getTime();
	var checkdelay = 200;

	if(!SCROLLING) { 
		SCROLLING=true;
		setTimeout(
			function(){
				if(scrollId == baseId){
					SCROLLING = false;
					//DO THE FOLLOWING
					adjustDownloads();
				}
				else{
					//RECURSIVE RUNCTION CALL
					baseId=scrollId;
					setTimeout(arguments.callee, checkdelay)
				}
			}, 
			checkdelay
		);
	}
}

function scrollOffset(){
	if(window.pageYOffset){
		return window.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop){
		return document.documentElement.scrollTop;
	}
	else if (document.body){
		return document.body.scrollTop;
	}
}

function viewPort(dimension){
	var x, y;
	if (self.innerHeight) // all except Explorer
	{
		y = self.innerHeight;
		x = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		y = document.documentElement.clientHeight;
		x = document.documentElement.clientWidth;
	}
	else if (document.body) // other Explorers
	{
		y = document.body.clientHeight;
		x = document.body.clientWidth;
	}
	if (dimension == 'height'){
		return y;
	}
	if (dimension == 'width'){
		return x;
	}
}

