
(function(){var Y=YAHOO.util;Y.Selector={_foundCache:[],_regexCache:{},_re:{nth:/^(?:([-]?\d*)(n){1}|(odd|even)$)*([-+]?\d*)$/,attr:/(\[.*\])/g,urls:/^(?:href|src)/},document:window.document,attrAliases:{},shorthand:{'\\#(-?[_a-z]+[-\\w]*)':'[id=$1]','\\.(-?[_a-z]+[-\\w]*)':'[class~=$1]'},operators:{'=':function(attr,val){return attr===val;},'!=':function(attr,val){return attr!==val;},'~=':function(attr,val){var s=' ';return(s+attr+s).indexOf((s+val+s))>-1;},'|=':function(attr,val){return attr===val||attr.slice(0,val.length+1)===val+'-';},'^=':function(attr,val){return attr.indexOf(val)===0;},'$=':function(attr,val){return attr.slice(-val.length)===val;},'*=':function(attr,val){return attr.indexOf(val)>-1;},'':function(attr,val){return attr;}},pseudos:{'root':function(node){return node===node.ownerDocument.documentElement;},'nth-child':function(node,val){return Y.Selector._getNth(node,val);},'nth-last-child':function(node,val){return Y.Selector._getNth(node,val,null,true);},'nth-of-type':function(node,val){return Y.Selector._getNth(node,val,node.tagName);},'nth-last-of-type':function(node,val){return Y.Selector._getNth(node,val,node.tagName,true);},'first-child':function(node){return Y.Selector._getChildren(node.parentNode)[0]===node;},'last-child':function(node){var children=Y.Selector._getChildren(node.parentNode);return children[children.length-1]===node;},'first-of-type':function(node,val){return Y.Selector._getChildren(node.parentNode,node.tagName)[0];},'last-of-type':function(node,val){var children=Y.Selector._getChildren(node.parentNode,node.tagName);return children[children.length-1];},'only-child':function(node){var children=Y.Selector._getChildren(node.parentNode);return children.length===1&&children[0]===node;},'only-of-type':function(node){return Y.Selector._getChildren(node.parentNode,node.tagName).length===1;},'empty':function(node){return node.childNodes.length===0;},'not':function(node,simple){return!Y.Selector.test(node,simple);},'contains':function(node,str){var text=node.innerText||node.textContent||'';return text.indexOf(str)>-1;},'checked':function(node){return node.checked===true;}},test:function(node,selector){node=Y.Selector.document.getElementById(node)||node;if(!node){return false;}
var groups=selector?selector.split(','):[];if(groups.length){for(var i=0,len=groups.length;i<len;++i){if(Y.Selector._test(node,groups[i])){return true;}}
return false;}
return Y.Selector._test(node,selector);},_test:function(node,selector,token,deDupe){token=token||Y.Selector._tokenize(selector).pop()||{};if(!node.tagName||(token.tag!=='*'&&node.tagName!==token.tag)||(deDupe&&node._found)){return false;}
if(token.attributes.length){var val,ieFlag,re_urls=Y.Selector._re.urls;if(!node.attributes||!node.attributes.length){return false;}
for(var i=0,attr;attr=token.attributes[i++];){ieFlag=(re_urls.test(attr[0]))?2:0;val=node.getAttribute(attr[0],ieFlag);if(val===null||val===undefined){return false;}
if(Y.Selector.operators[attr[1]]&&!Y.Selector.operators[attr[1]](val,attr[2])){return false;}}}
if(token.pseudos.length){for(var i=0,len=token.pseudos.length;i<len;++i){if(Y.Selector.pseudos[token.pseudos[i][0]]&&!Y.Selector.pseudos[token.pseudos[i][0]](node,token.pseudos[i][1])){return false;}}}
return(token.previous&&token.previous.combinator!==',')?Y.Selector._combinators[token.previous.combinator](node,token):true;},filter:function(nodes,selector){nodes=nodes||[];var node,result=[],tokens=Y.Selector._tokenize(selector);if(!nodes.item){for(var i=0,len=nodes.length;i<len;++i){if(!nodes[i].tagName){node=Y.Selector.document.getElementById(nodes[i]);if(node){nodes[i]=node;}else{}}}}
result=Y.Selector._filter(nodes,Y.Selector._tokenize(selector)[0]);return result;},_filter:function(nodes,token,firstOnly,deDupe){var result=firstOnly?null:[],foundCache=Y.Selector._foundCache;for(var i=0,len=nodes.length;i<len;i++){if(!Y.Selector._test(nodes[i],'',token,deDupe)){continue;}
if(firstOnly){return nodes[i];}
if(deDupe){if(nodes[i]._found){continue;}
nodes[i]._found=true;foundCache[foundCache.length]=nodes[i];}
result[result.length]=nodes[i];}
return result;},query:function(selector,root,firstOnly){var result=Y.Selector._query(selector,root,firstOnly);return result;},_query:function(selector,root,firstOnly,deDupe){var result=(firstOnly)?null:[],node;if(!selector){return result;}
var groups=selector.split(',');if(groups.length>1){var found;for(var i=0,len=groups.length;i<len;++i){found=Y.Selector._query(groups[i],root,firstOnly,true);result=firstOnly?found:result.concat(found);}
Y.Selector._clearFoundCache();return result;}
if(root&&!root.nodeName){root=Y.Selector.document.getElementById(root);if(!root){return result;}}
root=root||Y.Selector.document;if(root.nodeName!=='#document'){Y.Dom.generateId(root);selector=root.tagName+'#'+root.id+' '+selector;node=root;root=root.ownerDocument;}
var tokens=Y.Selector._tokenize(selector);var idToken=tokens[Y.Selector._getIdTokenIndex(tokens)],nodes=[],id,token=tokens.pop()||{};if(idToken){id=Y.Selector._getId(idToken.attributes);}
if(id){node=node||Y.Selector.document.getElementById(id);if(node&&(root.nodeName==='#document'||Y.Dom.isAncestor(root,node))){if(Y.Selector._test(node,null,idToken)){if(idToken===token){nodes=[node];}else if(idToken.combinator===' '||idToken.combinator==='>'){root=node;}}}else{return result;}}
if(root&&!nodes.length){nodes=root.getElementsByTagName(token.tag);}
if(nodes.length){result=Y.Selector._filter(nodes,token,firstOnly,deDupe);}
return result;},_clearFoundCache:function(){var foundCache=Y.Selector._foundCache;for(var i=0,len=foundCache.length;i<len;++i){try{delete foundCache[i]._found;}catch(e){foundCache[i].removeAttribute('_found');}}
foundCache=[];},_getRegExp:function(str,flags){var regexCache=Y.Selector._regexCache;flags=flags||'';if(!regexCache[str+flags]){regexCache[str+flags]=new RegExp(str,flags);}
return regexCache[str+flags];},_getChildren:function(){if(document.documentElement.children&&document.documentElement.children.tags){return function(node,tag){return(tag)?node.children.tags(tag):node.children||[];};}else{return function(node,tag){var children=[],childNodes=node.childNodes;for(var i=0,len=childNodes.length;i<len;++i){if(childNodes[i].tagName){if(!tag||childNodes[i].tagName===tag){children.push(childNodes[i]);}}}
return children;};}}(),_combinators:{' ':function(node,token){while((node=node.parentNode)){if(Y.Selector._test(node,'',token.previous)){return true;}}
return false;},'>':function(node,token){return Y.Selector._test(node.parentNode,null,token.previous);},'+':function(node,token){var sib=node.previousSibling;while(sib&&sib.nodeType!==1){sib=sib.previousSibling;}
if(sib&&Y.Selector._test(sib,null,token.previous)){return true;}
return false;},'~':function(node,token){var sib=node.previousSibling;while(sib){if(sib.nodeType===1&&Y.Selector._test(sib,null,token.previous)){return true;}
sib=sib.previousSibling;}
return false;}},_getNth:function(node,expr,tag,reverse){Y.Selector._re.nth.test(expr);var a=parseInt(RegExp.$1,10),n=RegExp.$2,oddeven=RegExp.$3,b=parseInt(RegExp.$4,10)||0,result=[],op;var siblings=Y.Selector._getChildren(node.parentNode,tag);if(oddeven){a=2;op='+';n='n';b=(oddeven==='odd')?1:0;}else if(isNaN(a)){a=(n)?1:0;}
if(a===0){if(reverse){b=siblings.length-b+1;}
if(siblings[b-1]===node){return true;}else{return false;}}else if(a<0){reverse=!!reverse;a=Math.abs(a);}
if(!reverse){for(var i=b-1,len=siblings.length;i<len;i+=a){if(i>=0&&siblings[i]===node){return true;}}}else{for(var i=siblings.length-b,len=siblings.length;i>=0;i-=a){if(i<len&&siblings[i]===node){return true;}}}
return false;},_getId:function(attr){for(var i=0,len=attr.length;i<len;++i){if(attr[i][0]=='id'&&attr[i][1]==='='){return attr[i][2];}}},_getIdTokenIndex:function(tokens){for(var i=0,len=tokens.length;i<len;++i){if(Y.Selector._getId(tokens[i].attributes)){return i;}}
return-1;},_patterns:{tag:/^((?:-?[_a-z]+[\w-]*)|\*)/i,attributes:/^\[([a-z]+\w*)+([~\|\^\$\*!=]=?)?['"]?([^\]]*?)['"]?\]/i,pseudos:/^:([-\w]+)(?:\(['"]?(.+)['"]?\))*/i,combinator:/^\s*([>+~]|\s)\s*/},_tokenize:function(selector){var token={},tokens=[],id,found=false,patterns=Y.Selector._patterns,match;selector=Y.Selector._replaceShorthand(selector);do{found=false;for(var re in patterns){if(YAHOO.lang.hasOwnProperty(patterns,re)){if(re!='tag'&&re!='combinator'){token[re]=token[re]||[];}
if((match=patterns[re].exec(selector))){found=true;if(re!='tag'&&re!='combinator'){if(re==='attributes'&&match[1]==='id'){token.id=match[3];}
token[re].push(match.slice(1));}else{token[re]=match[1];}
selector=selector.replace(match[0],'');if(re==='combinator'||!selector.length){token.attributes=Y.Selector._fixAttributes(token.attributes);token.pseudos=token.pseudos||[];token.tag=token.tag?token.tag.toUpperCase():'*';tokens.push(token);token={previous:token};}}}}}while(found);return tokens;},_fixAttributes:function(attr){var aliases=Y.Selector.attrAliases;attr=attr||[];for(var i=0,len=attr.length;i<len;++i){if(aliases[attr[i][0]]){attr[i][0]=aliases[attr[i][0]];}
if(!attr[i][1]){attr[i][1]='';}}
return attr;},_replaceShorthand:function(selector){var shorthand=Y.Selector.shorthand;var attrs=selector.match(Y.Selector._re.attr);if(attrs){selector=selector.replace(Y.Selector._re.attr,'REPLACED_ATTRIBUTE');}
for(var re in shorthand){if(YAHOO.lang.hasOwnProperty(shorthand,re)){selector=selector.replace(Y.Selector._getRegExp(re,'gi'),shorthand[re]);}}
if(attrs){for(var i=0,len=attrs.length;i<len;++i){selector=selector.replace('REPLACED_ATTRIBUTE',attrs[i]);}}
return selector;}};if(YAHOO.env.ua.ie&&((!document.documentMode&&YAHOO.env.ua.ie<8)||document.documentMode<8)){Y.Selector.attrAliases['class']='className';Y.Selector.attrAliases['for']='htmlFor';}})();YAHOO.register("selector",YAHOO.util.Selector,{version:"2.8.2r1",build:"7"});
