﻿/*****************************************************************
/*      Copyright notice :
/*   Javascript class/functions notifier() and notifyWindow() created by and 
/*    copyright : www.cass-hacks.com
/*    Functions getWinHeight(), getWinWidth(), getScrollTop() and getScrollLeft()
/*    based on work published at http://www.quirksmode.org
/*
/*      Copyright notice :
/*   Script created by and copyright : www.cass-hacks.com
/*    This work is licensed according to the following Terms and Conditions :
/*    Copyright (c) 2007 & 2008 cass-hacks.com</p>
/*    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
/*    files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, 
/*    merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished 
/*    to do so, subject to the following conditions:
/*    1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
/*    2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer 
/*        in the documentation and/or other materials provided with the distribution, and in the same place and form as other copyright, 
/*        license and disclaimer information.
/*    3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product 
/*        includes software developed by Cass-hacks.com (http://cass-hacks.com/) and its contributors", in the same place and 
/*        form as other third-party acknowledgments. Alternately, this acknowledgment may appear in the software itself, in the same form 
/*        and location as other such third-party acknowledgments.
/*    4. Except as contained in this notice, the name of Cass-hacks.com shall not be used in advertising or otherwise to 
/*        promote the sale, use or other dealings in this Software without prior written authorization from Cass-hacks.com.
/*    
/*    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
/*    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
/*    DISCLAIMED. IN NO EVENT SHALL THE XFREE86 PROJECT, INC OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
/*    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
/*    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
/*    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
/*    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
/*    POSSIBILITY OF SUCH DAMAGE.
/*    
/*    If you find something on this site useful, please use the contact form to inform Cass-hacks of your application.  If need be, 
/*    modifications could be made to any of the code found on this site to more accurately fit a given application's needs and 
/*    requirements.
/*
******************************************************************/
function notifier () {
  var myWindows = new Array();
  
  this.display = display;
  this.kill = kill;
  
  function display (id,text) {
    wind = new notifyWindow();
    var thisWind = new Array();
    thisWind['id'] = id;
    thisWind['ptr'] = wind;
    wind.open(text);
    if (myWindows.length > 0) {
      wind.setPrev(myWindows[myWindows.length-1]['ptr']);
    } else {
      wind.setTop();
    }
    myWindows.push(thisWind);
  }
  
  function kill (id) {
    for (var x=0; x<myWindows.length; x++) {
      if (myWindows[x]['id'] == id) {
        myWindows[x]['ptr'].close();
        delete myWindows[x]['ptr'];
        myWindows.splice(x,1);
      }
    }
  }
}

function notifyWindow () {
  var myTarget = 0;
  var myNotify = null;
  var myPrev = null;
  var myNext = null;
  var scrollTop = getScrollTop();
  var scrollLeft = getScrollLeft();
  var winWidth = getWinWidth();
  var winHeight = getWinHeight();
  this.open = open;
  this.setPrev = setPrev;
  this.setNext = setNext;
  this.setTop = setTop;
  this.slideTop = slideTop;
  this.doSlide = doSlide;
  this.close = close;
  
  function open (text) {
    myNotify = document.createElement('div');
    myNotify.className = 'notifyContainer';
    myNotify.innerHTML = '<div class="notifyBody"><p>'+text+'</p></div>';
    document.getElementsByTagName('body')[0].appendChild(myNotify);
    myNotify.style.left = winWidth/2 + scrollLeft - myNotify.offsetWidth/2 + 'px';
  }
  function setPrev (prev) {
    myPrev = prev;
    if (myPrev != null)
      prev.setNext(this);
  }
  function setNext (next) {
    if (myNext == null && next != null)
      next.setTop(myNotify.offsetTop + myNotify.offsetHeight);
    else if (next != null)
      next.slideTop(myNotify.offsetTop + myNotify.offsetHeight);
    myNext = next;
  }
  function setTop (top) {
    if (top == null || top == '' || top == 'undefined') {
      top = winHeight/2 + scrollTop - myNotify.offsetHeight;
    }
    myNotify.style.top = top + 'px';
    myNotify.style.visibility = 'visible';
    if (myNext != null) {
      myNext.setTop(top + myNotify.offsetHeight);
    }
  }
  function slideTop (top) {
    myTarget = top;
    doSlide();
  }
  function doSlide () {
    if (myNotify.offsetTop > myTarget) {
      myNotify.style.top = myNotify.offsetTop - 2 + 'px';
      setTimeout(doSlide,25);
    } else {
      myNotify.style.top = myTarget + 'px';
    }
    if (myNext != null)
      myNext.setTop(myNotify.offsetTop + myNotify.offsetHeight);
  }
  function close () {
    if (myPrev != null && myNext != null) {
      myNext.setPrev(myPrev);
    } else if (myPrev != null) {
      myPrev.setNext(null);
    } else if (myNext != null) {
      myNext.slideTop(myNotify.offsetTop);
      myNext.setPrev(null);
    }
    myNotify.parentNode.removeChild(myNotify);
  }
}
function getWinHeight () {
  var y;
  if (self.innerHeight) { // all except Explorer
  	y = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) {	// Explorer 6 Strict Mode
  	y = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
  	y = document.body.clientHeight;
  }
  return y;
}
function getWinWidth () {
  var x;
  if (self.innerWidth) { // all except Explorer
  	x = self.innerWidth;
  } else if (document.documentElement && document.documentElement.clientWidth) {	// Explorer 6 Strict Mode
  	x = document.documentElement.clientWidth;
  } else if (document.body) { // other Explorers
  	x = document.body.clientWidth;
  }
  return x;
}
function getScrollTop () {
  var y;
  if (self.pageYOffset) { // all except Explorer
  	y = self.pageYOffset;
  } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
  	y = document.documentElement.scrollTop;
  } else if (document.body) { // all other Explorers
  	y = document.body.scrollTop;
  }
  return y;
}
function getScrollLeft () {
  var x;
  if (self.pageYOffset) { // all except Explorer
  	x = self.pageXOffset;
  } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
  	x = document.documentElement.scrollLeft;
  } else if (document.body) { // all other Explorers
  	x = document.body.scrollLeft;
  }
  return x;
}
var notify = new notifier();