/*
** blend.js 
** (c) 2007 ASCON Group
** javascript for image blending
**
** based on: http://brainerror.net/scripts/javascript/blendtrans/
**
** !!! 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 = 2;// how many images?
** 
** 2) function startBlend() must be started in body tag
**    e.g.
**    <body onLoad="JavaScript:if (blend_sum > 1) startBlend();">
*/ 

// var blend_counter = 1; // definition commented, starting with random image

// Set the slideshow speed (in milliseconds)
var SlideShowSpeed = 10 * 1000;

// Set the duration of crossfade (in seconds)
var CrossFadeDuration = 5;

// start timer
function startBlend()	{
	setInterval("changeBlend()", SlideShowSpeed);
}

// function for changing images
function changeBlend()	{
	if (blend_sum > 0) { // if some illustrations exists
    if (blend_counter < blend_sum){
			blend_counter++;
		} else {
			blend_counter = 1;
		}
		
		blendimage("div_blend", "img_blend", OBlendImg[blend_counter].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 + ")"; 
} 
