var scrolling=[];
var reset=[];
var hover=[];
var height=120;//height of the image
var linkh=25;//height of the link (may need to be ajdusted by +-1)
//var linktop=0;
function scroll(sdiv1, k){
	//if(scrolling[k]){
	//alert(sdiv);
		sdiv = document.getElementById(sdiv1);
		sdiv2 = document.getElementById(sdiv1+'b');
		
		var top = parseInt((-(height+11)-parseInt(sdiv.style.top))/5);
		//alert(top);
		sdiv.style.top=parseInt(sdiv.style.top)+top+"px";
		
		//var top2 = parseInt((-(height+11)-parseInt(sdiv.style.top))/5);
		sdiv2.style.top=parseInt(sdiv2.style.top)-top-parseInt(linkh/10)+"px";
		//linktop=top-parseInt(linkh/10);
		//alert(linktop);
		if(parseInt(sdiv.style.top)>-height){
			
			//scroll(sdiv);
			setTimeout(function (){scroll(sdiv1, k);}, 25);
			
		}else{
			//alert("done");
			//sdiv.scrollTop=0;
			scrolling[k]=false;
			//time=5;
		}
	//}
}
function startScroll(sdiv1,k){
	//sdiv = document.getElementById(sdiv1);
	hover[k]=true;
	if(!scrolling[k] && !reset[k]){
		//sdiv.scrollTop=0;
		scrolling[k]=true;
		scroll(sdiv1, k);
	}else{
		
	}
	
}
function resetScroll(sdiv1,k){
	if(!hover[k]){
	sdiv = document.getElementById(sdiv1);
	//alert("reset");
	if(!scrolling[k]){
		reset[k]=true;
		sdiv.style.top=0+"px";
		sdiv = document.getElementById(sdiv1+'b');
		sdiv.style.top=height-linkh+"px";
		resetStitle(sdiv1+'b',k);
		//alert(sdiv.scrollTop);
		//alert(linktop);
	}else {//if(!hover[k]){
		//scrolling[k]=false;
		setTimeout(function (){resetScroll(sdiv1, k);}, 20);
	}
	}
}
function resetStitle(sdiv2,k){
	if(!hover[k]){
	sdivb = document.getElementById(sdiv2);
	//alert(sdiv2);
	if(parseInt(sdivb.style.top)<height){
		//setTimeout(function(){
		//sdiv.scrollTop=0;//},25);
		sdivb.style.top=parseInt(sdivb.style.top)+1+"px";
		setTimeout(function (){resetStitle(sdiv2, k);}, 10);
		
	}else{
		reset[k]=false;
	}
	//alert(sdiv.scrollTop);
	}
}
