/*
** blend.js 
** (c) 2004 ASCON Group. All rights reserved.
** javascript for image blending
**
** !!! R E A D M E !!!
** 1) Global variables "path" and "blend_sum" must be set in header:
**    e.g.
**    var path = "{$PATH_TEMPLATE}";
**    var blend_sum[i] = 2;// how many images?
** 
** 2) function startBlend() must be started in body tag
**    e.g.
**    <body onLoad="JavaScript:if (blend_sum[i] > 1) startBlend(i);">
*/ 

// var blend_counter = 1; // definition commented, starting with random image

// Set the slideshow speed (in milliseconds)
var SlideShowSpeed = 20 * 1000;

// Set the duration of crossfade (in seconds)
var CrossFadeDuration = 5;

// start timer
function startBlend(id)	{
	// setInterval("changeBlend("+id+")", SlideShowSpeed);
	// variable delay[id] is used to delay start of image rotation
	setTimeout("setInterval(\"changeBlend("+id+")\", "+SlideShowSpeed+")", delay[id]*1000);
}

// function for changing images
function changeBlend(id)	{
	// DEBUG: alert("changeBlend("+id+")");
	if (blend_sum[id] > 1) { // if some illustrations exists
    if (blend_counter[id] < blend_sum[id]){
			blend_counter[id]++;
		} else {
			blend_counter[id] = 1;
		}
		// alert ('id =' +id+ ', blend_counter=' + blend_counter[id] +', blend_sum=' + blend_sum[id]);
		
		div_element_name = "div_blend_" + id;
		img_element_name = "img_blend_" + id;
		ObjBlend = document.getElementById(img_element_name);
		
		bc_id = blend_counter[id];
		
		if (OBlendImg[id][bc_id]){
			blendimage (div_element_name, img_element_name, OBlendImg[id][bc_id].src, CrossFadeDuration*1000);
		}
	} // end of: if some illustrations exists
}

function blendimage(divid, imageid, 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
    changeOpac(0, imageid);
    
    //make new image
    document.getElementById(imageid).src = imagefile;

    //fade in image
    for(i = 0; i <= 100; i++) {
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(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 + ")"; 
}


