﻿ss						=	null;
al						=	null;

l_currnewsidx 			= 	0;
l_currentid				=	0;
newsrolltime			=	7000;
nr						=	null;

window.addEvent('domready', function() {

	if( $('imagebuffer'))	{

		ss	=	new	tcImageLoader();

		ss.setImageBuffer( 'imagebuffer' );
		ss.setImage( 'themainimage' );
//		ss.setThumbType(g_imgthumbtype);
		ss.setOnLoadCallback(userOnloadCallback);
		ss.setLoadingDisplay( 'loadingdisplay', '/resources/images/slideshow/loading-button.gif' );
		ss.init();		

// THis is for the standard clicked loaded
//		al	=	new	tcArticleLoader();
//		al.setOnLoadCallback(userOnloadArticleCallback);

		ss.loadImage(firstthumb);

// This is for the automated roller
		if( newscount > 1)	{
			nr	=	new	tcArticleLoader();
			nr.setOnLoadCallback(userNewsOnloadArticleCallback);
		}
		l_currnewsidx 			= 	0;
		doTimedLoad();
	}
});


function	userOnloadArticleCallback( art )	{
	ss.loadImage( art.d_thumbimageurl );

	var		artlink	= '/news/show/' + art.d_categoryniceid + '#' + art.niceid;

	$('heading').set('text', art.title);

//	$('thetext').set('text', art.subtitle);

// This is to stop the &amp; from being re-encoded
	$('thetext').innerHTML = art.subtitle;
	
	new	Element('br').inject($('thetext'));
	new Element('a', {'href':  artlink, 'text' : 'Read More ...' }).inject($('thetext'));
}

/* 
	This is called when the image has loaded
*/

function	userOnloadCallback( e )	{

	// Update the onscreen description
//	$('heading').set('text', e.name);
//	$('thetext').set('text', e.title);
}


function	loadNewItem(fname)	{
	ss.loadImage(fname);
}

function	loadNewArticle( id )	{
	al.loadArticle(id, g_imgthumbtype, g_imgtype);
}

// ==============================

function	userNewsOnloadArticleCallback( art )	{
	userOnloadArticleCallback(art);
	doTimedLoad();
}

function	_doTimedLoad()	{
	if(++l_currnewsidx >= newscount)	{
		l_currnewsidx = 0;
	}
	nr.loadArticle(newsroll[l_currnewsidx], g_imgthumbtype, g_imgtype);
}

function	doTimedLoad()	{
	_doTimedLoad.delay( newsrolltime );
}
