<!--

n = 0;
t = 0;

posi =5;

function endsWith(str, s){
	var reg = new RegExp (s + "$");
	return reg.test(str);
}

function pausecomp(millis) {
    var date = new Date();
    var curDate = null;

    do { curDate = new Date(); }
    while(curDate-date < millis);
} 

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
} 

function blendimage(divid, imagefile, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;
    			
    //set the current image as background
    //document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";

	//make image transparent
    
    //make new image
    //document.getElementById(divid).src = imagefile1;	
	
    //fade in image
    for(i = 0; i <= 100; i++) {
        setTimeout("changeOpac(" + i + ",'" + divid + "')",(timer * speed));
        timer++;
	}
		
	changeOpac(0, divid);
	//document.getElementById(divid).style.backgroundImage = "url(" + imagefile + ")";
	document.images[divid].src = imagefile;
}

function startSS(){
	t = setTimeout("runSS(" + posi + ")", 1 * 1);
}

function runSS(n){
	n++;
	if(n >= SLIDES.length){
		n = 0;
	}
					
 	blendimage('stage', S[n].src, 1000);
	
	//update link	
	//document.getElementById("view_gallery").href = S1[posi][1]
	//document.images["stage"].src = S[n].src;
		
	//var inputElement1 = document.getElementById('imageselected')
	//inputElement1.innerHTML = n+1;

	posi = n;
		
	//Update display possition
	//span.text = pos of SLIDES.length
  
	var inputElement1 = document.getElementById('imageselected')
	inputElement1.innerHTML = (posi+1) +" of "+ SLIDES.length;
             
    //Detect '/EN/' '/DE/' '/ZHS/' location
    var langPos=0;
    if(SLIDES[n][1].indexOf("/EN/") > -1)
    {
        langPos = SLIDES[n][1].indexOf("/EN/");
    }
    else if(SLIDES[n][1].indexOf("/DE/") > -1)
    {
        langPos = SLIDES[n][1].indexOf("/DE/");
    }
    else if(SLIDES[n][1].indexOf("/ZHS/") > -1)
    {
        langPos = SLIDES[n][1].indexOf("/ZHS/");
    }
                                                               
    if(endsWith(location,"SubGallery") || endsWith(location,"SubGallery.htm"))
    {
	    document.getElementById("view_gallery").href = SLIDES[n][1].substr(langPos);
    }
    else
    {
        if(endsWith(SLIDES[n][1],"htm"))
        {
            document.getElementById("view_gallery").href = SLIDES[n][1].substr(langPos);
        }
        else
        {
            document.getElementById("view_gallery").href = SLIDES[n][1].substr(langPos)+"SubGallery.htm";
        }
        
    }
    
	//f.wichIm[n].selected = true;
	t = setTimeout("runSS(" + posi + ")", display * 1000);
}

function stopSS(){
	if(t){
		t = clearTimeout(t);
	}
}

function nextSS(){
	stopSS();
	n = posi;
	n++;
	if(n >= SLIDES.length){
		n = 0;
	}
	
	if(n < 0){
		n = SLIDES.length - 1;
	}
				
	document.images["stage"].src = S[n].src;
	posi = n;
	
	var inputElement1 = document.getElementById('imageselected')
	inputElement1.innerHTML = (posi+1) +" of "+ SLIDES.length;

    //Detect '/EN/' '/DE/' '/ZHS/' location
    var langPos=0;
    if(SLIDES[n][1].indexOf("/EN/") > -1)
    {
        langPos = SLIDES[n][1].indexOf("/EN/");
    }
    else if(SLIDES[n][1].indexOf("/DE/") > -1)
    {
        langPos = SLIDES[n][1].indexOf("/DE/");
    }
    else if(SLIDES[n][1].indexOf("/ZHS/") > -1)
    {
        langPos = SLIDES[n][1].indexOf("/ZHS/");
    }

    if(endsWith(location,"SubGallery") || endsWith(location,"SubGallery.htm"))
    {
	    document.getElementById("view_gallery").href = SLIDES[n][1].substr(langPos);
    }
    else
    {
        if(endsWith(SLIDES[n][1],"htm"))
        {
            document.getElementById("view_gallery").href = SLIDES[n][1].substr(langPos);
        }
        else
        {
            document.getElementById("view_gallery").href = SLIDES[n][1].substr(langPos)+"SubGallery.htm";
        }
        
    }
}

function prevSS(){
	stopSS();
	n = posi;
	n--;
	if(n >= SLIDES.length){
		n = 0;
	}
	if(n < 0){
		n = SLIDES.length - 1;
	}
			
	document.images["stage"].src = S[n].src;
	posi = n;
	
	var inputElement1 = document.getElementById('imageselected')
	inputElement1.innerHTML = (posi+1) +" of "+ SLIDES.length;
	
	//Detect '/EN/' '/DE/' '/ZHS/' location
    var langPos=0;
    if(SLIDES[n][1].indexOf("/EN/") > -1)
    {
        langPos = SLIDES[n][1].indexOf("/EN/");
    }
    else if(SLIDES[n][1].indexOf("/DE/") > -1)
    {
        langPos = SLIDES[n][1].indexOf("/DE/");
    }
    else if(SLIDES[n][1].indexOf("/ZHS/") > -1)
    {
        langPos = SLIDES[n][1].indexOf("/ZHS/");
    }
    
    if(endsWith(location,"SubGallery") || endsWith(location,"SubGallery.htm"))
    {
	    document.getElementById("view_gallery").href = SLIDES[n][1].substr(langPos);
    }
    else
    {
        if(endsWith(SLIDES[n][1],"htm"))
        {
            document.getElementById("view_gallery").href = SLIDES[n][1].substr(langPos);
        }
        else
        {
            document.getElementById("view_gallery").href = SLIDES[n][1].substr(langPos)+"SubGallery.htm";
        }
        
    }
}
// -->
