/* ***** Begin ***************************************************** */

function fadeObject(id, c1, c2, s1, s2) {
  var self = this;
  this.id      = id;
  this.elem    = false;
  this.colour  = {
    stt: [parseInt(c1.substr(0, 2), 16), parseInt(c1.substr(2, 2), 16), parseInt(c1.substr(4, 2), 16)],
    end: [parseInt(c2.substr(0, 2), 16), parseInt(c2.substr(2, 2), 16), parseInt(c2.substr(4, 2), 16)],
    now: [parseInt(c1.substr(0, 2), 16), parseInt(c1.substr(2, 2), 16), parseInt(c1.substr(4, 2), 16)]
  };
  this.steps   = [s1, s2];
  this.dir     = false;
  this.active  = false;
  this.queue   = [];
  this.msg     = [];
  this.message = 0;
  function d2h(num) {
    num = Math.round(num);
    return ((num < 16) ? "0" : "") + num.toString(16);
  }
  this.fade = function(message, direction) {
    this.elem = this.elem || document.getElementById(this.id);
    this.queue.push([message, direction]);
    for (var x = 0; x < this.queue.length; x++) {
      for (var y = x + 1; y < this.queue.length; y++) {
        if (this.queue[x][0] == this.queue[y][0] && this.queue[x][1] != this.queue[y][1]) {
          this.queue.splice(x, 1);
          this.queue.splice(y - 1, 1);
        }
      }
    }
    if (!this.active) setTimeout(function() { self.fadeLoop(); }, 0);
  };
  this.fadeLoop = function() {
    if (!this.active && this.queue.length) {
      if (this.dir && this.message != this.queue[0][0]) this.queue.unshift([this.message, false]);
      var msg = this.queue.shift();
      if (this.msg[msg[0]]) {
        this.active = true;
        this.elem.innerHTML = this.msg[this.message = msg[0]];
        this.dir = msg[1];
      }
    }
    if (this.dir) {
      var c1 = this.colour.stt, c2 = this.colour.end, s = this.steps[0];
    } else var c1 = this.colour.end, c2 = this.colour.stt, s = this.steps[1];
    for (var x = 0, cnow = "", inc = 0; x < 3; x++) {
      this.colour.now[x] += inc = (c2[x] - c1[x]) / s;
      cnow += this.colour.now[x] = (inc < 0) ? Math.max(this.colour.now[x], c2[x]) : Math.min(this.colour.now[x], c2[x]);
    } this.elem.style.color = "#" + d2h(this.colour.now[0]) + d2h(this.colour.now[1]) + d2h(this.colour.now[2]);
    if (cnow == c2.join("")) {
      this.active = false;
      if (!this.queue.length) {
        if (!this.dir) {
          if (this.msg[0]) {
            this.queue.push([0, true]);
            setTimeout(function() { self.fadeLoop(); }, 0);
          } else this.elem.innerHTML = "&nbsp;";
        }
      } else setTimeout(function() { self.fadeLoop(); }, 0);
    } else setTimeout(function() { self.fadeLoop(); }, 0);
  };
  if (window.addEventListener) {
    window.addEventListener('load', function() { self.fade(0, true); }, false); 
  } else if (window.attachEvent)
    window.attachEvent('onload', function() { self.fade(0, true); });
}
/* ***** End ******************************************************* */

/* *****
 * User defined fade objects and messages
 *
 * These messages are used in fades triggered by mouseovers and
 * mouseouts on table cells.  They are the simplest type of fade and
 * require no extra Javascript code.
 */
var fader = new Array();


fader[0] = new fadeObject('scrollingtext', '535353', 'ffffff', 20, 20);
fader[0].msg[1] = "Discover fast pain relief";
fader[0].msg[2] = "Affordable expertise from caring staff";
fader[0].msg[3] = "Hands on, personalized care";
fader[0].msg[4] = "Healing injuries to get you back to your game";
fader[0].msg[5] = "Proven methods to relieve pain";
fader[0].msg[6] = "Helping you live, work, and play again!";




/* *****
 * The code below describes how to make a throbbing or automatic fade
 * sequence of messages.  It is important to note that this function is
 * NOT part of the Buffered Text-Fade Effect, but merely an example of
 * how it can be used.  In this example, the throb() function controls
 * the commands which are sent to the fade engine; it is called
 * repeatedly at set time intervals rather than using mouseover events
 * as triggers.
 *
 * Notes:
 * - A global array "hash" is used to keep track of where each
 *   animation is currently in the sequence.
 * - The list of messages defined in the fader *must* start at one (1)
 *   and count upwards without skipping any integers.
 * - The third line of the throb() function controls how fast
 *   commands get sent to the fade engine.  It waits only 100 milli-
 *   seconds when fading out, but 5000 milliseconds (5 seconds) when
 *   fading in; this means the message will remain visible for about 5
 *   seconds before fading out again.
 *
 * Other types of fade animation are possible simply by designing
 * different ways to control the fade-ins and fade-outs!
 */
var hash = new Array();
function throb(item) {

  // If the hash array does not have an entry for this item, initialise it at 2
  if (!hash[item])
  	hash[item] = 2;

  // Send a fade command using the hash array to tell us what parameters we should use
  fader[item].fade(Math.floor(hash[item] / 2), !(hash[item] % 2));

  setTimeout(function() { throb(item); }, (hash[item] % 2) ? 100 : 3500);
  	
  // If we have exceeded the number of messages in this fader, start over again at 2
  if (++hash[item] > fader[item].msg.length * 2 - 1) {
  	hash[item] = 2;
  }
}

// Start this fader
setTimeout(function() { throb(0); }, 1000);


/*****************************************
* Dissolving Image Rollover- By Roy Whittle (http://www.javascript-fx.com/)
* Featured on/available at http://www.dynamicdrive.com/
* This notice must stay intact for use
*****************************************

var onImages=new Array();
function Rollover(imgName, imgSrc)
{
	onImages[imgName] = new Image();
	onImages[imgName].src = imgSrc;
}

function turnOn(imgName){ 
	if(document.images[imgName].filters != null)
		document.images[imgName].filters[0].apply();
	document.images[imgName].offSrc = document.images[imgName].src;
	document.images[imgName].src    = onImages[imgName].src;
	if(document.images[imgName].filters != null)
		document.images[imgName].filters[0].play();
}

function turnOff(imgName){ 
	if(document.images[imgName].filters != null)
		document.images[imgName].filters[0].stop();
	document.images[imgName].src = document.images[imgName].offSrc;
}

//Specify name of participating images, plus paths to their onMouseover replacements:
Rollover("Image10", "/images/live.jpg");
Rollover("Image11", "/images/work.jpg");
Rollover("Image1011", "/images/play.jpg");
Rollover("mom_and_kid", "/images/mom_and_kid3.jpg");
Rollover("worker", "/images/worker3.jpg");
Rollover("basketball", "/images/basketball3.jpg"); */



var Pics = new Array();
var Index = 0;
var Index1 = 0;
var totalPics = 0;

function MM_preloadImages() { //v3.0
  var d=document;
  if(d.images){
  	if(!d.MM_p)
  		d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
    
    for(i=0; i<a.length; i++)
    	if (a[i].indexOf("#")!=0){
    		d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
    	}
   }
}

//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 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);

    //fade in image.  This needs to be delayed because otherwise Firefox can flicker on the fades
    setTimeout("blendLoop('" + imagefile + "','" +imageid + "', " + speed + ")",100);
}

function blendLoop(bl_imagefile, bl_imageid, bl_speed) {
	var lclTimer = 0;

    //make new image
    document.getElementById(bl_imageid).src = bl_imagefile;
	
	//fade in image
    for(i = 0; i < 100; i++) {
        setTimeout("changeOpac(" + i + ",'" + bl_imageid + "')",(lclTimer* bl_speed));
        lclTimer++;
    }
}

function fadeOut(fo_imageid, fo_millisec) {
	var fo_speed = Math.round(fo_millisec / 100);
	var fo_timer = 0;
	
	//fade the image out
	for(i = 99; i >= 0; i--) {
		setTimeout("changeOpac(" + i + ",'" + fo_imageid + "')",(fo_timer*fo_speed));
		fo_timer++;
	}
}

function fadeIn(fi_imageid, fi_millisec) {
	var fi_speed = Math.round(fi_millisec / 100);
	var fi_timer = 0;
	
	//fade the image in
	for(i = 0; i < 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + fi_imageid + "')",(fi_timer*fi_speed));
		fi_timer++;
	}
}

function FadeImages()
{
	var a = FadeImages.arguments;
	
	for(var i = 0; i<a.length; i++)
	{
		Pics[i] = new Image();
		Pics[i].src = "/images/" + a[i];
		totalPics++;
	}
	
	// Only do this if pictures were passed in
	if( a.length>0 )
		var Timer = setInterval("Animate()", 4000);
}

function FadeImages2()
{
	var a = FadeImages2.arguments;
	
	for(var i = 0; i<a.length; i++)
	{
		Pics[i] = new Image();
		Pics[i].src = "/images/" + a[i];
		totalPics++;
	}
	
	// Only do this if pictures were passed in
	if( a.length>0 )
		var Timer = setInterval("Animate2()", 4000);
}

function Animate()
{
  var object = document.getElementById(Index1).style;
  object.fontSize = '14px';
  object.fontWeight = 'normal';
  object.textDecoration = 'none';

  Index1++;
  if (Index1 >= totalPics) {
    Index1 = 0;
  }
  var newImage = new Image();
  newImage.src = Pics[Index1].src;
  
  object = document.getElementById(Index1).style;
  object.fontSize = '18px';
  object.fontWeight = 'bold';
  object.textDecoration = 'underline';

  blendimage('blenddiv','blendimage', newImage.src, 750)
}

function Animate2()
{
  Index1++;
  if (Index1 >= totalPics) {
    Index1 = 0;
  }
  
  var newImage = new Image();
  newImage.src = Pics[Index1].src;

  blendimage('blenddiv','blendimage', newImage.src, 750)
}

function popvid( url ) {
	newwindow=window.open(url,'videoPopup','height=200,width=200,resizable=false,toolbar=false,menubar=false,location=false');
	if (window.focus) {newwindow.focus()}

}

function clear( theSel ) {
	for( i=0; i<theSel.length; i++ ) {
		theSel.options[i] = null;
	}
}

function populate( theSel, className ) {

}

var dateArray = new Array();

function addDateArray( classIndex, dateIndex, theDate ) {
	dateArray[classIndex][dateIndex] = theDate;
}
