function topStorObj(){
	document.write( '<div id="topStoryCycleFlag" style="position:absolute; visibility:hidden; overflow:hidden; top:0px; left:0; width:0; height:0">-1</div>' );
	this.setCycleFlag = function( value ){
		if( document.getElementById('topStoryCycleFlag') ){
			document.getElementById('topStoryCycleFlag').innerHTML = value;
		}
	};
	this.getCycleFlag = function(){
		if( document.getElementById('topStoryCycleFlag') ){
			return document.getElementById('topStoryCycleFlag').innerHTML;
		}
		return;
	};
	this.doCycle = function(){
		delay = this.cycleSecond * 1000;
		if( delay ){
			this.rotation = setTimeout( "topStory.doCycle();", delay );
		}
		if( this.getCycleFlag() > 0 ){
			this.navigation('cycle');
		}
		if( this.getCycleFlag() == '-1' ){ this.setCycleFlag( 1 ); }
	};
	this.selected = -1;
	this.cycleSecond = 10;
	this.obj = function(){};
	this.add = function( bgImg, title, blurb, url, links, blurbColor ){
		if( ! this.story ){ this.story = new Array();}
		i = this.story.length;
		this.story[i] = new this.obj();
		this.story[i].bgImg 		= bgImg;
		this.story[i].title 		= title;
		this.story[i].blurb 		= blurb;
		this.story[i].url 		= url;
		this.story[i].links 		= links;
		this.story[i].blurbColor	= blurbColor;	
	};
	this.view = function( id, cycle ){
		if(( id < this.story.length ) && ( id >= 0 ))
		{
			this.selected = id;
       			document.getElementById('banner_img_bg').style.background = 'url(' + this.story[id].bgImg +') top center no-repeat';
       			document.getElementById('banner_img_bg').style.backgroundColor = '#000';
			if (this.story[id].url !== ''){
				fullStory = '<strong><a href="'+ this.story[id].url +'" id="main_article_link">read more</a></strong>';
                		document.getElementById('img_bann_anchor').setAttribute("href",this.story[id].url);
			}
			else
			{
				fullStory = '';
                		document.getElementById('img_bann_anchor').removeAttribute("href");
			}
			document.getElementById('text_bann_title').innerHTML = this.story[id].title;
			document.getElementById('text_bann_quote').innerHTML = this.story[id].blurb + '&nbsp;' +  fullStory;
       			document.getElementById('text_bann_quote').style.color = this.story[id].blurbColor;
       			document.getElementById('main_article_link').style.color = this.story[id].blurbColor;
			document.getElementById('text_bann_links').innerHTML = this.story[id].links;
			if( ! cycle ){
				clearTimeout(this.rotation);
				this.cycleSecond = 0;
				this.setCycleFlag(0);
			}
			for( j=0; j < this.story.length; j++ ){
				document.getElementById('topStory_link_' + j).style.color = ( j == id ) ? '#ff0' : '#fff';
				document.getElementById('topStory_link_' + j).style.fontWeight = ( j == id ) ? 'bold' : 'normal';
			}
		}
	}
	this.navigation = function( command ){
		if( command == 'prev' ){
			change = ( this.selected === 0 ) ? this.story.length-1 : this.selected - 1 ;
			this.view( change );
		}else if( command == 'pause' ){
			this.cycleSecond = 0;
			this.setCycleFlag(0);
		}else if( command == 'next' ){
			change = ( this.selected == this.story.length-1  ) ? 0 : this.selected + 1 ;
			this.view( change );
		}else if( command == 'cycle' ){
			change = ( this.selected == this.story.length-1  ) ? 0 : this.selected + 1 ;
			this.view( change, true );
		}else{
			this.view( 0 );
		}
	}
}
topStory = new topStorObj();
topStory.doCycle();