/* xLibrary={version:'4.24',license:'GNU LGPL',url:'http://cross-browser.com/'};
 * xAddClass
 * xAddEventListener
 * xAnimation
 * xAnimation.css
 * xAnimation.scroll
 * xCamelize
 * xDef
 * xEach
 * xGetComputedStyle
 * xGetElementById
 * xGetElementsByClassName
 * xGetElementsByTagName
 * xHasClass
 * xHeight
 * xNum
 * xOffset
 * xParentN
 * xPrevSib
 * xRemoveClass
 * xRemoveEventListener
 * xScrollLeft
 * xScrollTop
 * xStr
 * xStyle
 * xTop
 * xWidth
 * xWinScrollTo
 * xClientHeight
 */

// xClientHeight r6, Copyright 2001-2008 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xClientHeight()
{
  var v=0,d=document,w=window;
  if((!d.compatMode || d.compatMode == 'CSS1Compat') /* && !w.opera */ && d.documentElement && d.documentElement.clientHeight)
    {v=d.documentElement.clientHeight;}
  else if(d.body && d.body.clientHeight)
    {v=d.body.clientHeight;}
  else if(xDef(w.innerWidth,w.innerHeight,d.width)) {
    v=w.innerHeight;
    if(d.width>w.innerWidth) v-=16;
  }
  return v;
}

// xAnimation.scroll r3, Copyright 2006-2010 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
xAnimation.prototype.scroll = function(e,x,y,t,a,b,oe)
{
  var i = this;
  i.axes(2);
  i.init(e);
  i.win = i.e.nodeType==1 ? false:true;
  i.a[0].i = xScrollLeft(i.e, i.win); i.a[1].i = xScrollTop(i.e, i.win); // initial position
  i.a[0].t = Math.round(x); i.a[1].t = Math.round(y); // target position
  i.init(e,t,h,h,oe,a,b);
  i.run();
  function h(i) { // onRun and onTarget
    var x = Math.round(i.a[0].v), y = Math.round(i.a[1].v);
    if (i.win) i.e.scrollTo(x, y);
    else { i.e.scrollLeft = x; i.e.scrollTop = y; }
  }
};


// xOffset r1, Copyright 2009 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xOffset(c, p)
{
  var o = {x:0, y:0};
  c = xGetElementById(c);
  p = xGetElementById(p);
  while (c && c != p) {
    o.x += c.offsetLeft;
    o.y += c.offsetTop;
    c = c.offsetParent;
  }
  return o;
}


// xTop r2, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xTop(e, iY)
{
  if(!(e=xGetElementById(e))) return 0;
  var css=xDef(e.style);
  if(css && xStr(e.style.top)) {
    if(xNum(iY)) e.style.top=iY+'px';
    else {
      iY=parseInt(e.style.top);
      if(isNaN(iY)) iY=xGetComputedStyle(e,'top',1);
      if(isNaN(iY)) iY=0;
    }
  }
  else if(css && xDef(e.style.pixelTop)) {
    if(xNum(iY)) e.style.pixelTop=iY;
    else iY=e.style.pixelTop;
  }
  return iY;
}


// xGetElementById r2, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xGetElementById(e)
{
  if (typeof(e) == 'string') {
    if (document.getElementById) e = document.getElementById(e);
    else if (document.all) e = document.all[e];
    else e = null;
  }
  return e;
}

//xDef r2, Copyright 2001-2011 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xDef()
{
for (var i=0, l=arguments.length; i<l; ++i) {
 if (typeof(arguments[i]) === 'undefined')
   return false;
}
return true;
}

//xNum r3, Copyright 2001-2011 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xNum()
{
for (var i=0, l=arguments.length; i<l; ++i) {
 if (isNaN(arguments[i]) || typeof(arguments[i]) !== 'number')
   return false;
}
return true;
}

//xScrollTop r4, Copyright 2001-2009 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xScrollTop(e, bWin)
{
var w, offset=0;
if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
 w = window;
 if (bWin && e) w = e;
 if(w.document.documentElement && w.document.documentElement.scrollTop) offset=w.document.documentElement.scrollTop;
 else if(w.document.body && xDef(w.document.body.scrollTop)) offset=w.document.body.scrollTop;
}
else {
 e = xGetElementById(e);
 if (e && xNum(e.scrollTop)) offset = e.scrollTop;
}
return offset;
}

//xScrollLeft r4, Copyright 2001-2009 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xScrollLeft(e, bWin)
{
var w, offset=0;
if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
 w = window;
 if (bWin && e) w = e;
 if(w.document.documentElement && w.document.documentElement.scrollLeft) offset=w.document.documentElement.scrollLeft;
 else if(w.document.body && xDef(w.document.body.scrollLeft)) offset=w.document.body.scrollLeft;
}
else {
 e = xGetElementById(e);
 if (e && xNum(e.scrollLeft)) offset = e.scrollLeft;
}
return offset;
}

//xWinScrollTo r3, Copyright 2003-2007 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
var xWinScrollWin = null;
function xWinScrollTo(win,x,y,uTime) {
var e = win;
if (!e.timeout) e.timeout = 25;
var st = xScrollTop(e, 1);
var sl = xScrollLeft(e, 1);
e.xTarget = x; e.yTarget = y; e.slideTime = uTime; e.stop = false;
e.yA = e.yTarget - st;
e.xA = e.xTarget - sl; // A = distance
if (e.slideLinear) e.B = 1/e.slideTime;
else e.B = Math.PI / (2 * e.slideTime); // B = period
e.yD = st;
e.xD = sl; // D = initial position
var d = new Date(); e.C = d.getTime();
if (!e.moving) {
 xWinScrollWin = e;
 _xWinScrollTo();
}
}
function _xWinScrollTo() {
var e = xWinScrollWin || window;
var now, s, t, newY, newX;
now = new Date();
t = now.getTime() - e.C;
if (e.stop) { e.moving = false; }
else if (t < e.slideTime) {
 setTimeout("_xWinScrollTo()", e.timeout);

 s = e.B * t;
 if (!e.slideLinear) s = Math.sin(s);
// if (e.slideLinear) s = e.B * t;
// else s = Math.sin(e.B * t);

 newX = Math.round(e.xA * s + e.xD);
 newY = Math.round(e.yA * s + e.yD);
 e.scrollTo(newX, newY);
 e.moving = true;
}  
else {
 e.scrollTo(e.xTarget, e.yTarget);
 xWinScrollWin = null;
 e.moving = false;
 if (e.onslideend) e.onslideend();
}  
}

//xAddEventListener r8, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xAddEventListener(e,eT,eL,cap)
{
if(!(e=xGetElementById(e)))return;
eT=eT.toLowerCase();
if(e.addEventListener)e.addEventListener(eT,eL,cap||false);
else if(e.attachEvent)e.attachEvent('on'+eT,eL);
else {
 var o=e['on'+eT];
 e['on'+eT]=typeof o=='function' ? function(v){o(v);eL(v);} : eL;
}
}

//xGetElementsByTagName r5, Copyright 2002-2007 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xGetElementsByTagName(t,p)
{
var list = null;
t = t || '*';
p = xGetElementById(p) || document;
if (typeof p.getElementsByTagName != 'undefined') { // DOM1
 list = p.getElementsByTagName(t);
 if (t=='*' && (!list || !list.length)) list = p.all; // IE5 '*' bug
}
else { // IE4 object model
 if (t=='*') list = p.all;
 else if (p.all && p.all.tags) list = p.all.tags(t);
}
return list || [];
}

//xEach r1, Copyright 2006-2007 Daniel Frechette
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
/**
* Access each element of a collection sequentially (by its numeric index)
* and do something with it.
* @param c - Array/Obj - A collection of elements
* @param f - Func      - Function to execute for each element.
*                        Arguments: item, index, number of items
* @param s - Int       - Start index. A number between 0 and collection size - 1. (optional)
* @return Nothing
*/
function xEach(c, f, s) {
var l = c.length;
for (var i=(s || 0); i < l; i++) {
 f(c[i], i, l);
}
};

//xHasClass r3, Copyright 2005-2007 Daniel Frechette - modified by Mike Foster
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xHasClass(e, c)
{
e = xGetElementById(e);
if (!e || e.className=='') return false;
var re = new RegExp("(^|\\s)"+c+"(\\s|$)");
return re.test(e.className);
}

//xStyle r2, Copyright 2007,2010 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xStyle(p, v)
{
var i, e;
for (i = 2; i < arguments.length; ++i) {
 e = xGetElementById(arguments[i]);
 try { e.style[p] = v; }
 catch (ex) {
/*@cc_on
@if (@_jscript_version <= 5.7) // IE7 and down
if(p!='display'){continue;}var s='',t=e.tagName.toLowerCase();switch(t){case'table':case'tr':case'td':case'li':s='block';break;case'caption':s='inline';break;}e.style[p]=s;
@end @*/
 }
}
}

//xGetElementsByClassName r7, Copyright 2002-2011 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xGetElementsByClassName(c,p,t,f)
{
var r=[], re, e, i, l;
re = new RegExp("(^|\\s)"+c+"(\\s|$)");
//var e = p.getElementsByTagName(t);
e = xGetElementsByTagName(t,p); // See xml comments.
for (i=0, l=e.length; i<l; ++i) {
 if (re.test(e[i].className)) {
   r[r.length] = e[i];
   if (f) f(e[i]);
 }
}
return r;
}

//xAddClass r3, Copyright 2005-2007 Daniel Frechette - modified by Mike Foster
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xAddClass(e, c)
{
if ((e=xGetElementById(e))!=null) {
 var s = '';
 if (e.className.length && e.className.charAt(e.className.length - 1) != ' ') {
   s = ' ';
 }
 if (!xHasClass(e, c)) {
   e.className += s + c;
   return true;
 }
}
return false;
}

//xRemoveClass r3, Copyright 2005-2007 Daniel Frechette - modified by Mike Foster
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xRemoveClass(e, c)
{
if(!(e=xGetElementById(e))) return false;
e.className = e.className.replace(new RegExp("(^|\\s)"+c+"(\\s|$)",'g'),
 function(str, p1, p2) { return (p1 == ' ' && p2 == ' ') ? ' ' : ''; }
);
return true;
}

//xParentN 2, Copyright 2005-2007 Olivier Spinelli
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xParentN(e, n)
{
while (e && n--) e = e.parentNode;
return e;
}

//xCamelize r1, Copyright 2007-2009 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xCamelize(cssPropStr)
{
var i, c, a, s;
a = cssPropStr.split('-');
s = a[0];
for (i=1; i<a.length; ++i) {
 c = a[i].charAt(0);
 s += a[i].replace(c, c.toUpperCase());
}
return s;
}

//xGetComputedStyle r7, Copyright 2002-2007 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xGetComputedStyle(e, p, i)
{
if(!(e=xGetElementById(e))) return null;
var s, v = 'undefined', dv = document.defaultView;
if(dv && dv.getComputedStyle){
 s = dv.getComputedStyle(e,'');
 if (s) v = s.getPropertyValue(p);
}
else if(e.currentStyle) {
 v = e.currentStyle[xCamelize(p)];
}
else return null;
return i ? (parseInt(v) || 0) : v;
}

//xAnimation r5, Copyright 2006-2010 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xAnimation(r)
{
this.res = r || 10;
}
//Initialize an array of n axis objects.
xAnimation.prototype.axes = function(n)
{
var j, i = this;
if (!i.a || i.a.length != n) {
 i.a = [];
 for (j = 0; j < n; ++j) {
   i.a[j] = { i:0, t:0, d:0, v:0 }; // initial value, target value, displacement, instantaneous value
 }
}
};
//The caller must set the axes' initial and target values before calling init.
xAnimation.prototype.init = function(e,t,or,ot,oe,at,b)
{
var ai, i = this;
i.e = xGetElementById(e);
i.t = t;
i.or = or; // onRun
i.ot = ot; // onTarget
i.oe = oe; // onEnd
i.at = at || 0; // acceleration type
i.v = xAnimation.vf[i.at];
i.qc = 1 + (b || 0); // quarter-cycles
i.fq = 1 / i.t; // frequency
if (i.at > 0 && i.at < 4) {
 i.fq *= i.qc * Math.PI;
 if (i.at == 1 || i.at == 2) { i.fq /= 2; }
}
// displacements
for (ai = 0; ai < i.a.length; ++ai) {
 i.a[ai].d = i.a[ai].t - i.a[ai].i;
}
};
xAnimation.prototype.run = function(r)
{
var ai, qcm2, rep, i = this;
if (!r) { i.t1 = new Date().getTime(); }
if (!i.tmr) i.tmr = setInterval(
 function() {
   i.et = new Date().getTime() - i.t1; // elapsed time
   if (i.et < i.t) {
     // instantaneous values
     i.f = i.v(i.et * i.fq);
     for (ai = 0; ai < i.a.length; ++ai) {
       i.a[ai].v = i.a[ai].d * i.f + i.a[ai].i;
     }
     i.or(i); // call onRun
   }
   else { // target time reached
     clearInterval(i.tmr);
     i.tmr = null;
     qcm2 = i.qc % 2;
     for (ai = 0; ai < i.a.length; ++ai) {
       if (qcm2) { i.a[ai].v = i.a[ai].t; }
       else { i.a[ai].v = i.a[ai].i; }
     }
     i.ot(i); // call onTarget
     // handle onEnd
     rep = false;
     if (typeof i.oe == 'function') { rep = i.oe(i); }
     else if (typeof i.oe == 'string') { rep = eval(i.oe); }
     if (rep) { i.resume(1); }
   }
 }, i.res
);
};
xAnimation.prototype.pause = function()
{
clearInterval(this.tmr);
this.tmr = null;
};
xAnimation.prototype.resume = function(fs)
{
if (typeof this.tmr != 'undefined' && !this.tmr) {
 this.t1 = new Date().getTime();
 if (!fs) {this.t1 -= this.et;}
 this.run(!fs);
}
};
//Static array of velocity functions
xAnimation.vf = [
function(r){return r;},
function(r){return Math.abs(Math.sin(r));},
function(r){return 1-Math.abs(Math.cos(r));},
function(r){return (1-Math.cos(r))/2;},
function(r) {return (1.0 - Math.exp(-r * 6));}
];
//end xAnimation

//xAnimation.css r3, Copyright 2006-2010 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
xAnimation.prototype.css = function(e,p,v,t,a,b,oe)
{
var i = this;
i.axes(1);
i.a[0].i = xGetComputedStyle(e,p,true); // initial value
i.a[0].t = v; // target value
i.prop = xCamelize(p);
i.init(e,t,h,h,oe,a,b);
i.run();
function h(i) {i.e.style[i.prop] = Math.round(i.a[0].v) + 'px';}
};

//xStr r2, Copyright 2001-2011 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xStr(s)
{
for (var i=0, l=arguments.length; i<l; ++i) {
 if (typeof(arguments[i]) !== 'string')
   return false;
}
return true;
}

//xWidth r8, Copyright 2001-2010 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xWidth(e,w)
{
var css, pl=0, pr=0, bl=0, br=0;
if(!(e=xGetElementById(e))) return 0;
if (xNum(w)) {
 if (w<0) w = 0;
 else w=Math.round(w);
}
else w=-1;
css=xDef(e.style);
if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
 w = xClientWidth();
}
else if(css && xDef(e.offsetWidth) && xStr(e.style.width)) {
 if(w>=0) {
   if (document.compatMode=='CSS1Compat') {
     pl=xGetComputedStyle(e,'padding-left',1);
     if (pl !== null) {
       pr=xGetComputedStyle(e,'padding-right',1);
       bl=xGetComputedStyle(e,'border-left-width',1);
       br=xGetComputedStyle(e,'border-right-width',1);
     }
     // Should we try this as a last resort?
     // At this point getComputedStyle and currentStyle do not exist.
     else if(xDef(e.offsetWidth,e.style.width)){
       e.style.width=w+'px';
       pl=e.offsetWidth-w;
     }
   }
   w-=(pl+pr+bl+br);
   if(isNaN(w)||w<0) return;
   else e.style.width=w+'px';
 }
 w=e.offsetWidth;
}
else if(css && xDef(e.style.pixelWidth)) {
 if(w>=0) e.style.pixelWidth=w;
 w=e.style.pixelWidth;
}
return w;
}

//xScrollTop r4, Copyright 2001-2009 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xScrollTop(e, bWin)
{
var w, offset=0;
if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
 w = window;
 if (bWin && e) w = e;
 if(w.document.documentElement && w.document.documentElement.scrollTop) offset=w.document.documentElement.scrollTop;
 else if(w.document.body && xDef(w.document.body.scrollTop)) offset=w.document.body.scrollTop;
}
else {
 e = xGetElementById(e);
 if (e && xNum(e.scrollTop)) offset = e.scrollTop;
}
return offset;
}

//xScrollLeft r4, Copyright 2001-2009 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xScrollLeft(e, bWin)
{
var w, offset=0;
if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
 w = window;
 if (bWin && e) w = e;
 if(w.document.documentElement && w.document.documentElement.scrollLeft) offset=w.document.documentElement.scrollLeft;
 else if(w.document.body && xDef(w.document.body.scrollLeft)) offset=w.document.body.scrollLeft;
}
else {
 e = xGetElementById(e);
 if (e && xNum(e.scrollLeft)) offset = e.scrollLeft;
}
return offset;
}

//xRemoveEventListener r6, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xRemoveEventListener(e,eT,eL,cap)
{
if(!(e=xGetElementById(e)))return;
eT=eT.toLowerCase();
if(e.removeEventListener)e.removeEventListener(eT,eL,cap||false);
else if(e.detachEvent)e.detachEvent('on'+eT,eL);
else e['on'+eT]=null;
}

//xPrevSib r4, Copyright 2005-2007 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xPrevSib(e,t)
{
e = xGetElementById(e);
var s = e ? e.previousSibling : null;
while (s) {
 if (s.nodeType == 1 && (!t || s.nodeName.toLowerCase() == t.toLowerCase())){break;}
 s = s.previousSibling;
}
return s;
}
//xHeight r8, Copyright 2001-2010 Michael Foster (Cross-Browser.com)
//Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xHeight(e,h)
{
var css, pt=0, pb=0, bt=0, bb=0;
if(!(e=xGetElementById(e))) return 0;
if (xNum(h)) {
 if (h<0) h = 0;
 else h=Math.round(h);
}
else h=-1;
css=xDef(e.style);
if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
 h = xClientHeight();
}
else if(css && xDef(e.offsetHeight) && xStr(e.style.height)) {
 if(h>=0) {
   if (document.compatMode=='CSS1Compat') {
     pt=xGetComputedStyle(e,'padding-top',1);
     if (pt !== null) {
       pb=xGetComputedStyle(e,'padding-bottom',1);
       bt=xGetComputedStyle(e,'border-top-width',1);
       bb=xGetComputedStyle(e,'border-bottom-width',1);
     }
     // Should we try this as a last resort?
     // At this point getComputedStyle and currentStyle do not exist.
     else if(xDef(e.offsetHeight,e.style.height)){
       e.style.height=h+'px';
       pt=e.offsetHeight-h;
     }
   }
   h-=(pt+pb+bt+bb);
   if(isNaN(h)||h<0) return;
   else e.style.height=h+'px';
 }
 h=e.offsetHeight;
}
else if(css && xDef(e.style.pixelHeight)) {
 if(h>=0) e.style.pixelHeight=h;
 h=e.style.pixelHeight;
}
return h;
}


