var allImg=new Array;

function loadImages(){
	if(!document.images){}
	else{
		for (var i=0;i<Str.length;i++){
			allImg[i]=new Image();
			allImg[i].src=path + Str[i].img;
		}
		document.getElementById('content').innerHTML="<img src='"+ allImg[0].src +"' id='mainImg' />";
		setTimeout('autoSwap()',4000);
	}
}

var pause=false;
var period=4000;
var timer;

function chgPeriod(value){
	if (value==0) value=1;
	period=value*1000; clearTimeout(timer); autoSwap(period);
}

var i=-1;
function autoSwap(period){
	i++;
	beginEnd();
	document.getElementById('mainImg').src=allImg[i].src;
	timer=setTimeout('autoSwap(period)',period);
}

function playStop(action){
	if (action=='play'){
		if (pause) autoSwap(); pause=false;
	}
	if (action=='stop') clearTimeout(timer); pause=true;
}

function  nextBack(move){
	clearTimeout(timer); pause=true;
	if (move=='back') i--;
	if (move=='next') i++;
	if (move=='first') i=0;
	if (move=='last') i=(Str.length-1);
	beginEnd(); document.getElementById('mainImg').src=allImg[i].src;
}

function beginEnd(){
	if (i==Str.length) i=0;
	if (i==-1) i=(Str.length-1);
}

window.onload=loadImages;
