oParts = window.oParts || {};

oParts.version = '20080504.121826';

oParts.client = {
     w3c : !!window.getComputedStyle,
    MSIE : /*@cc_on!@*/false,
     IE6 : false/*@||!window.XMLHttpRequest@*/,
     IE7 : false/*@||!!window.XMLHttpRequest@*/,
   Opera : !!window.opera,
   Gecko : !!window.GeckoActiveXObject,
  Safari : !!(navigator.vendor && navigator.vendor.match(/Apple/))
};

oParts.events = [];
oParts.callee = [];
oParts.baseURL = '';

new function(){
 var scripts = self.parent.document.getElementsByTagName('SCRIPT');
 for (var i = 0, l = scripts.length; i < l; i++){
  if(scripts[i].src && scripts[i].src.indexOf('js/oParts.js') > 0) return oParts.baseURL = scripts[i].src.slice(0, -12);
 }
};

(function(){
 var w = window, d = document, de = d.documentElement, UD = 'undefined';
 var client = oParts.client;

 function Parts(parts, context){
  this.oparts = [];
  var _o;
  switch (typeof parts){
   case 'string' :
    _o = oParts.query(parts, context);
    this.size = (_o && _o.length) ? _o.length : _o ? 1 : 0;
    if(this.size){ 
     for(var j = 0; j < this.size; j++){
      att(this, _o[j]);
      this.oparts[this.oparts.length] = _o[j];
     }
    }
    break;
   case 'object' :
    if(parts instanceof Array){
     this.size = 0;
     for (var j = 0; _o = parts[j++];){
      if(_o){
       this.size++;
       this.oparts[this.oparts.length] = _o.$;
      }
     }
    } else {
     this.size = 1;
     att(this, parts);
     this.oparts[this.oparts.length] = parts;
    }
    break;
  }
  return this;
 }
 
 function att(a, b){
  a.$ = b;
  try { a.id = b.id; } catch(e) { a.id = null;};
  try { a.className = b.className; } catch(e){ a.className = null;};
 }
 Parts.prototype = {
  parent : function(n){
   var n = !n ? 1 : n, p = 'this.$';
   for(var i = 1; i <= n; i++){
    p += '.parentNode';
    if(!eval(p)) return null;
   }
   return o(eval(p));
  },
  child : function(n){
   var cn = this.$.childNodes, c = cn[n];
   if(c && c.nodeType != 1) while(c.nodeType != 1) c = c.nextSibling;
   return c ? o(c) : null;
  },
  sib : function(n){
   var N = n < 0 ? -n : n, sb = n < 0 ? '.previousSibling' : '.nextSibling', s = 'this.$';
   for(var i = 1; i <= N; i++){
    s += sb;
    if(!eval(s)) return null;
    if(eval(s).nodeType != 1) N++;
   }
   return o(eval(s));
  },
  item : function(n){ var self = this;
   this.each(function(e, i){
    if(n == i) return self = o(e);
   });
   return self;
  },
  visible : function(){
   return (this.css('display') != 'none') * 1;
  },
  show : function(a){
   if(a){ var s;
    if(client.Gecko) s = 'display: -moz-inline-stack; display:inline-block;';
    else if(client.MSIE) s = 'overflow:hidden; zoom: 1; display:inline;';
    else s = 'display: inline;'; this.css(s);
   } else this.css('display: block;'); return this;
  },
  hide : function(){
   this.css('display: none;'); return this;
  },
  toggle : function(){
   this.css('display:' + ['block','none'][this.visible()]); return this;
  },
  view : function(b){
   if(this.visible()) this.$.scrollIntoView(b);
   return this;
  },
  html : function(s, add){
   var v = []; this.each(function(o){
    if(s){
     if(add){
      switch (add){
       case 'before' : case -1 : o.innerHTML = (s + o.innerHTML); break;
       default  : o.innerHTML += s;
      }
     } else o.innerHTML = s;
    } else v[v.length] = o.innerHTML;
   });
   return s ? this : v.length == 1 ? v[0].toString() : v;
  },
  title : function(s){
   var v = []; this.each(function(o){
    if(s) o.title = s; else v[v.length] = o.title;
   });
   return s ? this : v.length == 1 ? v[0] : v;
  },
  value : function(s){
   var v = []; this.each(function(o){
    if(s || s == '') o.value = s; else v[v.length] = o.value;
   });
   return s ? this : v.length == 1 ? v[0] : v;
  },
  checked : function(){
   var v = []; this.each(function(o){
    v[v.length] = (o.checked ? 1 : 0);
   });
   return v.length == 1 ? v[0] : v;
  },
  src : function(s){
   if(s) this.$.src = s; else return this.$.src;
   return this;
  },
  subst : function (a, b){
   this.html(this.html().replace(a, b));
   return this;
  },
  clone : function(b){
   return o(this.$.cloneNode(b));
  },
  klass : function(c){
   if(c){
    return !this.$.className ? 0 : (' ' + this.$.className + ' ').indexOf(c) > 0 ? 1 : 0;
   } else return this.$.className;
  },
  css : function(exp){
   return exp.indexOf(':') > 0 ? this.setCSS(exp) : this.getCSS(exp);
  },
  setCSS : function(css){
   this.each(function(o){
    css.split(/;/).forEach(function(v){
     if(v.indexOf(':') > 0){
      v = v.split(/:/); var p = v.shift().trim(), s = v.join(':').trim() || '';
      if(/^0\.\d+$/.test(s) && s < 0.001) s = 0;
      p = p.replace(/-\D/g, function(m){ return m.charAt(1).toUpperCase()});
      if(p.indexOf('pacity') > 0){
       if(client.MSIE) o.style.zoom = 1;
       p = client.MSIE ? 'filter' : 'opacity';
       s = client.MSIE ? 'alpha(opacity=' + parseFloat(s) * 100 + ')' : parseFloat(s);
      }
      if(p=='float') p = client.MSIE ? 'styleFloat' : 'cssFloat';
      o.style[p] = s;
     }
    });
   });
   return this;
  },
  getCSS : function(prop){
   var v = null, o = this.$;
   if(d.defaultView){
    prop = prop.replace(/([A-Z])/g, '-$1').toLowerCase();
    if(prop.indexOf('border') != -1){
     prop = prop.replace(/border\-(\w+)$/, 'border-left-$1');
    }
    v = d.defaultView.getComputedStyle(o, null).getPropertyValue(prop);
   } else if(o.currentStyle){
    prop = prop.replace(/-\D/g, function(m){ return m.charAt(1).toUpperCase()});
    var cs = o.currentStyle, md = 'medium';
    switch (prop){
     case 'width' : 
      var bl = cs.borderLeftWidth; bl = bl == md ? 0 : parseInt(bl);
      var br = cs.borderRightWidth; br = br == md ? 0 : parseInt(br);
      v = o.offsetWidth - bl - br; break;
     case 'height' :
      var bt = cs.borderTopWidth; bt = bt == md ? 0 : parseInt(bt);
      var bb = cs.borderBottomWidth; bb = bb == md ? 0 : parseInt(bb);
      v = o.offsetHeight - bt - bb; break;
     case 'opacity' :
      o.style.zoom = 1; v = cs.filter.match(/opacity=([^)]+)/)[1] / 100; break;
     case 'float' : v = cs.styleFloat; break;
     default : v = cs[prop];
    }
    if(v == md) v = 2;
   } else v = o.style[prop];
   return /px$/.test(v) ? parseInt(v) : v;
  },
  moveTo : function(x, y){
   this.each(function(o){
    o.style.position = 'absolute';
    if(x != null) {o.style.left = parseInt(x) + 'px'; this.X = x;}
    if(y != null) {o.style.top = parseInt(y) + 'px'; this.Y = y;}
   });
   return this;
  },
  sizeTo : function(w, h){
   this.each(function(o){
    if(w != null) {o.style.width = parseInt(w) + 'px'; this.W = w;}
    if(h != null) {o.style.height = parseInt(h) + 'px'; this.H = h;}
   });
   return this;
  },
  dimension : function(x, y, w, h, pos){
   this.moveTo(x, y).sizeTo(w, h); if(pos) this.css('position:relative;'); return this;
  },
  rect : function(s){
   var self = this.$;
   return s === 0 ? self.offsetWidth : s === 1 ? self.offsetHeight : [self.offsetWidth, self.offsetHeight];
  },
  offset : function(s){
   var v, $ = this.$;
   if($.getBoundingClientRect){
    var r = $.getBoundingClientRect();
    if(s === 0) v = r.left + de.scrollLeft - 2;
    else if(s === 1) v = r.top + de.scrollTop - 2;
    else v = [r.left + de.scrollLeft - 2, r.top + de.scrollTop - 2];
   } else {
    var x = 0, y = 0;
    while ($.offsetParent){
     x += ($.offsetLeft); y += $.offsetTop; $ = $.offsetParent;
    }
    if(client.Safari && !w.getSearchEngine){
     x += d.body.offsetLeft; y += d.body.offsetTop;  
    }
    v = s === 0 ? Number(x) : s === 1 ? Number(y) : [Number(x), Number(y)];
   }
   return v;
  },
  addBefore : function(el){
   if(el.$) el = el.$;
   this.$.parentNode.insertBefore(el, this.$);
   return this;
  },
  addAfter : function(el){
   this.parent().addChild(el, this.$.nextSibling);
   return this;
  },
  addChild : function(a, b){
   if(!(a instanceof Array)) a = [a];
   for(var i = 0; el = a[i++];){
    if(el.$) el = el.$;
    if(b){
     if(b.$) b = b.$;
     this.$.insertBefore(el, b);
    } else this.$.appendChild(el);
   }
   return this;
  },
  deleteChild : function(a){
   if(!(a instanceof Array)) a = [a];
   for(var i = 0; el = a[i++];){
    if(el.$) el = el.$; this.$.removeChild(el);
   }
   return this;
  },
  away : function(){
   this.each(function(o){
    o.parentNode.removeChild(o); o = null;
   });
   return this;
  },
  await : function(ms, F){
   this.each(function(o){
    oParts.ticker = setTimeout(function(){ F.apply(o, arguments); }, ms);
   });
  },
  fade : function(delay, mode){
   delay = delay || 500; mode = mode || 'OUT';
   this.await(delay, function(e){ var el = o(this);
    switch(mode){
     case 'OUT' : var op = 1.0;
      (function(o){
       o.css('opacity:'+ (op -= 0.1));
       if(op < 0){
        if(oParts.ticker){
         clearTimeout(oParts.ticker); oParts.ticker = null;
        }
        o.hide().css('opacity:1');
       }
      }).loop(30, 15)(el);
     break;
    }
   });
  },
  each : function(F, index){
   for (var i = 0, l = this.oparts.length; i < l; ++i){
    if(this.$break) break;
    F.call(this, this.oparts[i], i);
   }
   return this;
  },
  cancelEvent : function(){
   this.each(function(){
    if(oParts.evt){
     oParts.evt.preventDefault();
     oParts.evt.stopPropagation();
    }
   });
   return this;
  },
  on : function(evType, F){
   var listener = function(o){
    var ev = evType.split(/\|/);
    for (var i = 0, l = ev.length; i < l; i++){
     var evi = ev[i], evRef = '_' + evi;
     if(!o[evRef]){
      o[evRef] = [];
      o['on' + evi] = function(e){
       e = e || ieev(w.event);
       for(var i in this[evRef]){ this[evRef][i].apply(this, [e]);}
      }
     } else for(var j in o[evRef]){ if(o[evRef][j] === F) return;}
     o[evRef].push(F);
     oParts.events.push([o, evRef]);
    }
    o = null;
   }
   this.each(function(o){ listener(o)});
  },
  off : function(evType, F){
   var listener = function(o){
    var evRef = '_' + evType;
    if(o[evRef]){
     for(var i in o[evRef]) if(o[evRef][i] === F) delete o[evRef][i];
     if(oParts.isEmpty(o[evRef])) delete o[evRef];
    }
   }
   this.each(function(o){ listener(o)});
  }
 }; //#prototype
 w.o = function(a, context, htmlelement){
  var element = new Parts(a, context || d);
  if(!element.size) delete element;
  return element.size ? element : null;
 }
  
 function ieev(e){
  e.preventDefault = new Function('event.returnValue = false;');
  e.stopPropagation = new Function('event.cancelBubble = true;');
  e.target = e.srcElement;
  e.relatedTarget = /out/.test(e.type) ? e.toElement : e.fromElement;
  e.pageX = de.scrollLeft + e.clientX || d.body.scrollLeft + e.clientX || 0;
  e.pageY = de.scrollTop + e.clientY || 0;
  e.which = e.keyCode;
  return e;
 };

 Parts.extend = function(name, method){
  if(!Parts.prototype[name]){
   Parts.prototype[name] = method;
  }
 };

 o(w).on('unload', function(){
  if(!oParts || !oParts.events) return;
  for (var i = 0, ev; oe = oParts.events[i++];){
   ev = oe[i];
   if(ev) if(ev[0]) ev[0][ev[1]] = null;
  }
  oParts = null;
  Function.prototype.await = Function.prototype.loop = null; // IE
 });

 oParts.start = function(F){
  for(var i in oParts.callee) if(oParts.callee[i] !== F) oParts.callee.push(F);
  if(client.Gecko || client.Opera || client.Safari){
   d.addEventListener('DOMContentLoaded', F, false);
  } else if(client.MSIE){
   $IEHTC = de.addBehavior(oParts.baseURL + 'js/ie.htc');
  } else o(w).on('load', F);
 };
 
 [].forEach || (Array.prototype.forEach = function(F){
  var i, l = this.length;
  for (i = 0; i < l; i++){
   if(typeof F != 'function') return;
   if(i in this) F.call(arguments[0], this[i], i, this);
  }
 });
 var EVENTS = 'MOUSEDOWN|MOUSEUP|MOUSEOVER|MOUSEOUT|MOUSEMOVE|MOUSEDRAG|CLICK|DBLCLICK|KEYPRESS|KEYDOWN|KEYUP';
 if(client.w3c){
  EVENTS.split('|').forEach(function(e){
   w.addEventListener(e.toLowerCase(), function(e){ oParts.evt = e}, true);
  });
 } else {
  EVENTS.split('|').forEach(function(e){
   d.attachEvent('on' + e.toLowerCase(), function(){ oParts.evt = ieev(event);});
  });
 }

 oParts.target = function(a){
  var tar = oParts.evt.target;
  if(a === 0) return o(tar).offset(0); // x-offset
  if(a === 1) return o(tar).offset(1); // y-offset
  if(a === 2) return [o(tar).offset(0), o(tar).offset(1)]; // x, y-offset
  return o(tar);
 }

 oParts.create = function(tag, css, parent, fly){
  var I = tag.indexOf('#'), C = tag.indexOf('.'), fly = fly || false;
  var el = d.createElement(tag.split(/[#\.]/)[0]);
  var context = parent || d.body;
  if(I > 0) el.id = tag.slice(I + 1);
  if(C > 0) el.className = tag.slice(C + 1);
  if(!fly){
   if(context.$) context = context.$;
   context.appendChild(el);
   el = el.id ? o(tag.slice(I)) : el.className ? o(tag.slice(C)) : o(el);
 } else el = o(el);
  if(css) el.setCSS(css);
  return el;
 };
 
 oParts.fragment = function(nodes){
  var frag, div = d.createElement('div'); div.innerHTML = nodes;
  frag = d.createDocumentFragment(); 
  while (div.firstChild) frag.appendChild(div.firstChild);
  return frag;
 };

})();

oParts.isEmpty = function(ob){
 for(var i in ob) return false; return true;
};
 
oParts.search = function(rex, array){
 for (var i = 0, l = array.length, m = null; i < l; i++){
  m = rex.test(array[i]);
  if(m) return array[i];
 }
 return m;
};

oParts.metrics = function(w){
 var d = document, de = d.documentElement;
 switch (w){
  case 'w' : case 0 : return de.clientWidth || self.innerWidth || d.body.clientWidth || 0;
  case 'h' : case 1 : return self.innerHeight || de.clientHeight || d.body.clientHeight || 0;
  case 'dh': case 2 : return de.scrollHeight || d.body.scrollHeight || 0;
  case 'sc': case 3 : return window.pageYOffset || de.scrollTop || d.body.scrollTop || 0;
 }
}

oParts.imgloader = function(hash, path){
 for(var name in hash){
  eval(name +'= new Image().src = "'+path+hash[name]+'";');
 }
}

oParts.server = {
 request : function(){
  if(window.XMLHttpRequest) return new XMLHttpRequest();
  if(window.ActiveXObject){ var r = null;
   ['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.3.0'].forEach(function(p){
    try { r = new ActiveXObject(p);} catch(e){}
   });
   return r;
  }
 },
 get : function(url, func){
  var r = oParts.server.request();
  var async = !arguments[2] ? true : false;
  try {
   r.open("GET", url, async);
   r.onreadystatechange = function(){
    if(r.readyState==4){
     if(toolTip && toolTip.visible()) toolTip.fade(200);
     if(func) func(r.responseText);
    }
   }
   //r.setRequestHeader("If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT");
   r.send(null);
  } catch (e){}
 },
 post : function(url, data, func){
  var r = oParts.server.request();
  try {
   r.open("POST", url, true);
   r.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   r.onreadystatechange = function(){
    if(r.readyState==4){
     if(toolTip && toolTip.visible()) toolTip.fade(200);
     if(func) func(r.responseText);
    }
   }
   r.send(data);
  } catch (e){}
 }
}

oParts.loadScript = function(src){
 if(!oParts.scripts) oParts.scripts = {};
 var r, s, async = arguments[1] ? true : false, d = document, safari = oParts.client.Safari;
 if(!oParts.scripts[src]){
  try {
   r = oParts.server.request();
   s = d.createElement('script');
   s.type = 'text/javascript'; s.charset = 'utf-8';
   if(safari) s.src = src;
   r.open('GET', src, async);
   r.send(null);
   if(r.readyState==4){
    if(r.status==200){
     s.text = r.responseText;
     d.documentElement.firstChild.appendChild(s);
     if(safari) eval(s.text);
     oParts.scripts[src] = src;
     return true;
    }
   }
  } catch(e){
   d.write('<script type="text/javascript" src="'+src+'"><\/scr'+'ipt>');
  }
 } else return true; // cached
 return false;
}

oParts.cookie = {
 set : function(name, value, days){
  days = days || 30;
  if(value == UD || value === '') return;
  var expire = new Date(); expire.setTime(expire.getTime() + (days*60*60*24*1000));
  document.cookie = name + "=" + escape(value) + "; expires=" + expire.toGMTString() + "; path=/";
 },
 get : function(name){
  var c = document.cookie.match(name + '=(.*?)(;|$)');
  return c ? unescape(c[1]) : null;
 },
 del : function(name) { oParts.cookie.set(name, '', -1); }
}

String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g, '');}

Function.prototype.await = function(ms){
 var F = this; return function(){
  var a = arguments.callee.arguments;
  setTimeout(function(){ F.apply(null, a);}, ms);
 }
}
Function.prototype.loop = function(ms, limit){
 var count = 0, self = this;
 return function(){
  var a = arguments;
  if(limit <= count) return; count++;
  self.apply(a.callee.await(ms)(a[0]), a);
 }
}

oParts.query = (function(){

function $S(rule,context){var d=document;context=context||d;context=context.$?context.$:context;if(d.evaluate){return nodes=xpath(css2xpath(rule,context),context);}
var REX=/(^[>\+~])/;rule=rule.replace(/([>\+~])\s*(\w+)/,'$1$2');var parts=rule.split(/\s/),i=0,node,sep=null,nodes=[context||d];for(i;node=parts[i++];){if(REX.test(node)){sep=RegExp.$1;node=node.replace(REX,'');}
nodes=getNodes(node,nodes,sep);}
return nodes;}
function getNodes(node,context,sep){var nodes=[],u={},d=document,tagName,className=null,attr=null,pseudo=null,thru=true;var ipos=node.indexOf('#');if(ipos>=0){node=d.getElementById(node.slice(ipos+1));return node?[node]:nodes;}
var apos=node.indexOf('['),cpos=node.indexOf('.'),ppos=node.indexOf(':');var i=0,index=0,j,cn,paren,val,flag;if(apos>=0){tagName=node.slice(0,apos);attr=node.slice(apos+1,-1);attr=(attr.indexOf('][')>0)?attr.split(']['):[attr];}else if(cpos>=0){tagName=node.slice(0,cpos);className=node.slice(cpos+1);}else if(ppos>=0){tagName=node.slice(0,ppos);pseudo=node.slice(ppos+1);paren=pseudo.indexOf('(');if(paren>0){val=pseudo.slice(paren+1,-1);pseudo=pseudo.slice(0,paren);}}else{tagName=node;}
tagName=tagName.toUpperCase();for(i;x=$n=context[i++];){if(sep){thru=false;switch(sep){case'+':while(($n=$n.nextSibling)&&$n.nodeType!=1);if($n&&$n.nodeName==tagName)nodes[nodes.length]=$n;break;case'>':for($n=$n.firstChild;$n;$n=$n.nextSibling){if($n.nodeName==tagName)nodes[nodes.length]=$n;}
break;case'~':while($n=$n.nextSibling){if($n.nodeName==tagName){nodes[nodes.length]=x;break;}}
break;}}else{var roots=tagName?x.getElementsByTagName(tagName):x.getElementsByTagName('*');if(!className&&!attr&&!pseudo){}
if(attr){var att,val;for(var a,k=0;a=attr[k++];){if(a.indexOf('=')>0){att=a.split('='),val=att[1],att=att[0];var op=null,m=/^(\w+)([\^\$~\*\|])$/i.exec(att);if(m){att=m[1],op=m[2];}
att=(att=='class')?'className':att;}else{attr=(attr=='class')?'className':attr;}}}
for(j=0;n=$=roots[j++];){if(className){if(n.className){if((' '+n.className+' ').indexOf(className)<0)continue;}else continue;}
if(attr){if(!att){if(n[attr]=='')continue;}else{if(op){var p=n[att];switch(op){case'^':if(p.indexOf(val)!=0)continue;break;case'$':if(p.lastIndexOf(val)!=p.length-val.length)continue;break;case'~':if((' '+p+' ').indexOf(val)==-1)continue;break;case'*':if(p.indexOf(val)==-1)continue;break;case'|':if(p!=val&&p.indexOf(val+'-')==-1)continue;break;}}else{if(n[att]!=val)continue;}}}
if(pseudo){switch(pseudo){case'root':return[(ownerDocument||d).documentElement];case'first-child':while(($=$.previousSibling)&&$.nodeType!=1);if($)continue;break;case'last-child':while(($=$.nextSibling)&&$.nodeType!=1);if($)continue;break;case'only-child':if(n.previousSibling||n.nextSibling)continue;break;case'first-of-type':flag=false;while($=$.previousSibling){if($&&$.nodeName==tagName){flag=true;break;}};if(flag)continue;break;case'last-of-type':flag=false;while($=$.nextSibling){if($&&$.nodeName==tagName){flag=true;break;}};if(flag)continue;break;case'only-of-type':var _$=n;flag=2;while($=$.previousSibling){if($&&$.nodeName==tagName){flag--;break;}}
while(_$=_$.nextSibling){if(_$&&_$.nodeName==tagName){flag--;break;}}
if(flag!=2)continue;break;case'empty':var c=n.firstChild;if(c.nodeType==1||c.nodeType==3)continue;break;case'not':var m=/^[a-z1-6]+$/i.test(val);if(m){if(n.nodeName==val.toUpperCase())continue;}else{var m=/^\[(.+?)(="?(.+?)"?)?\]$/i.exec(val);if(m[1]&&m[3]){if(n[m[1]]==m[3])continue;}else if(m[1]){if(!!n[m[1]])continue;}}
break;case'contains':var txt=n.innerText||n.textContent||'';if(txt!=''){if(txt.indexOf(val)<0)continue;}else continue;break;case'lang':if(n['lang']){if(n['lang'].indexOf(val)<0)continue;}else continue;break;case'enabled':case'disabled':if('BUTTON|INPUT|TEXTAREA|SELECT|OPTION|LINK|STYLE|OPTGROUP|'.indexOf(tagName+'|')<0){continue;}else{if(pseudo=='disabled'){if(n[pseudo]!=pseudo&&n[pseudo]!=true)continue;}else{var nd=n['disabled'];if(nd&&(nd==true||nd=='disabled'))continue;}}
break;case'checked':if(tagName!='INPUT')continue;if(!n['checked'])continue;break;case'nth-child':case'nth-of-type':case'nth-last-child':case'nth-last-of-type':var a,b=-1;thru=false;if(val=='even'||val=='2n'){a=2,b=0;}else if(val=='odd'||val=='2n+1'){a=2,b=1;}else a=/(\d+?)?n?\+?(\d+)?$/.exec(val);if(b<0){if(a[0]=='n'){a=1,b=0;}
else if(a[2]){b=a[2],a=a[1];}
else{b=a[1],a=0;}}
var p=n.parentNode,c,index=0;var last=pseudo.indexOf('last')>0?1:0;if(!p.touched){for(c=(last?p.lastChild:p.firstChild);c;c=(last?c.previousSibling:c.nextSibling)){if(c.nodeType==1){if(pseudo.indexOf('child')>0){c.srcIndex=++index;}else if(c.nodeName==tagName)c.srcIndex=++index;}}
p.touched=true;}
if(a!=0){if(n.srcIndex%a==b)nodes[nodes.length]=n;}else if(n.srcIndex==b)nodes[nodes.length]=n;continue;break;}}
if(thru){if(n&&u[n.sourceIndex]==undefined)nodes[nodes.length]=u[n.sourceIndex]=n;}}}}
return nodes;}
function xpath(selector,context){var d=document,nodes=[],item,xp;xp=d.evaluate(selector,context||d,null,XPathResult.ANY_TYPE,null);for(item=xp.iterateNext();item;item=xp.iterateNext()){nodes[nodes.length]=item;}
return nodes.length?nodes:null;}
function css2xpath(rule,context){var path=[],REX=/(^[>\+~])/;var tagName,className,exp='',paren,val,ipos,apos,cpos,ppos,combinator=null,connecter;rule=rule.replace(/^\s|\s$/g,'').replace(/([>\+~])\s*(\w+)/,'$1$2');var parts=rule.split(/\s/),i=0,node;for(i;node=parts[i++];){exp=connecter='';if(REX.test(node)){combinator=RegExp.$1;node=node.replace(REX,'');}
tagName=node;ipos=node.indexOf('#'),apos=node.indexOf('['),cpos=node.indexOf('.'),ppos=node.indexOf(':');if(ipos>=0){tagName=node.slice(0,ipos)||'*';exp='[@id="'+node.slice(ipos+1)+'"]';}
if(cpos>=0){tagName=node.slice(0,cpos)||'*';className=node.slice(cpos+1);exp='[contains(concat(" ",@class," ")," '+className+' ")]';}else if(apos>=0){tagName=node.slice(0,apos)||'*';attr=node.slice(apos+1,-1);attr=(attr.indexOf('][')>0)?attr.split(']['):[attr];var att,val;for(var a,k=0;a=attr[k++];){if(a.indexOf('=')>0){att=a.split('='),val=att[1].replace('"',''),att=att[0];var m=/^(\w+)([\^\$~\*\|])$/i.exec(att);if(m){switch(m[2]){case'*':exp='[contains(@'+m[1]+',"'+val+'")]';break;case'^':exp='[starts-with(@'+m[1]+',"'+val+'")]';break;case'$':exp='[substring(@'+m[1]+',string-length(@'+m[1]+')-string-length("'+val+'")+1)="'+val+'"]';break;case'~':exp='[contains(concat(" ",@'+m[1]+'," ")," '+val+' ")]';break;case'|':exp='[@class = "'+val+'" or starts-with(@class, "'+val+'-")]';break;};}else exp='[@'+att+'="'+val+'"]';}else exp='[@'+a+']';}}else if(ppos>=0){tagName=node.slice(0,ppos)||'*';pseudo=node.slice(ppos+1);paren=pseudo.indexOf('(');if(paren>0){val=pseudo.slice(paren+1,-1);pseudo=pseudo.slice(0,paren);}
switch(pseudo){case'root':exp='[not(parent::*)]';break;case'first-child':exp='[not(preceding-sibling::*)]';break;case'last-child':exp='[not(following-sibling::*)]';break;case'only-child':exp='[not(preceding-sibling::*) and not(following-sibling::*)]';break;case'first-of-type':exp='[1]';break;case'last-of-type':exp='[last()]';break;case'only-of-type':exp='[count(../'+tagName+') = 1]';break;case'empty':exp='[not(child::*) and not(text())]';break;case'not':exp='[not('+css2xpath(val,context).replace(/^\/\/(\*|\w+)/,'self::$1')+')]';break;case'contains':exp='[contains(descendant::text(), "'+val+'")]';break;case'lang':exp='[boolean(lang("'+val+'") or boolean(ancestor-or-self::*[@lang][1][starts-with(@lang,"'+val+'")]))]';break;case'enabled':exp='[not(@disabled and (@disabled = "true" or @disabled = "disabled")) or (@enabled and @enabled = "false")]';break;case'disabled':exp='[(@disabled and (@disabled = "true" or @disabled = "disabled")) or (@enabled and @enabled = "false")]';break;case'checked':exp='[(@checked and (@checked = "true" or @checked = "checked"))]';break;case'nth-child':case'nth-last-child':case'nth-of-type':case'nth-last-of-type':var a,b=-1,last=pseudo.indexOf('last')>0?1:0,type=pseudo.indexOf('type')>0?1:0;if(val=='even'||val=='2n'){a=2,b=0;}else if(val=='odd'||val=='2n+1'){a=2,b=1;}
else a=/(\d+?)?n?\+?(\d+)?$/.exec(val);if(b<0){if(a[0]=='n'){a=1,b=0;}else if(a[2]){b=a[2],a=a[1];}else{b=a[1],a=0;}}
exp=type?'['+(last?'(last() + 1 - position())':'position()')+(a===0?'':'mod '+a)+' = '+b+']':'[(count('+(last?'follow':'preced')+'ing-sibling::*) + 1) '+(a===0?'':'mod '+a)+' = '+b+']';break;};}
if(combinator){switch(combinator){case'>':path.push('/child::'+tagName);break;case'+':path.push('/following-sibling::*[1][self::'+tagName+']');break;case'~':path.push('/following-sibling::'+tagName);break;};tagName='';connecter='';}else connecter='//';path.push(tagName+exp);}
return(context.nodeType==9?'//':'.//')+path.join(connecter);}
return function(rule,context,parts){var d=document,nodes=[];if(rule.indexOf(',')>0){var i,r,rs=rule.split(','),x=rs.length,unique=[],u={},ns;while(x--){r=rs[x].replace(/^\s|\s$/g,'');if(u[r]==undefined)unique[unique.length]=u[r]=r;}
for(i=0;u=unique[i++];){ns=$S(u,context);for(x=0;r=ns[x++];)nodes[nodes.length]=r;}}else nodes=$S(rule,context);if(nodes==null||nodes=='')return null;if(parts)return o(nodes);return nodes;}

})();

