var selected_image = 'thumb1';
var current_opac = 0;

function blendimage(divid, imageid, imagefile, millisec,id) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//for Idea Showcase
	if(id){
		//fix so the previous selected image no longer has the selected opacity 
		if(id != selected_image){
			chgOpac(70,selected_image);
			selected_image = id;
		}
		
		//also, lets set the text attributes based on file name
		var name = document.getElementById(id).src.substring(document.getElementById(id).src.lastIndexOf('/')+1,document.getElementById(id).src.length-4);
		var door;
		var sidelite;
		var transom;
		
		var count = 0;
		var pos = name.indexOf("_");
		while ( pos != -1 ) {
			count++;
			pos = name.indexOf("_",pos+1);
		}
		
		if(count == 0) {
			door = name.substring(0,name.length);
			sidelite = "NA";
			transom = "NA";	
		}else if(count == 1){
			door = name.substring(0,name.indexOf('_'));
			sidelite = name.substring(name.indexOf('_')+1,name.length);
			transom = "NA";	
		}else{
			door = name.substring(0,name.indexOf('_'));
			sidelite = name.substring(name.indexOf('_')+1,name.lastIndexOf('_'));
			transom =  name.substring(name.lastIndexOf('_')+1, name.length);
		}
				
		document.getElementById('dr').innerHTML = door;		
		document.getElementById('sl').innerHTML = sidelite;
		document.getElementById('tr').innerHTML = transom;
	}
	

	
	//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 = current_opac; i <= 100; i++) {
		current_opac = i;
		setTimeout("chgOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
	//if(current_opac==100) current_opac = 0;
	current_opac = 100 - current_opac;
}
//change the opacity for different browsers
function chgOpac(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 + ")";
}

//used to allow the selected thumb to stay at 100 opacity
function changeOpac(opacity, id){
	if(id != selected_image){
		chgOpac(opacity,id);
	}
}