// JavaScript Document

document.observe('dom:loaded', function(){
		var existing = new Array(0);
		var rand = makeRandom(existing);
		existing.push(rand);
		showRandomPic("1",rand);
		rand = makeRandom(existing);
		existing.push(rand);
		showRandomPic("2",rand);
		rand = makeRandom(existing);
		showRandomPic("3",rand);
		var theThumbs = $$('.homenewsthumb');
		theThumbs.each(function(elt){
								var theImage = elt.readAttribute('rel');
								elt.onmouseover = function() { showSummary(theImage);}
								elt.onmouseout = function() { $('newstext').replace('<div id="newstext"></div>');}
								});
	 });

function makeRandom(existing)
{
	var max = newsStories.length;
	var min = newsStories.length - 9;
	var rand = Math.floor(Math.random()*max);
	rand += 1;
	while(existing.indexOf(rand) > -1 || rand < min){
		rand = Math.floor(Math.random()*max);
		rand += 1;
	}
	return rand;
}

function showSummary(id)
{
	var theStory = getNews(id);
	var theInsert = '<div id="newstext"><h1 class="home">' + theStory.headline + '</h1><p>' + theStory.summary + '</p>';
	theInsert += '</div>';
	$('newstext').replace(theInsert);
}

function showRandomPic(thumb,rand)
{
	var theStory = getNews(rand);
	$('newsthumb' + thumb).writeAttribute({ src: 'Images/' + theStory.thumb });
	$('newslink' + thumb).writeAttribute({href: 'news.html?story=' + rand });
	$('newsthumb' + thumb).writeAttribute({rel: rand});
}