﻿/**
 * Class to load an article using ajax
 * 
 * @version		1.1		01.04.10		Unprototyped
 */

function	tcArticleLoader()	{

//	this.init	=	function()	{
//		this.isLoading	=	false;
//	}

	/**
	 * Begin the loading of an article
	 *
	 * @param		Number		id
	 * @param		Number		Thumb type
	 * @param		Number		Image type
	 *
	 */
	 
	this.loadArticle		=	function( id, thumbtype, imgtype  )	{

		this.showLoading();
		var	aurl	=	'/code/ajaxcall.php?module=article&action=getarticlebyid&id=' + id + "&thumbtype=" + thumbtype + "&imgtype=" + imgtype;

		var myloader = function( jsonObj ) {
			this._onloadcallback( jsonObj );
		}.create({bind : this});
	
		var request = new Request.JSON({
			url: aurl,
			onComplete: function( jsonObj ) {
				myloader( jsonObj.TC_ARTICLE );
			}
		}).send();
	}

	this._onloadcallback	=	function	(e)	{

		if( this.onloadusercallback )	{
			this.onloadusercallback(e);
		}	
		this.hideLoading();
	}

	this.setOnLoadCallback	=	function( cb )	{	this.onloadusercallback	=	cb;		}
	this.showLoading		=	function()		{	this.isLoading		=	true;		}
	this.hideLoading		=	function()		{	this.isLoading		=	false;		}

	// Construct
	this.isLoading		=	0;
	this.onloadusercallback	=	null;
}
