dojo.extend(dojo.NodeList, {
	/**
	 * shows selected nodes
	 */
    show: function(){
		 this.forEach(function(item){
	         item.style.display='block';
	     });
        return this;
    },
    /**
     * hides selected nodes
     */
   hide: function(){
        this.forEach(function(item){
        	item.style.display='none';
        });
       return this;
    },
    /**
     * shows or hides selected nodes according to their actual status
     */
    toggle: function(){
        this.forEach(function(item){
            if(item.style.display=='none'){
            	item.style.display='block';
           } else {
        	   item.style.display='none';
            }
        });
        return this;
    },
    
    /**
     * Selects following tag at the same level, if nodeType is specified, first following tag at same level of selected type is selected
     */
    next: function(nodeType){
			if(typeof(nodeType) == "undefined") nodeType=false;
	        var result = dojo.NodeList();
	        this.forEach(function(node){
	                var next = node.nextSibling;
	                var last = node;
	                if(nodeType){
	                   do{ 
	                	   while(next && next.nodeType != 1 ){
	   	                    	next = next.nextSibling;
	   	                   }
	                	   if(typeof(next.isSameNode) != "undefined"){
		   	                   if(!next || next.isSameNode(last)){
			   	                   next=null;
			   	                   break;
		   	                   }
	                	   } else {
	                		   if(!next || next == last){
	                			   next=null;
	                			   break;
	                		   }
	                	   }
	   	                   last = next;
	   	                   if(next.tagName.toLowerCase() == nodeType.toLowerCase()){
		   	                   break;
	   	                   }
	                   } while(next);
	                } else {
	                    while(next && next.nodeType != 1 ){
	                    	next = next.nextSibling;
	                    }
	                }
	                if(next){
	                	result.push(next);
	                } 
	        });
	        return result;
	},
	
	/**
     * Selects previous tag at the same level, if nodeType is specified, first previous tag at same level of selected type is selected
     */
	prev: function(nodeType){
		if(typeof(nodeType) == "undefined") nodeType=false;
	    var result = dojo.NodeList();
	    this.forEach(function(node){
	            var prev = node.previousSibling;
	            var last = node;
	            if(nodeType){
	               do{ 
	            	   while(prev && prev.nodeType != 1 ){
		                    	prev = prev.previousSibling;
	                   }
	            	   if(typeof(prev.isSameNode) != "undefined"){
	            		   if(!prev || prev.isSameNode(last)){
	       	                   prev=null;
	       	                   break;
    	                   }
	            	   } else {
	            		   if(!prev || prev == last){
	            			   prev=null;
	       	                   break;
	            		   }
	            	   }
	                   
	                   last = prev;
	                   
	                   if(prev.tagName.toLowerCase() == nodeType.toLowerCase()){
	                	   break;
	                   }
	               } while(prev);
	            } else {
	                while(prev && prev.nodeType != 1 ){
	                	prev = prev.previousSibling;
	                }
	            }
	            if(prev){
	            	result.push(prev);
	            }
	    });
	    return result;   
	},
	
    /**
     * sets content to all selected nodes
     */
    setContent: function(html){
    	this.forEach(function(item){
	         dojo.html.set(item, html);
	     });
    	return this;
    },
    /**
     * gets innerHTML content from first selected node
     */
    getContent: function(){
    	if(this.length == 0) return null;
    	return this.at(0).attr("innerHTML");
    }
});
