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


//flashtagger();


});



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




// ---- Main feature animation----




//select all of the newsitems
newsitems = $$('#news .newsitem');

newsArray = Array();

//set them all invisible and create array of IDs
newsitems.each(function(element){

	element.setStyle('opacity','0');
	element.setStyle('display','block');	
			var elName = element.getProperty('id');
			var arr = elName.split("_");
			var id = arr[1]; 
			newsArray.push(id); 

});




if (!$('flashfeature')) { //only do the feature animation if a flash-based feature is not present



	//get the width of the feature
	featureWidth = $('feature1').getStyle('width').toInt();
	
	//calculate the left position for line2
	leftx=($('line2').getStyle('left').toInt())
	
	//get the x coord of the sliding text from the css
	rightx = (featureWidth - leftx) + 5;
	
	
	$('feature1').setStyle('opacity','0');
	$('line1').setStyle('right', featureWidth);
	$('line2').setStyle('left', featureWidth);
	$('line3').setStyle('opacity','0');
	
	
	var fadePhoto = new Fx.Morph('feature1', {duration:1000, wait:false});
	var slideLine1 = new Fx.Morph('line1', {duration:1800, transition:Fx.Transitions.Quart.easeOut, wait:false});
	var slideLine2 = new Fx.Morph('line2', {duration:1800, transition:Fx.Transitions.Quart.easeOut, wait:false});
	var fxLine3 = new Fx.Morph('line3', {duration:1000, transition:Fx.Transitions.Quart.easeOut, wait:false});
	//var fxLine4 = new Fx.Styles('line4', {duration:1000, transition:Fx.Transitions.Quart.easeOut, wait:false});
	
	fadePhoto.start ({'opacity':'1'});
	slideLine1.start.delay (500, slideLine1, {'right' : rightx +'px' });
	slideLine2.start.delay (500, slideLine2, {'left' : leftx +'px' });
	fxLine3.start.delay (2700, fxLine3, {'opacity':1});
	//fxLine4.start.delay (3700, fxLine4, {'opacity':1});

}


// ----- News column animation -----




//setup the loop

//set the first item visible
$('ni_'+newsArray[0]).setStyle('opacity','1');

itemCount=1; //start at key 1 since key 0 is already showing
totalItems = (newsArray.length);
lastItemKey = (totalItems-1);


newsFade = function() {


	//if we're not at the beginning of the Array
	//fade out the previous item
	//If we are at the beginning, fade out
	//the the last item of the array
	if (itemCount != 0) {
	
		var pastItem = 'ni_'+newsArray[itemCount-1];
		
	} else {
	
		var pastItem = 'ni_'+newsArray[lastItemKey];		
	}
	
	var fadeOut = new Fx.Morph(pastItem, {duration:700, wait:false});
	var fadeIn = new Fx.Morph('ni_'+newsArray[itemCount], {duration:500, wait:false});
	
	fadeOut.start({'opacity':'0'});
	fadeIn.start({'opacity':'1'});
	
	//if we've reached the end of the Array
	//set the counter back to the beginning
	if (itemCount >= lastItemKey) {
	
		itemCount = 0;
	
	} else {
	
		itemCount++;
	}


}

//Only loop through the newsitems if there
//are two or more items
if (totalItems >= 2) {
	var newsloop = newsFade.periodical(12000,newsFade);
}





}); //close onLoad handler