var OriPicNum = 0;
var CurDocument = 0;
var CurPicNum = 0;
var CurUrl = "";

function next(thumb) {
	return (thumb +3) <= 29 ? thumb +3 : 2;
}

function update(idDoc) {
	if (CurDocument != 0 && idDoc == CurDocument) {
		document.getElementById("doc_" + CurDocument).src = CurUrl + CurPicNum + ".jpg";
		nextthumb = next(CurPicNum);
		preload(nextthumb);
		CurPicNum = nextthumb;
		setTimeout("update("+ CurDocument +")", 1000);
	}
}

function restore(){
	document.getElementById("doc_" + CurDocument).src = CurUrl + OriPicNum + ".jpg";
	CurDocument = 0;
}

function preload(pic) {
	heavyImage = new Image(); 
	heavyImage.src = CurUrl + pic + ".jpg";
}

function slide(IdDoc, Url, CurNum) {
	if (CurDocument == 0) {
		OriPicNum = CurNum;
		CurDocument = IdDoc;
		CurUrl = Url+".";
		var nextthumb = next(CurNum);
		preload(nextthumb);
		CurPicNum = nextthumb;
		setTimeout("update("+ CurDocument +")", 20);
	}
}

