// need a timer on-load to run the pics endlessly
// <a href="javascript:shiftOpacity('digicam2', 1000)">show/hide</a>
// onload="javascript:beginTransform();"
var browser = navigator.appName; //find the browser name
var versionb = navigator.appVersion;
var version = parseFloat(versionb);
var chfun = 0; // there are 10 words
function beginTransform()
{
   // infinite loop
   
   //if(browser == "Microsoft Internet Explorer"){
   //   setTimeout("inline('names')",3000);
   //}else
   //{
      inline('names');
   //}
  //alert(version);
// if(browser == "Microsoft Internet Explorer" && !window.XMLHttpRequest)
 //   {
  //    var d = document.getElementById('names');
   //   d.style.opacity = 1;
    //  d.style.color="#000";
     // d.innerHTML = "Upgrade to <a //href='http://www.microsoft.com/windows/products/winfamily/ie/default.mspx'> IE //7</a>";
//      d.style.top = "170px";
//      d.style.left = "0px;";
//   }else
 //  {
      func(0);
//   }   
  
}

function inline(doc)
{
   var d = document.getElementById(doc);
   d.style.display = "inline";
}

function func(x)
{
   // id always the same - change location and text
   var doc = document.getElementById("names");
   var n="";
   if(browser == "Microsoft Internet Explorer"){
      shiftOpacity('names', 1000);
   }
   switch(x)
   {
      case 0:
         n = "patience";
         break;
      case 1:
         n = "strength";   
         break;
      case 2:
         n = "courage";
         break;
      case 3:
         n = "perseverance";
         break;
      case 4:
         n = "potential";
         break;
      case 5:
         n = "compassion";
         break;
      case 6:
         n = "respect";
         break;
      case 7:
         n = "effort";
         break;
      case 8:
         n = "believe";
         break;
      case 9:
         n = "community";
         break;
      default:
         n = "patience";
         x = 0;
         break;
   }
   doc.innerHTML = n;
   // random spot
   // left / top
   var rnd = Math.random(); // what is the range?
   doc.style.left = (Math.round(rnd*50)+50)+"px";
   rnd = Math.random(); // what is the range?
   doc.style.top = (Math.round(rnd*75)+125)+"px";
   rnd = Math.random();
   doc.style.fontSize = ((rnd*20)+24)+"px";
   // if mozilla
   if(browser == "Microsoft Internet Explorer"){
      	
         //setTimeout("shiftOpacity('names',1000)",1000);
      setTimeout("func("+(x+1)+")", 5000);
      setTimeout("shiftOpacity('names',1000)",8000);
      
   }else{
      shiftOpacity('names', 1000);
      setTimeout("shiftOpacity('names',1000)",3000);
      setTimeout("func("+(x+1)+")", 5000);
   }
}

function func2(x)
{
   // id always the same - change location and text
   //shiftOpacity('names', 1000);
   //setTimeout("func("+x+")", 2000);
   
}

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(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(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 + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity < 1) {
		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 = 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++;
	}
}

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)
}
