// JavaScript Document
var AtomFeedComponent = Class.create();

Object.extend(AtomFeedComponent.prototype,
			{
				 
				initialize : function(container){
					
					this.container = $(container);
					this.serviceHandle = this.handleService.bind(this);
				
				},
				handleService : function(xml){
					 
					this.buildDisplay(xml);							
				
				},
				buildDisplay : function(xml){
					
					var collection = $A(xml.getElementsByTagName("entry")).collect(this.buildEntry.bind(this));
					
					this.container.innerHTML = "";
					this.container.setOpacity(0);
					
					collection.each(this.appendContainer.bind(this));							
				
					Effect.Appear(this.container, { queue : "end" });
				
				},
				buildEntry : function(obj){
					
					var link = $C("a", { target : "_blank", href : this.getAlternateLink(obj), innerHTML : obj.getElementsByTagName("title").item(0).firstChild.nodeValue });
					
					var paragraph = $C("p", { innerHTML : obj.getElementsByTagName("summary").item(0).firstChild.nodeValue });
					
					var container = $C("div");
					
					container.appendChild(link);
					
					container.appendChild(paragraph); 
					
					return container;							
					
				
				},
				getAlternateLink : function(obj){
					
					try{
						return $A(obj.getElementsByTagName("link")).detect(this.detectAlternateLink).getAttribute("href");						
					}
					catch(e){
						return "#blank";	
					}
					
				},
				detectAlternateLink : function(obj){
					
					return obj.getAttribute("rel").toLowerCase() == "alternate";
					
				},
				getSelfLink : function(obj){
					try{
						return $A(obj.getElementsByTagName("link")).detect(this.detectSelfLink).firstChild.nodeValue;						
					}
					catch(e){
						return "";	
					}
					
					
				},
				detectSelfLink : function(obj){
						
					return obj.getAttribute("rel").toLowerCase() == "self";
					
				},
				appendContainer : function(ele){
					
					this.container.appendChild(ele);
				
				}					
			}
		);
					
