
/**
#           :SlideMe - Image Gallery V 1.0              #
#             Copyright (c) by Mario B.                 #
#                 www.m-a-r-i-o.com                     #
#-------------------------------------------------------#
#    This script can be used freely as long as this     #
#           copyright-notice remains here.              #
#                                                       #
#       See readme.txt for further information.         #
*/
var timer;
var next_location = 1;
var pics_loaded = 0;
var onoff = 0;
var direction = 1;
var timeout_value;
var images = new Array;
var transitionNames = new Array;
var transitions = new Array;
var current_transition = 1;
var loop = 1;

/** Time Out Rufen */
if(resize == 1){
	window.setInterval("window_resize()", 1000);
}

transitions[0] = "progid:DXImageTransform.Microsoft.Fade(duration=1)";
transitions[1] = "progid:DXImageTransform.Microsoft.Blinds(Duration=1,bands=20)";
transitions[2] = "progid:DXImageTransform.Microsoft.Checkerboard(Duration=1,squaresX=20,squaresY=20)";
transitions[3] = "progid:DXImageTransform.Microsoft.Strips(Duration=1,motion=rightdown)";
transitions[4] = "progid:DXImageTransform.Microsoft.Barn(Duration=1,orientation=vertical)";
transitions[5] = "progid:DXImageTransform.Microsoft.GradientWipe(duration=1)";
transitions[6] = "progid:DXImageTransform.Microsoft.Iris(Duration=1,motion=out)";
transitions[7] = "progid:DXImageTransform.Microsoft.Wheel(Duration=1,spokes=12)";
transitions[8] = "progid:DXImageTransform.Microsoft.Pixelate(maxSquare=10,duration=1)";
transitions[9] = "progid:DXImageTransform.Microsoft.RadialWipe(Duration=1,wipeStyle=clock)";
transitions[10] = "progid:DXImageTransform.Microsoft.RandomBars(Duration=1,orientation=vertical)";
transitions[11] = "progid:DXImageTransform.Microsoft.Slide(Duration=1,slideStyle=push)";
transitions[12] = "progid:DXImageTransform.Microsoft.RandomDissolve(Duration=1,orientation=vertical)";
transitions[13] = "progid:DXImageTransform.Microsoft.Spiral(Duration=1,gridSizeX=40,gridSizeY=40)";
transitions[14] = "progid:DXImageTransform.Microsoft.Stretch(Duration=1,stretchStyle=push)";
transitions[15] = "special case";
var transition_count = 15;

var slideShowLow = "";

var browserCanBlend = (is_ie5_5up);

function pop_up (id) {
  MeinFenster = window.open(url+"/slideshow-"+current_location+"-"+id+".html", "Zweitfenster", "width=300,height=400,left=100,top=200");
  MeinFenster.focus();
}

function stopOrStart() {
    if (onoff) {
	stop();
    } else {

	play();
    }
}


function toggleLoop() {
    if (loop) {
	loop = 0;
    } else {
	loop = 1;
    }
}


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

function stop() {
    changeElementText("stopOrStartText", "<img src=\""+url+"\"/images/play.gif\" border=\"0\" alt=\"play\">");

    changeElementText("changeDirText", "&nbsp;");

    if (browserCanBlend) {
    	changeElementText("select1", "&nbsp;");
    	changeElementText("select2", "&nbsp;");
    }

    onoff = 0;
    clearTimeout(timer);

}

function play() {

    changeElementText("stopOrStartText", "<img src=\""+url+"\"/images/pause.gif\" border=\"0\" alt=\"aus\">");
    if (browserCanBlend) {
    	if (!onoff) {
		if (direction==1)
			changeElementText("changeDirText", "&raquo;&raquo;");
		else
			changeElementText("changeDirText", "&laquo;&laquo;");
		changeElementText("select1", "<select name='time' size=1  onchange='play()' style='font-family: Tahoma,Verdana,Arial, Helvetica; font-size: 9px; width: 40px; color : #000000; background-color: #f3f3f3; border-color:#f3f3f3; '><option value=1 > 1s<option value=2 selected> 2s<option value=3 > 3s<option value=4 > 4s<option value=5 > 5s<option value=10 > 10s</select>");
		changeElementText("select2", "<select name='transitionType' size=1  onchange='change_transition()' style='font-family: Tahoma,Verdana,Arial, Helvetica; font-size: 9px; width: 90px; color : #000000; background-color:#f3f3f3; border-color:#000000; '> <option value=0> Blend <option value=1 > Blinds <option value=2 > Checker <option value=3 > Diagonal <option value=4 > Doors <option value=5 > Gradient <option value=6 > Iris <option value=7 > Pinwheel <option value=8 > Pixelate <option value=9 > Radial <option value=10 > Rain <option value=11 > Slide <option value=12 > Snow <option value=13 > Spiral <option value=14 > Stretch <option value=15 > .:Random:. </select>");
	}

   }

    onoff = 1;

    go_to_next_photo();
}

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();

	window_resize();
}

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();

	window_resize();
}

function weiter() {
    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();

	window_resize();
}

function changeDirection() {
    if (direction == 1) {
	direction = -1;
	changeElementText("changeDirText", "&laquo;&laquo;");
    } else {
	direction = 1;
	changeElementText("changeDirText", "&raquo;&raquo;");
    }
    setCaption(photo_captions[current_location],photo_comment[current_location],photo_user_epic_comment[current_location]);
    preload_next_photo();

}

function change_transition() {
    current_transition = document.TopForm.transitionType.selectedIndex;
}

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 + " von " + 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();
	window_resize();
}

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 window_resize(){
	if(resize==1) window.resizeTo(images[current_location].width, images[current_location].height+130);
}

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];
		    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 + " &nbsp;&nbsp;[" + current_location + " von " + photo_count + "] " + "&nbsp;&nbsp;&nbsp;" + comment);
	changeElementText("user_epic_comment", user_comment);
	}
}
