/////////////////////////////////////////////////////////////////////////////////////////
// ARTICLES
/////////////////////////////////////////////////////////////////////////////////////////

/**
	@param id 		Number	article id
	@param section		String	Specific section references section in archives.xml
	@param element		Object	Element to dump contents into and scale
	
	* Note the 'bind' on the event handlers , binds to this class
	
	* should auto cancel upon new request, need to test this
*/

var ArticleClass = new Class({

	initialize: function(id, section, element){
			
		this.id = id;
		this.section = section;
		this.element = element;
		
		this.getArticleData();
	},
	
	//retrieve the article url
	getArticleData: function(){

		var article = getArticle( this.id, this.section );	
		this.getArticle( article );
	},
	
	//load the article
	getArticle: function( article ){
	
		article = article + "?date=" + new Date().getTime();
		new Ajax(article, {
			evalScripts:true,  /* IMPORTANT, evalScripts is necessary if you want to run any code in the loaded page */
			autoCancel: true,
			method: 'get',
			update: $(this.element),
			//onFailure: showError(),  //always shown for some reason
			onSuccess: this.onArticleLoaded.bind(this)
		}).request();
	},
	
	onArticleLoaded: function( response ){
	
		this.fireEvent( 'onArticleLoaded', {id:this.id, section:this.section, element:this.element}, 50 );
	}
	
});
/* allow our class to broadcast events to anyone listening */
ArticleClass.implement(new Events);