// Opacity and Fade in script.
// Script copyright (C) 2008 http://www.cryer.co.uk/.
// Script is free to use provided this copyright header is included.
// ### ALTERED & ADJUSTED in 2010 for use in this site by rb@bertosweb.com ###

function SetOpacity(object,opacityPct) {
	// IE.
	object.style.filter = 'alpha(opacity=' + opacityPct + ')';
	// Old mozilla and firefox
	object.style.MozOpacity = opacityPct/100;
	// Everything else.
	object.style.opacity = opacityPct/100;
}

function ChangeOpacity(elname,msDuration,msStart,fromO,toO) {
	var element = gObj(elname);
	var opacity = element.style.opacity * 100;
	var msNow = (new Date()).getTime();
	opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
	if (opacity <= 0) {
		SetOpacity(element,0);
		if (element.timer) window.clearTimeout(element.timer);
		if (elname == 'slide_txt') {
			element.innerHTML = msgArray[j];
			element.timer = window.setTimeout("ChangeOpacity('" + elname + "'," + msDuration + "," + (msStart+msDuration+1) + "," + toO + "," + fromO + ")",1);
		}
	} else if (opacity >= 100) {
		SetOpacity(element,100);
		if (element.style.removeAttribute) element.style.removeAttribute('filter');
		if (element.timer) window.clearTimeout(element.timer);
	} else {
		SetOpacity(element,opacity);
		element.timer = window.setTimeout("ChangeOpacity('" + elname + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",1);
	}
}

function FadeInImage(foregroundID,newImageURL,backgroundID,nm) {
	if (t) window.clearTimeout(t);
	var foreground = gObj(foregroundID);
	if (backgroundID)
	{
		var background = gObj(backgroundID);
		if (background)
		{
			background.style.background = 'transparent url(' + foreground.src + ') left top no-repeat';
		}
	}
	SetOpacity(foreground,0);
	foreground.src = newImageURL;
	if (foreground.timer) window.clearTimeout(foreground.timer); 
	var startMS = (new Date()).getTime();
	foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "',crossFadeDuration," + startMS + ",0,100)",1);
	t = setTimeout('runSlideShow()', slideShowSpeed);
	j = nm;
	
	chCaption();
	circleOff();
}

function runSlideShow() {
	j = j + 1;
	if (j > (p - 1)) j = 0;
	t = setTimeout("FadeInImage('SlideShow','" + preLoad[j].src + "','" + slideShowID + "'," + j + ")", slideShowSpeed);
}

function chCaption() {
	var caption = gObj('slide_txt');
	if (caption.timer1) window.clearTimeout(caption.timer1);
	var startMS = (new Date()).getTime();
	var capDuration = parseInt(crossFadeDuration/4);
	caption.timer1 = window.setTimeout("ChangeOpacity('slide_txt'," + capDuration + "," + (startMS+1) + ",100,0)",1);
}

function mvCir(fb) {
	if (fb == 'fwd') {
		j = j + 1;
		if (j > (p - 1)) j = 0;
	} else {
		j = j - 1;
		if (j < 0) j = p - 1;
	}
	FadeInImage('SlideShow',preLoad[j].src,slideShowID,j);
}

function circleOn(cid) {
	gObj(cid).className = "circle_link_on";
}

function circleOff() {
	var k;
	for (k = 0; k < 6; k++) {
		cid = "c_link_" + k;
		if (k === j) {
			gObj(cid).className = "circle_link_on";
		} else {
			gObj(cid).className = "circle_link_off";		
		}
	}	
}

