// newsbox.js
// Created by Ryan of KNR Designs
// Allows switching between different items in the news box.
// Add more items below. HTML is supported, and is needed to add images. If it's too big, the text will disappear.

// Change only this array. Make sure to escape the single quotes like this: \'
// Or else the script won't work properly.
// Add items in the order that you wish them to appear.

var newsarr = new Array	(

	'<p><a href="http://www.collegegrad.com/jobsearch/Competitive-Interview-Prep/The-One-Thing-You-Must-Do-Before-Your-First-Interview/"><img src="template/images/interview.JPG" alt="News Image" /></a>.</p>',				

	'<p><a href="http://www.expressbuzz.com/edition/story.aspx?Title=Know+your+prime+minister&artid=JKtS0XHQTbU=&SectionID=b7ziAYMenjw=&MainSectionID=b7ziAYMenjw=&SectionName=pWehHe7IsSU=&SEO=pm,%20manmohan,%20profile,%20career"><img src="template/images/Know your PM.JPG" alt="News Image" /></a>.</p>',

	'<p><a href="http://www.mindpowerindia.com/free-articles-all/01-success-secrets-and-motivation-from-steve-jobs.htm"><img src="template/images/steve jobs.JPG" alt="News Image" /></a>.</p>'
) ;

// This is how fast we go, in seconds, you can use decimal to signify half seconds and such.
var speed = 5 ;



// Do not change these next variables, they are required for the script to work.
var newsitem = 2 ;	// This is the item we are currently on, and that which we start on.
var paused = false ;	// This tells us if we are paused or not.
var numitems = newsarr.length ;	// The number of news items we have to display.
var newsbox = null ;
var newscontrols = null ;
var pausebutton = null ;


function setids ( )	{
	newsbox = document.getElementById ( "newsbox" ) ;
	newscontrols = document.getElementById ( "newscontrols" ) ;
	pausebutton = document.getElementById ( "pausebutton" ) ;
}


// Now begin the functions, do not change anything here unless you know what you are doing.

function prev ( )	{
	
	var prev = newsitem - 1 ;	// This is the previous item, unless we are at 0, in which case we loop back around.
	
	if ( prev < 0 )	{	// If we have a number that is less than 0, then we will loop back around to the top.
		prev = numitems - 1 ;
	}
	
	newsitem = prev ;
	newsbox.innerHTML = newsarr[prev] ;	// We set the HTML in the box to what's in the array.
}


function next ( user )	{
	if ( user != true && paused )	{
		return false ;
	}
	
	var next = newsitem + 1 ;	// This is the next item, unless we are at the top, in which case we loop back around.
	
	if ( next >= numitems )	{	// If we have a number that is greater than the number of items, then we will loop back around to the bottom.
		next = 0 ;
	}
	
	newsitem = next ;
	newsbox.innerHTML = newsarr[next] ;	// We set the HTML in the box to what's in the array.
}


function playpause ( )	{
	if ( paused )	{
		paused = false ;
		pausebutton.src = "images/pausebutton.gif" ;
	}
	else	{
		paused = true ;
		pausebutton.src = "images/playbutton.gif" ;
	}
	
}

window.onload = setids ;	// This function will set our ids when the page is finished loading.

setInterval ( next , speed * 1000 ) ;
