//pre-load images
var autoImg = new Image();
autoImg.src = 'media/News.gif';
var mpfm50Img = new Image();
mpfm50Img.src = 'media/MPFM-50.gif';
var ow200Img = new Image();
ow200Img.src = 'media/OW-200 Series.gif';
var ow300Img = new Image();
ow300Img.src = 'media/OW-300 Series.gif';
var id200Img = new Image();
id200Img.src = 'media/ID-200 Series.gif';

function makeNews(t,c,l,f,i,lo){
	this.title = t;
	this.copy = c;
	this.link = l;
	this.follow = f;
	this.img = i;
	this.location = lo;
	this.write = writeNews;
}

function writeNews(){
	var str = '<table border="0" cellpadding="0" cellspacing="0" width="100%" height="199" bgcolor="#F0F0F0"><tbody>';
	str += '<th><b><font face="Verdana,Geneva,Arial,Helvetica" size="1">' + this.title + '</font></b></th>'
	str += '<tr><td align="center"><a href="' + this.location + '">';
	str += '<img src="' + this.img.src + '"></a></td></tr><br>';
	str += '<tr><td style="padding-left: 9px; padding-right: 3px"><b><font face="Verdana,Geneva,Arial,Helvetica" size="1">' + this.copy + '</font></b></td></tr>';
    str +=  '<tr><td align="center"><font face="Verdana,Geneva,Arial,Helvetica" size="1"><a href="' + this.link + '">' + this.follow + '</a></tr></font></td>';
	str += '</tbody></table>';
	return str;
}

var productArray = new Array(4);
productArray[0] = new makeNews("MPFM-50 Series","The AGAR MPFM-50 Series is a true multiphase flow meter that provides on-line, real-time well production information for the entire production flow stream.",'flowmeters.html','Learn More',mpfm50Img,'flowmeters.html').write();
productArray[1] = new makeNews("OW-200 Series","Agar’s OW-200 series is a second-generation design, microwave based liquid/liquid analyzer developed by Agar Corporation after introducing the first 0-100% water cut monitor to the market in 1985.",'watercut_meters.html','Learn More',ow200Img,'watercut_meters.html').write();
productArray[2] = new makeNews("ID-200 Series","The ID-200 Series Interface Detectors are used for interface measurement and control in all types of liquid/liquid and vapor/liquid separation processes.",'detectors.html','Learn More',id200Img,'detectors.html').write();
productArray[3] = new makeNews("OW-300 Series","Agar’s OW-300 Series monitors are used to measure the complex permittivity properties of the flow stream using the multiple high frequency method, which will compensate for the effects of changing hydrocarbon composition and water salinity.",'watercut_meters.html','Learn More',ow300Img,'watercut_meters.html').write();
productArray[4] = new makeNews("ID-200 Series","The ID-200 Series Interface Detectors are used for interface measurement and control in all types of liquid/liquid and vapor/liquid separation processes.",'detectors.html','Learn More',id200Img,'detectors.html').write();

var newsArray = new Array(4);
newsArray[0] = new makeNews("Agar Corporation Canada","Agar Corporation Expands its Operational Base to Canada.",'News.html#Anchor-Agar-1234','Read More',autoImg,'News.html').write();
newsArray[1] = new makeNews("Agar develops 2-wire system","Agar Soon to Offer its New 2-Wire 24VDC Loop Powered ID-200.",'News.html#Anchor-Agar-1235','Read More',autoImg,'News.html').write();
newsArray[2] = new makeNews("Agar's Training Forum","Agar Training Forum - Next Session Starts February 4th.",'News.html#Anchor-Agar-1236','Read More',autoImg,'News.html').write();
newsArray[3] = new makeNews("Upcoming Events","Upcoming Events.",'News.html#Anchor-Agar-1237','Read More',autoImg,'News.html').write();
newsArray[4] = new makeNews("Agar Corporation Canada","Agar Corporation Canada makes an impact on the local community.",'News.html#Anchor-Agar-1238','Read More',autoImg,'News.html').write();

var nIndex = 0;
var timerID = null;
var ptimerID = null;
var pIndex =0;
var pLen = productArray.length;
var nLen = newsArray.length;
function rotateNews(){
	if(nIndex >= nLen)
		nIndex = 0;
	document.getElementById('stories').innerHTML = newsArray[nIndex];
	nIndex += 1;
	timerID = setTimeout('rotateNews()',4000);
}
function rotateProducts(){
	if(pIndex >= pLen)
		pIndex = 0;
	document.getElementById('products').innerHTML = productArray[pIndex];
	pIndex ++;
	ptimerID = setTimeout('rotateProducts()',5000);
}
function rotateAll(){
	rotateNews();
	rotateProducts();
}
function pauseNews() {
	if (timerID != null) {
		clearTimeout(timerID);
		timerID = null;
	}
}
function playNews() {
	if (timerID == null) {
		timerID = setTimeout('rotateNews()', 1000);
	}
}
function pauseProducts() {
	if (ptimerID != null) {
		clearTimeout(ptimerID);
		ptimerID = null;
	}
}
function playProducts() {
	if (ptimerID == null) {
		ptimerID = setTimeout('rotateProducts()', 1000);
	}
}

function wait(numberMillis) {
 var now = new Date();
 var exitTime = now.getTime() + numberMillis;
  while (true) {
   now = new Date();
   if (now.getTime() > exitTime)
    return;
	}
}