var detect = navigator.userAgent.toLowerCase();
var browser;

function checkIt(string)
{
	place = detect.indexOf(string)+1; //If the string doesn't exist, place will return 0
	return place;
}

if (checkIt('safari'))
	browser = 'safari';
else if (checkIt('firefox'))
	browser = 'firefox';
else if (checkIt('msie'))
	browser = 'ie';
else
	browser = 'other';

function changeOpacity (id, opac) {
	if (browser == 'firefox') {
		document.getElementById(id).style.MozOpacity = opac;
	}
	else if (browser == 'safari' || browser == 'other') {
		document.getElementById(id).style.opacity = opac;
	}
	if (browser == 'ie') {
		opacity = opac * 100;
		document.getElementById(id).style.filter = "alpha(opacity=" + opacity + ")"; 
	}
	
}

function rotateNews(numRows, thisStory) {
	timer = 0;
	seconds = 3;
	speed = seconds * 10;
	totalTime = 5 * 1000;
	
	for(j=0; j<numRows; j++) {
		changeOpacity("apNewsFeeds" + j, 0);
	}
	
	id = "apNewsFeeds" + thisStory;
	
	nextStory = (thisStory+1)%numRows;
	
	document.getElementById(id).style.display = "inline";
	
	for(a=0; a<100; a++) {
		b=a/100;
		c=1-b;

		setTimeout("changeOpacity(\'" + id + "\',"+b+")", (timer * speed));
		setTimeout("changeOpacity(\'" + id + "\',"+c+")", totalTime + (timer * speed));
		
		timer++;	
	}
	
	setTimeout("document.getElementById(id).style.display = \"none\"", totalTime+(timer*speed)+40);
		
	setTimeout("rotateNews("+numRows+", "+nextStory+")", totalTime+(timer*speed)+50);
}

//Code for rotating the pictures
function start() {
		
	if (browser == 'ie') {
		blendPictureL();
		setTimeout("blendPictureC();", 2000);
		setTimeout("blendPictureR();", 4000);
	}
	else if (browser == 'safari' || browser == 'firefox' || browser == 'camino') {
		changePictureL();
		setTimeout("changePictureC();", 2000);
		setTimeout("changePictureR();", 4000);
	}	
}

var oldnumL = 0;
var oldnumC = 15;
var oldnumR = 28;

function blendPictureL() {
	var picnum = (oldnumL+9)%43;
	
	document.getElementById('blendL').filters.blendTrans.Apply();
	document.getElementById('blendL').src = "images/pics/pic" + picnum + ".jpg";
	document.getElementById('blendL').filters.blendTrans.Play();
	oldnumL = picnum;
	blendpic = setTimeout("blendPictureL();", 6000);
}

function blendPictureC() {
	var picnum = (oldnumC+9)%43;
	
	document.getElementById('blendC').filters.blendTrans.Apply();
	document.getElementById('blendC').src = "images/pics/pic" + picnum + ".jpg";
	document.getElementById('blendC').filters.blendTrans.Play();
	oldnumC = picnum;
	blendpic = setTimeout("blendPictureC();", 6000);
}

function blendPictureR() {
	var picnum = (oldnumR+9)%43;
	
	document.getElementById('blendR').filters.blendTrans.Apply();
	document.getElementById('blendR').src = "images/pics/pic" + picnum + ".jpg";
	document.getElementById('blendR').filters.blendTrans.Play();
	oldnumR = picnum;
	blendpic = setTimeout("blendPictureR();", 6000);
}

function changePictureL() {
	var millisec = 2000;
	var speed = Math.round(millisec/100);
	var timer = 0;
	var picnum = (oldnumL+9)%43;
	
	document.getElementById('picLeft').style.background = "url(images/pics/pic" + oldnumL + ".jpg) no-repeat";
	changeOpacity('blendL', 0);
	document.getElementById('blendL').src = "images/pics/pic" + picnum + ".jpg";
	for (i=0; i<=99; i++) {
		j=i/100;
		setTimeout("changeOpacity('blendL',"+j+")", (timer * speed));
		timer++;
	}
	oldnumL = picnum;
	setTimeout("changePictureL()", 6000);
}

function changePictureC() {
	var millisec = 2000;
	var speed = Math.round(millisec/100);
	var timer = 0;
	var picnum = (oldnumC+9)%43;
	
	document.getElementById('picCent').style.background = "url(images/pics/pic" + oldnumC + ".jpg) no-repeat";
	changeOpacity('blendC', 0);
	document.getElementById('blendC').src = "images/pics/pic" + picnum + ".jpg";
	for (i=0; i<=99; i++) {
		j=i/100;
		setTimeout("changeOpacity('blendC',"+j+")", (timer * speed));
		timer++;
	}
	oldnumC = picnum;
	setTimeout("changePictureC()", 6000);
}

function changePictureR() {
	var millisec = 2000;
	var speed = Math.round(millisec/100);
	var timer = 0;
	var picnum = (oldnumR+9)%43;
	
	document.getElementById('picRight').style.background = "url(images/pics/pic" + oldnumR + ".jpg) no-repeat";
	changeOpacity('blendR', 0);
	document.getElementById('blendR').src = "images/pics/pic" + picnum + ".jpg";
	for (i=0; i<=99; i++) {
		j=i/100;
		setTimeout("changeOpacity('blendR',"+j+")", (timer * speed));
		timer++;
	}
	oldnumR = picnum;
	setTimeout("changePictureR()", 6000);
}