/********************************************************************

CHANGE
	FOREX.COM - ARTICLE VIEW
	
	=========================================
	Author: Dave Bobak (bobak@teehanlax.com)
	Agency: teehan+lax
	Date: September 12, 2008
	=========================================
	
	Article View is a class used to load in a full article into a seperate div, display it, and hide the current list.
	
	Public Methods
	-------------------------------------------------------------
	initialize (constructor)
		- Arguments:
			- listContainer (string): The container that holds the list of articles
			- viewContainer (string): The container that loads in the full article
		- Returns: null
		
	show
		Hides the list container and shows the view container. Specific controls are turned off (toggle winnow, related pair checkbox, see 20 more items (if applicable))	
		- Arguments: 
			- feedURL (URL): The URL for the full article feed fragment (passes to retrieveData function)
		- Returns: null
		
	hide
		Hides the view container and shows the list container. Other specific controls are turned on again.
		
	Internal "Private" Methods
	--------------------------------------------------------------
	retrieveData
		Grabs the data from the specified feedURL and populates it into the view container
		- Arguments:
			- feedURL (URL): The URL for the full article feed fragment
		- Returns: null
		
	CSS 
	-------------------------------------------------------------
	All styles relating to this Class reside in /resources/css/market.css 
	- Technically this is built to allow any list container name, and view container name, but in reality they are typically going to b
		- #article_content
		- #article_view

	Dependencies
	-------------------------------------------------------------
	- MooTools 1.2
	
*********************************************************************/

var ArticleView = new Class({
							   
    initialize: function(listContainer, viewContainer) {
		// Set properties		
		this.listContainer = $(listContainer);
		this.viewContainer = $(viewContainer);
    },
	
	show: function(feedURL) {
		// Set the width and height of the view container to the same as the list container
		this.viewContainer.setStyles({	
			height: this.listContainer.getStyle('height'),
			width: this.listContainer.getStyle('width')
		});
		
		// Do AJAX call and load response into container
		this.retrieveData(feedURL);
		
		// Hide list container
		this.listContainer.addClass('hidden_element');
		
		// Show view container
		this.viewContainer.removeClass('hidden_element');
		
		// Hide all related controls
		$$('div.related_content').addClass('hidden_element');
		$$('ul.content_toggle_links').addClass('hidden_element');
		$$('p.research_more').addClass('hidden_element');		
	},
	
	hide: function() {
		// Hide view container
		this.viewContainer.addClass('hidden_element');		
		
		// Show list container
		this.listContainer.removeClass('hidden_element');		

		// Show all related controls
		$$('div.related_content').removeClass('hidden_element');
		$$('ul.content_toggle_links').removeClass('hidden_element');
		$$('p.research_more').removeClass('hidden_element');		
	},
	
	retrieveData: function(feedURL) {

		var xmlRequest = new Request.HTML({url: feedURL, 
							
			onSuccess: function(responseTree, responseHTML) {
						
				// Find the parent node we are looking for
				$each(responseTree, function(item) {
				
					// Empty the view container
					this.viewContainer.empty();
					// Add the new content into the view container
					this.viewContainer.grab(item, 'top');
					
					// Set the position of the div container to the top
					var myScroll = new Fx.Scroll(this.viewContainer,{});
					myScroll.set(0,0);

				}, this); // end each
				
			}.bind(this), // end onSuccess						 

			onFailure: function() {
				
				
			}.bind(this)
		});
		xmlRequest.send();
	}		

});

