/**********************************************************************
***********************************************************************
***    Copyright by Frank Mühlschlegel, Bonn, Germany               ***
***********************************************************************
**********************************************************************/

/**********************************************************************
***    für das Wechseln & Überblenden der Kopfbilder                ***
**********************************************************************/


var pic_timer;	
var pic_data = new Array();
var pic_max = 0;
var pic_act_nr = 0;
var pic_id_next_new = "kopfbild_placeB"; 
var pic_id_old = "kopfbild_placeA";       
var pic_duration = 8000;

var fader_timer;
var fade_from_pic_id;
var fade_to_pic_id;
var fade_duration;
var fade_level;
var fade_step = 2;
var fade_duration = 3000;

function InitHeadPicture(_numpictures) {
    pic_max = _numpictures-1;
    pic_data = new Array(pic_max);
    pic_act_nr = Math.round(Math.random()*pic_max);
}
function AddHeadPicture(num,path){
    pic_data[num]=path;
}

function StartHeadPicture() {
    document.getElementById(pic_id_old).setAttribute("src",pic_data[pic_act_nr]);
	document.getElementById(pic_id_next_new).setAttribute("src",pic_data[pic_act_nr]);
	set_visibility(pic_id_next_new,false);
    pic_timer = window.setInterval("ChangePicture()", pic_duration + fade_duration); // We habe to wait till fader finished

}
function ChangePicture(){
    pic_act_nr = pic_act_nr + 1;
	if (pic_act_nr > pic_max ) { pic_act_nr=0 }
			
	document.getElementById(pic_id_next_new).setAttribute("src",pic_data[pic_act_nr]);
	fade(pic_id_old,pic_id_next_new);
		
			
	var temp_id = pic_id_old;
	pic_id_old = pic_id_next_new;
	pic_id_next_new = temp_id;

}


function fade(_from_pic_id,_to_pic_id){
    fade_from_pic_id = _from_pic_id;
    fade_to_pic_id = _to_pic_id;
    fade_level = 0;
    set_opac(fade_to_pic_id,0);
    set_visibility(fade_to_pic_id,true);
    fader_timer = window.setInterval("makeFadeStep()", fade_duration/(100/fade_step));
 }

function makeFadeStep(){
    fade_level += fade_step;
    set_opac(fade_from_pic_id,100-fade_level);
    set_opac(fade_to_pic_id,fade_level);
    if (fade_level>=100) {
        window.clearInterval(fader_timer);
        set_visibility(fade_from_pic_id,false);
    }
        
}

function set_opac(pic_id,level){
    document.getElementById(pic_id).style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+level+")"; // IE 5.5 +
    document.getElementById(pic_id).style.MozOpacity=level/100; // Mozilla & Firefox
    document.getElementById(pic_id).style.KhtmlOpacity=level/100; // KBrowser (Linux)
    document.getElementById(pic_id).style.opacity=level/100; // Sonstige
}

function set_visibility(pic_id,isVisible){
    if (isVisible==true) {
        document.getElementById(pic_id).style.display = "block";
    }
    else {
       document.getElementById(pic_id).style.display = "none";
    }
}