/** Opacity code from http://www.brainerror.net/scripts_js_blendtrans.php **/
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(var i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(var 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 + ")";
} 

/* Banner cycling code */
function banner_fadeout() {
	opacity('image_banner', 100, 0, 500);
}

function banner_fadein() {
	opacity('image_banner', 0, 100, 500);
}

function banner_next() {
	id_image++;
	if (id_image == count_banners+1) {
		id_image = 1;
	}
	
	//Change image
	document.image_banner.src = eval("img_"+id_image+".src");
	document.image_banner.alt = eval("img_"+id_image+".src");
	
	//Change link
	//changeLinkHref("image_href", eval("img_"+id_image+"_url"), id_href);

	//Store old link for backwards compatibilty
	//id_href = eval("img_"+id_image+"_url");
}

function start_cycle() {
	banner_fadeout();
	setTimeout('banner_next()',600);
	setTimeout('banner_fadein()',900);
	setTimeout('start_cycle()',(banner_speed+750));
}

/** Link switchingode from http://www.irt.org/script/1747.htm **/
function findLinkByHref(href) {
	for (var i=0; i<document.links.length; i++) {
		if (document.links[i].href == href) return i;
	}
	return -1;
}

function changeLinkHref(id, newHref, oldHref) {
	if (document.links.length > 0) {
		if (document.getElementById) {
			document.getElementById(id).href = newHref;
		} else if (document.all) {
			document.all[id].href = newHref;
		} else {
			var index = findLinkByHref(oldHref);
			if (index > -1) {
				document.links[index].href = newHref;
			}
		}
	}
}
