/*
fade in/out quote text
*/

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 ******************************************************* */

var fader = new Array();

var hash = new Array();
function throb(item) {
  if (!hash[item]) hash[item] = 2;
  fader[item].fade(Math.floor(hash[item] / 2), !(hash[item] % 2));
  setTimeout(function() { throb(item); }, (hash[item] % 2) ? 1000 : 10000);
  if (++hash[item] > fader[item].msg.length * 2 - 1) hash[item] = 2;
}

fader[2] = new fadeObject('fade2', 'ffffff', '5484c0', 30, 30);

fader[2].msg[1] = "<strong>&nbsp;</strong> backpack online is user friendly. Training new staff is easy and... Overall it is a very good system.  <em>&nbsp;</em> <a href='http://www.hostelnapoli.com' target='_new'>Hostel Of The Sun, Naples</a>";
fader[2].msg[2] = "<strong>&nbsp;</strong> backpack online proved to be fully functional tool allowing one property check availability & make bookings in our other property. <em>&nbsp;</em> <a href='http://www.mamashostel.com.pl' target='_new'>Mama's Hostels, Krakow</a>";
fader[2].msg[3] = "<strong>&nbsp;</strong> I love it. It enables me to manipulate occupancy and prices in a matter of seconds and those changes go out to the market immediately <em>&nbsp;</em> <a href='http://www.palmerslodge.co.uk' target='_new'>Palmers Lodge, London</a>";
fader[2].msg[4] = "<strong>&nbsp;</strong> I think backpack online is easy to use.  The staff find it better for checking people in and our online bookings have increased. <em>&nbsp;</em> <a href='http://www.marlboroughhostel.com' target='_new'>Marlborough Hostel, Dublin</a>";
fader[2].msg[5] = "<strong>&nbsp;</strong> Well may I be the first of what will no doubt be thousands of managers to say.....WOW! The system is amazing. <em>&nbsp;</em> <a href='http://www.hostelsaccommodation.com' target='_new'>Cowgate Hostels, Scotland</a>";
fader[2].msg[6] = "<strong>&nbsp;</strong> I really like backpack online, it has changed how we work in a very positive way, Thanks a lot. <em>&nbsp;</em> <a href='http://www.picassoscorner.com' target='_new'>Picasso's Corner Backpackers, Malaga</a>";
fader[2].msg[7] = "<strong>&nbsp;</strong> Our work has become more efficient the reports are very useful for our daily, monthly & yearly   organisation. We  really recommend  backpack online. <em>&nbsp;</em> <a href='http://www.losamigoshostel.com' target='_new'>Los Amigo Backpackers, Madrid</a>";
fader[2].msg[8] = "<strong>&nbsp;</strong> It saves me hours of work every month as occupancy and income analysis is all there, in the system. <em>&nbsp;</em> <a href='http://www.mamashostel.com.pl' target='_new'>Mama's Hostels, Krakow</a>";
fader[2].msg[9] = "<strong>&nbsp;</strong> backpack online has been a great tool for our business. It easy to work with, maximizing our availability on line, so we're always full to capacity<em>&nbsp;</em> <a href='http://www.villageinnhostel.com' target='_new'>Village Inn, New York</a>";
fader[2].msg[10] = "<strong>&nbsp;</strong> backpack online has removed all the stress from our bed management  so I can concentrate on  getting the best yield possible. <em>&nbsp;</em> <a href='http://www.palmerslodge.co.uk' target='_new'>Palmers Lodge, London</a>";
fader[2].msg[11] = "<strong>&nbsp;</strong> backpack online decreases a lot the stress in the life of any Hostel manager! Its easy to use, fast and very complete. <em>&nbsp;</em> <a href='http://www.lisbonoldtownhostel.com' target='_new'>Lisbon Old Town Hostel</a>";

// Start this fader
setTimeout(function() { throb(2); }, 1000);
