<!--
// HTTP-Request ausführen - AJAX
// http://board.gulli.com/thread/801675-php-script-aus-einem-javascript-aufrufen/

function get(url, callback_function, return_xml)
{
    //alert(url);
	var http_request = false;

	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml; charset= iso-8859-1');
		}
	}else if(window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Leider unterstützt Ihr Browser diese Funktion nicht.');
		return false;
	}
	http_request.onreadystatechange = function() {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				if (return_xml) {
					eval(callback_function + '(http_request.responseXML)');
				} else {
					eval(callback_function + '(http_request.responseText)');
				}
			} else {
				alert('Problem: ' + http_request.status + ')');
			}
		}
	}
	http_request.open('GET', url, true);
	http_request.send(null);
}

function doNothing(text)
{
    return;//document.getElementById('id').innerHTML = text;
}

function WriteCounterFile(file)
{
    var filename = file.split(".jpg").join(".cnt");

    //alert(filename);
    get("WriteCounter.php?file="+filename,"doNothing");
}

function change_image(image_id)
{
    stop_pictureshow();
    
    // the next thumb and picture to be selected
    NextActivePictureIndex = image_id+ScrollPos;//+FirstActivePictureIndex;
    
    WriteCounterFile(files[NextActivePictureIndex]);
    change(files[NextActivePictureIndex], thumbs[NextActivePictureIndex]);
}

function start_changing(id)
{
    id.style.borderColor = '#808080';
    id.style.borderStyle = 'solid';        id.style.borderWidth = '1px';
}

function stop_changing(id)
{
    id.style.borderColor = '#151515';
    id.style.borderStyle = 'solid';        id.style.borderWidth = '1px';
}

function change(image, small_image)
{
    if(NumPictures == 0)
        return 0;

    if(last_image == image)
        return 1;
        
    if(image != '')
    {
        last_image = image;
        last_small_image = small_image;
        FirstActivePictureIndex = NextActivePictureIndex;
        preLoad(image, 1);
        document.all.pic_name.innerHTML = '<font class=\"text\">'+image.substring(image.lastIndexOf('/')+1)+'</font>';
    }
    
    return 1;
}  

function show()
{
    window.setTimeout("fadeOut(\"thephoto\", 100, 0)", 0); // 500
    window.setTimeout("initImage()", 1000); // 1400
    window.setTimeout("fadeIn(\"thephoto\", 0)", 1500); // 1500
}

function initImage()
{
    //thephoto.src = "prepareimg.php?img="+last_image;
    thephoto.src = last_image;
    //document.getElementById("thephoto").style.visibility = "visible";
}

function addImage()
{
//var Fenster = window.open("", "Warenkorb");
//Fenster.location.href = 'overview.php?ImageName='+last_image+'&ImageSmallName='+last_small_image+'&action=add';
    this.location.href = 'overview.php?ImageName='+last_image+'&ImageSmallName='+last_small_image+'&action=add'+'&BitmapID='+FirstActivePictureIndex+'&ScrollPos='+ScrollPos; //(currentBitmapID-SelectedThumbID);
}

//http://www.web-toolbox.net/webtoolbox/bilder/images-vorladen.htm
function preLoad(next_image, bDisplay)
{
    var pic = new Image();
    pic.src = next_image;
    if(bDisplay == 0)
        return;
    pic.onload = show;
}

var aktiv = 0;
var pshowPos = 0;

function pause(mode)
{
    if(aktiv == 0)
        return;
    
    if(mode == 1)
    {
        window.clearInterval(aktiv);
        document.all.pause.innerHTML = '<blink><font color=red>stop</font></blink>';
    }
    else
    {
        aktiv = window.setInterval("pictureshow_displaypicture()", 4000);
        document.all.pause.innerHTML = '&nbsp;';
    }
}

function pictureshow_displaypicture()
{
    if(aktiv != 0)
    {
        window.clearInterval(aktiv);
        aktiv = 0;
    }
    
    pshowPos++;
    
    if(pshowPos > (NumPictures-1))
        pshowPos = 0;
        
    //preLoad(thumbs[picture], 0);
    change(files[pshowPos], thumbs[pshowPos]);
    aktiv = window.setInterval("pictureshow_displaypicture()", 4000);
}

function start_pictureshow()
{
    pshowbitmap.src = 'bitmaps/pictureshow_stop.jpg';
    pictureshow_displaypicture();
}

function stop_pictureshow_paused()
{
    pause(0);
    stop_pictureshow();
}

function stop_pictureshow()
{
    if(aktiv != 0)
    {
        pshowbitmap.src = 'bitmaps/pictureshow_start.jpg';
        window.clearInterval(aktiv);
        aktiv = 0;
        pshowPos = 0;
    }
}

function pictureshow()
{
//alert(aktiv);
    if(aktiv == 0)
        start_pictureshow();
    else
        stop_pictureshow();
}


/*
// onunload="GoodBye()"
function GoodBye()
{
  var Ende = new Date();
  var Endzeit = Ende.getTime();
  var Aufenthalt = Math.floor((Endzeit - Startzeit) / 1000);
  alert("Sie waren " + Aufenthalt + " Sekunden auf dieser Seite");
}
*/
-->

