// This jQuery plugin will gather the excerpt from an jQuery Collection within the html comment tags
// Start <!--StartFeed-->
// End <!--EndFeed-->
//
// 
var start = (start || false);
var end = (end || false); 

jQuery.fn.excerpt = function( ){

var jExcerpt = $( [] );
var ThisNode=this;
var objNode=$(this)[0]; 
//stops the function if start and end tags have been reached
if(start && end){return(jExcerpt);}

// Loop over each node to search its children for
// comment nodes and element nodes (if deep search).		
		var objChildNode = objNode.childNodes[0];
		var strParentID = $( this ).attr( "id" );
		var strParentType= objNode.nodeName;
		var arrParentAttr = objNode.attributes;


// Keep looping over the top-level children
// while we have a node to examine.
		var childNodes= $([]);
		while (objChildNode){
			//check if this ChildNode has children
			if(objChildNode.childNodes.length>0)
				{
				//subLoop to cycle through the childNodes 	
 				jExcerpt = jExcerpt.add($(objChildNode).excerpt());
				if(end){return(jExcerpt);}
				}else{

// Check to see if this node is a comment.
			if (objChildNode.nodeType === 8)
			{
			if(objChildNode.nodeValue=="StartFeed")
				{
//start collecting the text;
				start=true;	
				}
			if(objChildNode.nodeValue=="EndFeed")
				{
//stop collecting the text
				end=true;	
				}
//this node is not a comment
			} 
//end else node has no children				
		}
if (start && end){objChildNode=null;}else{
	childNodes= childNodes.add(objChildNode);
// Move to the next sibling.
objChildNode = objChildNode.nextSibling;
}
//END while(objChildNode)
	}
if(start){
//need to wrap the current jComments object with this tag
	//rough to eleminate empty text nodes
	var NewNode='';
					for(var i=0;i<childNodes.length;i++)
						{
						var txtStr= jQuery.trim(childNodes[i].textContent);
						if(childNodes[i].nodeType!=3 || txtStr!='')
							{
						
							if(childNodes[i].outerHTML)
						  		{
							  	var a=childNodes[i].outerHTML;
						  		}else{
							  	var a=childNodes[i].textContent;
									if(a=="")
										{
										var nodeAttr = childNodes[i].attributes
										var strAttr= ''
										$(nodeAttr).each(function(){
											strAttr = strAttr+' '+this.name+'="'+this.nodeValue+'"';
										});
										 a = '<'+childNodes[i].nodeName+' '+strAttr+' />';
										
										}
						  		}	
							NewNode=NewNode+a;	
							}
						}
					
					var strAttr = ' ';
						for(var i=0; i<arrParentAttr.length; i++)
						  {
							   strAttr=strAttr+ ' ' + arrParentAttr[i].name+'="'+arrParentAttr[i].nodeValue+'"';
						  }
					var NewNode= '<'+strParentType+strAttr+'>'+NewNode+'</'+strParentType+'>';
					//jExcerpt = jExcerpt.add(a);
						}
// Return the jQuery comments collection.
return( NewNode );
}

