var webcam_auto_active = false;
var this_name='', this_dir_path='', this_form_select='', this_button_name='';
var this_speed_name=1000;
var webcam_reload_time_in_sec = 60000;
var webcam_text_start = 'Starten';
var webcam_text_stopp = 'Stoppen';

function webcam_set_image(name, dir_path, img_src )
{
	document[name].src = ( img_src.indexOf('/')<0 ? dir_path : '' ) +img_src;
}

function webcam_next( name, dir_path, form_select )
{
	webcam_auto_active= false;
	
	if (document.webcam_form[form_select].selectedIndex<=0)
		document.webcam_form[form_select].selectedIndex=document.webcam_form[form_select].length-1;
	else
		document.webcam_form[form_select].selectedIndex-=1;
	val = document.webcam_form[form_select].value;
	document[name].src = ( val.indexOf('/')<0 ? dir_path : '' ) +val;
}

function webcam_prev( name, dir_path, form_select )
{
	webcam_auto_active= false;

	if (document.webcam_form[form_select].selectedIndex>=document.webcam_form[form_select].length-1)
		document.webcam_form[form_select].selectedIndex=document.webcam_form[form_select].selectedIndex=0;
	else
		document.webcam_form[form_select].selectedIndex+=1;
	val = document.webcam_form[form_select].value;
	document[name].src = ( val.indexOf('/')<0 ? dir_path : '' ) +val;
}

function webcam_auto_on( name, dir_path, form_select, button_name,speed_name,text_start,text_stopp )
{
	webcam_text_start = text_start;
	webcam_text_stopp = text_stopp;
	if ( webcam_auto_active ) {
		webcam_auto_active=false;
		document.webcam_form[button_name].value=webcam_text_start;
	} else {
		this_name=name;
		this_dir_path=dir_path;
		this_form_select=form_select;
		this_speed_name=speed_name;
		webcam_next( this_name, this_dir_path, this_form_select );
		webcam_auto_active = true;
		document.webcam_form[button_name].value=webcam_text_stopp;
		this_button_name=button_name;
		speed = document.webcam_form[this_speed_name].value;
		setTimeout("webcam_auto()", speed);
	}
}

function webcam_auto( ) {
	if ( webcam_auto_active ) {
		webcam_next( this_name, this_dir_path, this_form_select );
		webcam_auto_active= true;
		speed = document.webcam_form[this_speed_name].value;
		setTimeout("webcam_auto()", speed);
	} else
		document.webcam_form[this_button_name].value=webcam_text_start;
}
function webcam_current_reload_on(name, img_path ) {
	setTimeout("webcam_current_reload('"+name+"','"+img_path+"')", webcam_reload_time_in_sec);
}

function webcam_current_reload(name, img_path ) {
		if ( document[name].src.indexOf(img_path)>=0) {
			document[name].src=img_path + '?' + (new Date()).getTime();
		}
		setTimeout("webcam_current_reload('"+name+"','"+img_path+"')", webcam_reload_time_in_sec);
}
