function changeElementText(id, newText) {
    if (id && newText) {
    	element = document.getElementById(id);
    	element.innerHTML = newText;
    }
}


function vor() {

    direction = 1;
    next_location = (parseInt(current_location) + parseInt(direction));
    if (next_location > photo_count) {
	next_location = 1;
	if (!loop) {
	    stop();
	}
    }
    if (next_location == 0) {
        next_location = photo_count;
	if (!loop) {
	    stop();
	}
    }

    current_location=next_location;
    preload_photo(current_location);

    document.slide.src = images[current_location].src;

    setCaption(photo_captions[current_location],photo_comment[current_location],photo_user_epic_comment[current_location]);
    if (onoff==1)
    	stop();
}

function back() {
    direction = -1;
    next_location = (parseInt(current_location) + parseInt(direction));
    if (next_location > photo_count) {
	next_location = 1;
	if (!loop) {
	    stop();
	}
    }
    if (next_location == 0) {
        next_location = photo_count;
	if (!loop) {
	    stop();
	}
    }

    current_location=next_location;
    preload_photo(current_location);

    document.slide.src = images[current_location].src;
    setCaption(photo_captions[current_location],photo_comment[current_location],photo_user_epic_comment[current_location]);
    if (onoff==1)
    	stop();
}


function preload_complete() {
}

function reset_timer() {
    clearTimeout(timer);

    if (onoff) {

	timeout_value = document.TopForm.time.options[document.TopForm.time.selectedIndex].value * 1000;
	timer = setTimeout('go_to_next_photo()', timeout_value);

    }
}

function wait_for_current_photo() {

    if (!show_current_photo()) {

	status = "Bild wird geladen...(" + current_location + " of " + photo_count +
		").  Bitte warten..." ;
	clearTimeout(timer);
	timer = setTimeout('wait_for_current_photo()', 505);
	return 0;
    } else {
	status = "Slideshow läuft...";
	preload_next_photo();
	reset_timer();
    }
}

function go_to_next_photo() {
    current_location = next_location;

    if (!show_current_photo()) {
	wait_for_current_photo();
	return 0;
    }

    preload_next_photo();
    reset_timer();

}

function preload_next_photo() {

    next_location = (parseInt(current_location) + parseInt(direction));
    if (next_location > photo_count) {
	next_location = 1;
	if (!loop) {
	    stop();
	}
    }
    if (next_location == 0) {
        next_location = photo_count;
	if (!loop) {
	    stop();
	}
    }

    preload_photo(next_location);
}

function show_current_photo() {

    if (!images[current_location] || !images[current_location].complete) {
	preload_photo(current_location);
	return 0;
    }

    if (browserCanBlend){
	var do_transition;
	if (current_transition == (transition_count)) {
	    do_transition = Math.floor(Math.random() * transition_count);
	} else {
	    do_transition = current_transition;
	}
	document.images.slide.style.filter=transitions[do_transition];
	document.images.slide.filters[0].Apply();
    }
    document.slide.src = images[current_location].src;
    setCaption(photo_captions[current_location],photo_comment[current_location],photo_user_epic_comment[current_location]);

    if (browserCanBlend) {
	document.images.slide.filters[0].Play();
    }

    return 1;
}

function preload_photo(index) {

    if (pics_loaded < photo_count) {

	if (!images[index]) {
	    images[index] = new Image;
	    images[index].onLoad = preload_complete();
	    images[index].src = photo_urls[index];


if (photo_urlsmed[index]) {
	    	imagesmed[index] = new Image;
	    	imagesmed[index].src = photo_urlsmed[index];
	    }


	    pics_loaded++;
	}
    }
}

function setCaption(text,comment,user_comment) {
    	if (text=="werbung") {
				changeElementText("caption", text + " &nbsp;&nbsp;[" + current_location + " von " + photo_count + "] ");
    		changeElementText("user_epic_comment", comment);
	} else {
		    			changeElementText("caption", "[Bild " + text + " von " + photo_count + "] " + comment);
    		    		changeElementText("user_epic_comment", user_comment);
	}
}

function zoom() {
    document.slide2.src = imagesmed[current_location].src;

}

function NeuFenster() {
 MeinFenster = window.open("../pics.php?img="+photo_urlsmed[current_location], "Zweitfenster","width=600,height=500");
 MeinFenster.focus();
}

function unzoom() {
	theimage=document.getElementById('slide2');
<!--	theimage.setAttribute("src","bilder/space.gif");-->
}
