/* ********************************************************************
* Buffered Text-fade Effect - v3.0
* - Copyright 2008 - Licenced for free distribution under the BSDL
*   - http://www.opensource.org/licenses/bsd-license.php
*
*   This program is licenced under the BSDL and may be distributed far
* and wide, anywhere on the planet and beyond (maybe!)  If you happen
* to get a kick out of this script, please drop me a note at:
* wyvern@greywyvern.com and tell me where you gave it a good home and
* plenty of bytes to eat, hmmm? :)  I'd be eternally grateful.
*
* Description:
*   A javascript object which allows you to direct text fades within an
* HTML page.  Fades received before the previous fade has completed are
* queued rather than displayed immediately.  This keeps all fade
* animations smooth.
*
* Changelog:
*  3.0  - Buffer for each fadeObject is stored separately for stability
*         and speed.
*       - Major structure changes.  Different arguments
*
* Support:
*   Opera   - Yes
*   IE 6    - Yes
*   IE 5.5  - Yes
*   IE 5.01 - Fails
*   Firefox - Yes
*   Safari  - Yes
*
***********************************************************************
* I) Setting Up
*
*   Copy the javascript from this page into an external .js file or
* into the <script> tag of your own HTML page.  You only need the code
* between the "Begin" and "End" lines.  This shouldn't be that
* difficult, but you wouldn't believe the kind of mail I get about
* this!  Just do it, okay?  Jeez.
*
*   a) The Fade Object
*   After that's done we need to create a fade object.  We do this by
* calling the fadeObj function with a number of arguments.  We'll use
* the default example included in the script: fader[0].  You can delete
* the fader[1] lines if you like.
*
* fader[0] = new fadeObj('fade0', 'dddddd', '000000', 20, 20);
*
*   The first argument ('fade0') is the id of the HTML tag which will
* be displaying the fading effect.  Usually you'll want to apply some
* height and width styles to this element, since it starts out with no
* text by default and will probably be collapsed.  You don't want it
* jumping around when the script writes new text to it.
*
*   The next two values are hexidecimal colour values, WITHOUT the
* preceding #.  The first value is the starting colour, or the colour
* the text is before it fades in.  The second value is the ending
* colour, or the colour the text will be when it finishes fading in.
*
*   The last two values are two integers which indicate the number of
* "steps" the script must take to complete a fade-in and a fade-out
* respectively.  With a value of 20 like in the example above, there
* will be 20 colour changes before the text is fully faded-in or faded-
* out.  The lower these numbers, the faster the fade will be.
*
*   b) The Fade Messages
*   After setting up our fade object, all we need to do now is write
* out all of the messages which will be displayed in this element.
* Remember that this script only affects text of a single colour.
* Images and multi-coloured text won't work.
*
*   Messages are included in the msg[] array.  Simply assign each
* message a number, like so:
*
* fader[0].msg[1] = "Fade text, message one.";
*
*   Each fade object can have as many messages as you want, and be in
* any numerical order.  You can even skip numbers, but note that if you
* use the fade() method pointed at a message number which doesn't
* exist, you will get an error.
*
* The msg[] array should start at element [1].  If you would like a
* default message to appear if there are no more fade-in events in the
* queue, assign the default message to element [0].
*
***********************************************************************
* II) The Events
*
*   Fades can be triggered by any DOM event, but most likely you'll be
* using mouseover and mouseout events.  I used those events as examples
* below.
*
*   To trigger a fade, you use the fade() method to add a fade action
* to the queue.  The reason we use a queue, is so that you can add this
* fade, even if another fade is already happening.  The fade() method
* takes two important arguments:
*
* Example: onmouseover="fader[0].fade(1, true);"
*
*   In this example we are still referencing fade object fader[0].
*
*   The first argument is the message this command refers to.  This one
* has been associated with msg[1] of fader[0].
*
*   The second argument indicates the direction of the fade.
*     -> true = fade in, false = fade out.
*
*   Examine the working example script to see how these events were
* placed on the <td> elements below.
*
***********************************************************************
* III) Tips
*
*   - All the text in each msg[] variable MUST be on one line in the
* code.  That means this:
*
*   fader[0].msg[1] = "Fader zero,
* message one";
*
* ... is not allowed!  The text should wrap automatically when it's
* displayed on your HTML page, but you can force line breaks with the
* <br> tag.  (If you have some Javascript experience you'll know how to
* get around this).
*
*   - If you're placing the fading text on a background image, make
* the starting colour an average sample of the background instead of
* just black or white.  This will enhance the "disappearing" effect.
*
*   - The script can only fade text, but can accept non-graphical HTML
* tags in which CSS text color is inherited, such as <p>, <table> (no
* borders), <strong> and <em>.  Use these tags to add structure and a
* simple text layout to your fades.
*
*   - To have links fade along with with the surrounding text, apply
* the CSS style: color:inherit !important; to all links within the fade
* text messages.
*
***********************************************************************
* That's it!  Isn't that amazing!?! :)
*
* If you have any problems with this script, don't hesitate to email me
* at wyvern@greywyvern.com and I'll be happy to answer your matter-of-
* life-and-death questions!  Cheers!
******************************************************************** */


/* ***** 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('medDetails', 'F7FCE3', '000000', 20, 20);
fader[0].msg[1] = "<b>Acetazolamide</b> (Diamox)<br><br>Used to enhance certain other anti-epileptic drugs may also be used for menstrual related seizures and certain episodic disorders.<br><br><u>Possible side effects incl.</u>:<br>Weight loss, drowsiness, lack of appetite, pins and needles in hands and feet, depression, joint pains, thirst, increased urine output, headache, fatigue, irritability and dizziness.";
fader[0].msg[2] = "<b>Carbamazepine</b> (Tegretol, Tegretol Retard)<br><br>Effective against generalised tonic-clonic and partial seizures. May worsen myoclonic and absence seizures. Ineffective against absences.<br><br><u>Possible side effects incl.</u>:<br>Blurred vision, double vision, unsteadiness and nausea may occur initially or if the dose it too high. Skin rash if allergic to carbamazepine. Dizziness and headaches.";
fader[0].msg[3] = "<b>Clobazam</b> (Frisium)<br><br>Effective against generalised tonic-clonic and partial seizures, but tolerance develops in about one third of children.<br><br><u>Possible side effects incl.</u>:<br>Irritability, fatigue and depression. Drowsiness may occur although this medication is less sedating than clonazepam or diazepam.";
fader[0].msg[4] = "<b>Clonazepam</b> (Rivotril)<br><br>Effective against absences, generalised tonic-clonic and partial seizures, myoclonic seizures, Lennox-Gastaut syndrome, infantile spasms and status epilepticus.<br><br><u>Possible side effects incl.</u>:<br>Sedation and drowsiness are fairly common although these may wear off and tolerance (decline in effectiveness with time) tends to develop. Fatigue, aggression and overactive restlessness. Increased respiratory tract secretions.";
fader[0].msg[5] = "<b>Diazepam</b> (Stesolid, Diazepam Rectubes)<br><br>For emergency use only in status epilepticus.<br><br><u>Possible side effects incl.</u>:<br>Blurred vision, vertigo, amnesia, drowsiness and unsteadiness.";
fader[0].msg[6] = "<b>Ethosuximide</b> (Emeside, Zarontin)<br><br>Only effective against generalised absences.<br><br><u>Possible side effects incl.</u>:<br>Drowsiness, nausea, headache.";
fader[0].msg[7] = "<b>Gabapentin</b> (Neurontin)<br><br>Recommended for partial seizures, where previous treatment has been ineffective. May worsen myoclonic and/or absence seizures.<br><br><u>Possible side effects incl.</u>:<br>Dizziness, headache, double vision, fatigue, drowsiness, unsteadiness and shaky movements.";
fader[0].msg[8] = "<b>Lamotrigine</b> (Lamictal)<br><br>Effective against Lennox-Gastaut syndrome, absence, partial and generalised tonic-clonic seizures.<br><br><u>Possible side effects incl.</u>:<br>Skin rash particularly if rapid dose increase, if allergic to lamotrigine. Double vision, dizziness, drowsiness, headache and flu-like symptoms, if the dose is too high. Possibly insomnia.";
fader[0].msg[9] = "<b>Levetiracetam</b> (Keppra)<br><br>Currently not licensed for children under 16 years; refractory partial seizures. <br><br><u>Possible side effects incl.</u>:<br>Dizziness, nausea, behaviour change and sedation.";
fader[0].msg[10] = "<b>Nitrazepam</b><br><br>Infantile spasms. <br><br><u>Possible side effects incl.</u>:<br>Shaky movements, dependence, loss of memory, confusion, muscle weakness.";
fader[0].msg[11] = "<b>Oxcarbazepine</b> (Trileptal)<br><br>Generalised and partial seizures.<br><br><u>Possible side effects incl.</u>:<br>Skin rash if allergic to oxcarbazepine. Headache, nausea, double vision, unsteadiness and confusion.";
fader[0].msg[12] = "<b>Phenobarbitone</b><br><br>Effective against generalised partial and tonic-clonic seizures. Neonatal seizures and status epilepticus. <br><br><u>Possible side effects incl.</u>:<br>Drowsiness may occur initially, sedation and slowing of mental performance may persist. Listlessness, depression, fatigue, rash, tiredness, insomnia and irritability. Hyperactivity, aggression and subtle impairment of mood, memory and learning capacity.";
fader[0].msg[13] = "<b>Phenytoin</b> (Epanutin)<br><br>Effective against partial and generalised tonic-clonic seizures. Status epilepticus. Blood testing is essential when using phenytoin as the relationship between dose and blood level is complex.<br><br><u>Possible side effects incl.</u>:<br>Skin rash if allergic to phenytoin. Unsteadiness, drowsiness and slurred speech may occur if too high a dose is used. Coarsening of facial features, overgrowth of gums, acne and growth of excess hair may be problems with prolonged therapy, as can some anaemias (treated with folic acid). Unsteady gait, shaky movements, sedation and rapid involuntary movement of the eye.";
fader[0].msg[14] = "<b>Primidone</b> (Mysoline)<br><br>Effective against partial and generalised tonic-clonic seizures.<br><br><u>Possible side effects incl.</u>:<br>Tiredness, depression, listlessness, fatigue, psychosis, overactive restlessness and irritability.";
fader[0].msg[15] = "<b>Sodium Valproate</b> (Epilim, Epilim Chrono)<br><br>Effective against absences and generalised tonic-clonic and partial seizures.<br><br><u>Possible side effects incl.</u>:<br>Weight gain may occur with increased appetite. Hair loss occurs in some people but this is not usually severe and is usually reversible if the dosage is reduced. Gastric problems, hyperactivity and behaviour problems. Liver damage due to sodium valproate is very uncommon. The use of sodium valproate has been associated with increased incidence of polycystic ovaries and menstrual irregularities but needs to be evaluated further. Shaky movements and drowsiness are infrequent side effects.";
fader[0].msg[16] = "<b>Stiripentol</b><br><br>Improves the effectiveness of many other anticonvulsants and is indicated as an adjunctive therapy with sodium valproate and clobazam for treating severe myoclonic epilepsy in infancy (SMEI, also know as Dravet's syndrome).<br><br><u>Possible side effects incl.</u>:<br>Nausea and vomiting are particularly noted when used in combination with sodium valproate.";
fader[0].msg[17] = "<b>Tiagabine</b> (Gabitril)<br><br>May make myoclonic seizures worse. Recommended for partial seizures when previous treatment has been ineffective.<br><br><u>Possible side effects incl.</u>:<br>Tremor, concentration difficulties, dizziness, anxiety, depression, fatigue, agitation and jerkiness of limbs.";
fader[0].msg[18] = "<b>Topiramate</b> (Topamax)<br><br>Effective against severe myoclonic epilepsy in infancy. For children over 2 years of age. Recommended in partial and generalised seizures. <br><br><u>Possible side effects incl.</u>:<br>Pins and needles in hands and feet and loss of weight, headache, drowsiness. Increased risk of kidney stones. Slowing of mental performance and language may occur but minimised if dose started low and increased slowly. Cases of eye reactions have rarely been associated with topiramate occurring within one month of commencement of treatment.";
fader[0].msg[19] = "<b>Vigabatrin</b> (Sabril)<br><br>First line for infantile spasms. May worsen absences and myoclonic seizures. May be considered for resistant partial seizures if visual fields can be monitored.<br><br><u>Possible side effects incl.</u>:<br>Behaviour and mood changes, drowsiness, nausea. Visual field defects have been reported in one in three adults taking this drug in the long term. While taking vigabatrin visual fields should be measured every six months. Psychotic reactions have been reported.";
