var image_file=new Array(20);
var total=0;
var now_image=0;
var id;
var idx;
var loop_num=12;
var selsize=0;

function init(ty) {
	get_val(ty);
	ShowOneOrMore();
}

function stop_image() {

	if(id)
		clearTimeout(id);

	for(i=0;i<20;i++)
		delete(image_file[i]);

}

function change_image(a1,l1) {

	stop_image();

		
	area_sel=a1;
	loop_or_not=l1;

	sel_to=document.f.sel.selectedIndex;
	sel_from=document.f.sel.selectedIndex+loop_num-1;
	if(sel_from>=document.f.sel.options.length) sel_from=document.f.sel.options.length-1;
	total=sel_from-sel_to+1;
	ii=0;
	for(i=sel_from;i>=sel_to;i--) {
			a = new Image();
			fn=document.f.sel.options[i].value;
			a.src=fn;
			image_file[ii]= a;
			ii=ii+1;
	} 

	if(total>1) Loop();
	else
		document.f.im.src=image_file[0].src;
}

function Loop() {
		document.f.im.src=image_file[now_image].src;
		now_image=(now_image+1)%total;
		id = setTimeout('Loop()',1000);
}


function ChangeLink(ty,dd) {

		if(dd==1)
			get_val(ty);
		ChangeSelect();
}


function ShowOneOrMore(ty) {
	stop_image();

	area_sel=GetRadioValue(document.f.area);
	if(ty) loop_or_not=ty.value;
	else
		loop_or_not=GetRadioValue(document.f.lo);

	fn=document.f.sel.options[document.f.sel.selectedIndex].value;
	document.f.im.src=fn;

	if(loop_or_not=="1") change_image(area_sel,loop_or_not);
}

function get_val(ty) {

	for(i=0;i<ty.length;i++) {
		if(i==0) {
			document.f.sel[i]=new Option(ty[i][0],ty[i][1],true,true);
			document.f.sel.options[i].selected = true;
		}
		else {
			document.f.sel[i]=new Option(ty[i][0],ty[i][1]);
			document.f.sel.options[i].selected = false;
		}
	}
	document.f.sel.length=ty.length;
}

function SelectArea(ty,co) {

	get_val(ty);
	area_sel=GetRadioValue(document.f.area);
	loop_or_not=GetRadioValue(document.f.lo);

	fn=document.f.sel.options[document.f.sel.selectedIndex].value;
	document.f.im.src=fn;
	if(loop_or_not=="1") change_image(area_sel,loop_or_not);
}

function GetRadioValue(ty) {
var val;
	idx=ty.length;
	for(i=0;i<idx;i++) {
		if(ty[i].checked)
			val=ty[i].value;
	}
	return val;
}
	
