//ģ黯д͵ִ
(function(){

/*
ʸ//ֵܽڵ㣬߶ȳƱȽ
eleemnt ǰڵ
walk ָķʽ
start ʼڵλ
match ƥ˵ıǩ
all Ƿ񷵻ָаĽڵ
nocash ǷҪԽڵչĬΪfalseҪ
*/
var walk = function(element, walk, start, match, all, nocash){
 //ȷʼλ
 var el = element[start || walk];
 var elements = [];
 while (el){
  //HTML ElementڵƥָǩĽڵ(ָƥǩʱ)
  if (el.nodeType == 1 && (!match || Element.match(el, match))){
   elements.push(el);
   //Ҫзڵʱѭ
   if (!all) break;
  }
  //ƶ
  el = el[walk];
 }
 return (all) ? new Elements(elements, {ddup: false, cash: !nocash}) : $(elements[0], nocash);
};

Element.implement({

 //ȡǰڵǰͬڵ
 getPrevious: function(match, nocash){
  return walk(this, 'previousSibling', null, match, false, nocash);
 },

 //ȡǰڵǰеͬڵ
 getAllPrevious: function(match, nocash){
  return walk(this, 'previousSibling', null, match, true, nocash);
 },

 //ȡǰڵͬڵ
 getNext: function(match, nocash){
  return walk(this, 'nextSibling', null, match, false, nocash);
 },

 //ȡǰڵеͬڵ
 getAllNext: function(match, nocash){
  return walk(this, 'nextSibling', null, match, true, nocash);
 },

 //ȡǰڵڵĵһڵ
 getFirst: function(match, nocash){
  return walk(this, 'nextSibling', 'firstChild', match, false, nocash);
 },

 //ȡǰڵڵһڵ
 getLast: function(match, nocash){
  return walk(this, 'previousSibling', 'lastChild', match, false, nocash);
 },

 //ȡǰڵϼڵ
 getParent: function(match, nocash){
  return walk(this, 'parentNode', null, match, false, nocash);
 },

 //ȡǰڵ
 getParents: function(match, nocash){
  return walk(this, 'parentNode', null, match, true, nocash);
 },

 //ȡǰڵӽڵ
 getChildren: function(match, nocash){
  return walk(this, 'nextSibling', 'firstChild', match, true, nocash);
 },

 //жǷָӽڵ
 hasChild: function(el){
  el = $(el, true);
  return (!!el && $A(this.getElementsByTagName(el.tagName)).contains(el));
 }

});

})();


