/******************************************************************
 * This function will handle the checkboxes that control the overlays.
 ******************************************************************
 * section with variables that can be changed
 ******************************************************************/
//transition time
transTime = 200;
/******************************************************************/
function overlayCtrl(passedNum, totalLen, imageName, defaultImage){	
	if(totalLen == 1 ){
		if(document.junk.overlay.checked){
			blendimage('blenddiv','blendimage',imageName,transTime);
		}
		else{
			blendimage('blenddiv','blendimage',defaultImage,transTime);
		}
		return true;
	}
	for(j =0; j < totalLen; j++){
		if(j == passedNum){
			//display this image if checkbox is checked
			if(document.junk.overlay[j].checked){
				blendimage('blenddiv','blendimage',imageName,transTime);
			}
			else{
				//show default image
				blendimage('blenddiv','blendimage',defaultImage,transTime);				
			}			
		}
		else{
			//uncheck all other check boxes
			document.junk.overlay[j].checked = false;			
		}			
	}
}
/*****************************************************/
// This function will let us pull information from the url
/*****************************************************/
function sortUrl(){
	course = '';
	// sets the variable 'text' to whatever is in the url after the '?' sign
	var text = window.location.search.substring(1);	
	// if the variable 'text' is blank or empty then set the variable 'course' to equal the default course 'path'		
	if(text == ""){
		course = "path";
	}
	// if the variable 'text' equals "curpage=about_medpics" then set the value of 'course' to equal 'about'
	else if(text == "curpage=about_medpics"){
		course = "about";
	}
	// if the variable 'text' equals "curpage=credits" then set the value of 'course' to equal 'credits'
	else if(text ==  "curpage=credits"){
		course = "credits";
	}	
	// otherwise, parse through the value of 'text' looking for 'course=something'
	else{
		//set the variable 'course' to equal the part of the url that looks like, '&course=something'
		course = text.match(/&course\=[a-zA-z]+/i);
		//okay ... now we have the '&course=something', so now lets remove the '&course=' part
		course = course[0].replace(/&course\=/,"");
	}
	return course;
}
/********************************************/
// The script below handles the image transitions
/********************************************/
// This javascript below was found at the following location:
// http://www.brainerror.net/scripts_js_blendtrans.php
//  http://www.brainerror.net/media/scripts/js/blendtrans/blendtrans.js?
/********************************************/
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 200);
	var timer = 0;
	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		//alert("bring it back - out of for");
		for(i = opacStart; i <= opacEnd; i++)
		{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}else{}
}
//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 + ")";
}
function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} 
	else {
		opacity(id, 100, 0, millisec);
	}
}
function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 100;	
	//set the new image as background	
	document.getElementById(divid).style.backgroundImage = "url(" + imagefile  + ")";
	//make image transparent
	changeOpac(0, imageid);			
	//make new image		
	document.getElementById(imageid).src = imagefile;
	changeOpac(100, imageid);	
	timer = 0;
}
function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}
	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}


