function NewsArticle(headline, teaser, photo, id, morelink)
{
	this.headline = headline;
	this.teaser = teaser;
	this.photo = photo;
	this.id = id;
	this.morelink = morelink;
	
	this.getHeadline = function()
	{
		return this.headline;
	}
	
	this.getTeaser = function()
	{
		return this.teaser;
	}
	
	this.getPhoto = function()
	{
		return this.photo;
	}
	
	this.getId = function()
	{
		return this.id;
	}
	
	this.getMoreLink = function()
	{
		return this.morelink;
	}
}

function BlurArticle(id)
{
	var source = articles[id];
	
	if( document.getElementById && source )
	{
		// set behind-image to the current image
		var tempsrc = GetElement("article-photo").src;

		GetElement("article-fadepair").src=tempsrc.length>0?tempsrc:source.getPhoto();
		// now full-alpha the front image (so we see the behind image)
		SetOpacity(0, "article-photo");
		
		// set the front image to the new one
		GetElement("article-photo").src = source.getPhoto();
		
		// and fade in the new image
		Fade("article-photo", 0, 100, 500);
		
		// swap textual elements
		GetElement("article-headline").innerHTML = source.getHeadline();
		GetElement("article-teaser").innerHTML = source.getTeaser();
		GetElement("article-more").href=source.getMoreLink();
	}
}

function GetElement(id)
{
	return document.getElementById(id);
}

/* slide show funcs */
var swapActive = true;
var delay = 8000;

function StartHeadlineTimer(idx)
{
	window.setTimeout("SwapHeadlines(" + idx + ");", delay);
}

function StopTimer()
{
	swapActive = false;
}

function SwapHeadlines(index)
{
	if( swapActive == true )
	{
		if( index >= sequence.length )
			index = 0;
			
		BlurArticle(sequence[index]);
		StartHeadlineTimer(index+1);
	}
}

// start slide show
StartHeadlineTimer(1);

/* 
	Script to support fading of elements over time
	and crossfading images
	
	v.1.0 
	3/31/06
	Kam Figy
	
	Loosely based on original code from http://www.brainerror.net/scripts_js_blendtrans.php
*/

function Fade(id, alphaStart, alphaEnd, duration) {
	//speed for each frame
	var speed = Math.round(duration / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(alphaStart > alphaEnd) {
		for(i = alphaStart; i >= alphaEnd; i--) {
			setTimeout("SetOpacity(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(alphaStart < alphaEnd) {
		for(i = alphaStart; i <= alphaEnd; i++)
			{
			setTimeout("SetOpacity(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function SetOpacity(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}


/*

	Stopped StartHeadlineTimer();
	
	Script for next/previous button. 
	uses jquery
	
	Michael Brevig
	05/29/07
*/

runNextPrev = function(ary,direction){
	
	var cnt = ary.length -1;
	
	StopTimer();
	
	if( cnt == 0 ){
		return false;
	}//end if
	
	if( direction == 'next' ){
		var next = $('#next').attr('plink');
		next = parseInt(next);
		
		if( !next && next != 0){
			next = 1;
		}
		
		if( next > cnt  )  {
		
			$('#previous').attr('plink',cnt);
			$('#next').attr('plink',1);
			BlurArticle(ary[0]);
			//return false;
		}//end if
		
		if( next <= cnt ){
			
				
			$('#previous').attr('plink',next);
			nextpl = next + 1;
			$('#next').attr('plink',nextpl);
			BlurArticle(ary[next]); 
			return false;
		}//end 
		
	}
	
	if( direction == 'previous') {
		
		var prev = $('#previous').attr('plink');
		
		
		prev = parseInt(prev);
		if( !prev && prev != 0){
			prev = 0;
		}
		
		if( prev == 0 ){
			 //alert(prev)
			 $('#previous').attr('plink',cnt);
			 $('#next').attr('plink',0);
			 BlurArticle(ary[cnt]);
			 return false;
		}else{
			//alert(prev);
			 $('#previous').attr('plink',prev-1);
			 $('#next').attr('plink',prev);
			 BlurArticle(ary[prev-1]);
			 return false;
		}
		
	}//end if
	
}//end function