//BROWSER SNIFFER

function Is() {
    this.ie4 = document.all && !document.getElementById;
	this.ns4 = document.layers;
	this.ie5 = document.all && document.getElementById;
	this.ns6 = document.getElementById && !document.all;
}

var is = new Is()

var agt=navigator.userAgent.toLowerCase();
var mac=0;
if(agt.indexOf('mac')!=-1){mac=1;lin=0;}

if(is.ns4) {
	doc = "document";
	sty = "";
	htm = ".document"
}
else if(is.ie4 || is.ie5) {
	doc = "document.all";
	sty = ".style";
	htm = ""
}
else if(is.ns6) {
	doc = "document.getElementById(";
	sty = ").style";
	htm = ""
}

function showLayer(layer)
{
	showLyr = eval(doc + '["' + layer + '"]' + sty);
	showLyr.visibility = "visible";
}

function hideLayer(layer)
{
	hideLyr = eval(doc + '["' + layer + '"]' + sty);
	hideLyr.visibility = "hidden";
}

/*var win=null;
function NewWindow(mypage, name)
{
	settings='top=0,left=0,scrollbars=yes,location=yes,directories=yes,status=yes,menubar=yes,toolbar=yes,resizable=yes';
	win=top.open(mypage, name);
}
*/
//var top = 0;
var clipTop = 0;
var clipTop2 = 0;
//var clipWidth = 212;
//var clipBottom = 0;
//var topper = 300;
//var lyrheight = 0;
function prepLyr()
{
	textLyr = eval(doc + '["scrollText"]' + sty);
	if (is.ns4)
	{
		lyrheight = textLyr.clip.bottom;
		lyrheight += 20;
		textLyr.clip.top = clipTop;
		textLyr.clip.left = 0;
		//textLyr.clip.right = 233;
		textLyr.clip.bottom = clipBottom;
	}
	else
	{
		if(is.ns6)
			lyrheight = lyrheightNS6;
		else
			lyrheight = scrollText.offsetHeight;
			
		textLyr.clip = 'rect('+clipTop+' '+lyrwidth+' '+clipBottom+' 0)'
	}
	textLyr.visibility = "visible";
}

var loop = false;
//var direction = "up";
var timer1 = null;
function scroll(dir)
{
	textLyr = eval(doc + '["scrollText"]' + sty);
	//lyrheight = text.offsetHeight;
    direction = dir;
    	speed = 1;
    var y_pos = parseInt(textLyr.top);
    //var x_pos = parseInt(textLyr.left);
	if(direction == "down") 
	{
		if(clipBottom > lyrheight)
			return;
		textLyr.top = (y_pos-(speed));
		clipTop += speed;
		clipBottom  += speed;
		if (is.ns4)
		{
			textLyr.clip.top = clipTop;
			textLyr.clip.bottom = clipBottom;
			//alert(textLyr.clip.top);
		}
		else
		{
			clipstring = 'rect('+clipTop+' '+lyrwidth+' '+clipBottom+' 0)';
			textLyr.clip = clipstring;
		}
		clearTimeout(timer1);
		timer1 = setTimeout("scroll(direction,speed)", 2);
	} 
	else if(direction == "up") 
	{
		if(y_pos > top)
			return;
		textLyr.top = (y_pos+(speed));
		clipTop -= speed;
		clipBottom  -= speed;
		if (is.ns4)
		{
			textLyr.clip.top = clipTop;
			textLyr.clip.bottom = clipBottom;
			//alert(textLyr.clip.top);
		}
		else
		{
			clipstring = 'rect('+clipTop+' '+lyrwidth+' '+clipBottom+' 0)';
			textLyr.clip = clipstring;
			//textLyr.top = topper;
		}
		clearTimeout(timer1);
		timer1 = setTimeout("scroll(direction,speed)", 2);
	}
	return;
}	

var Mac_OS = (navigator.userAgent.indexOf("mac") != -1) || (navigator.userAgent.indexOf("Mac") != -1); 

function wait()
{
	one = wait.arguments[0];
	two = wait.arguments[1];
	three = wait.arguments[2];
	maxDistance = wait.arguments[3];
	timer1 = setTimeout("agents(one, two, three, maxDistance)", 1000);
}

function agents(one, two, three, maxDistance)
{
	showLayer("agents");
	timer1 = setTimeout("startEngines(one, two, three, maxDistance)", 2000);
}

function startEngines(one, two, three, maxDistance)
{
	showLayer("startEngines");
	timer1 = setTimeout("flag(one, two, three, maxDistance)", 2000);
}

function flag(one, two, three, maxDistance)
{
	showLayer("flag");
	hideLayer("agents");
	hideLayer("startEngines");
	timer1 = setTimeout("carScroll(one, two, three, maxDistance)", 4000);
}

function showNames(one, two, three)
{
	if(one != 0)
	{
		showLayer("first");
		if(two != 0)
		{
			showLayer("second");
			if(three != 0)
				showLayer("third");
		}
	}
	else
		showLayer("noPoints");
}

function showStandings()
{
	showLayer("standings");
}

function carScroll(one, two, three, maxDistance)
{
		//alert(one);
	newLayer = new Array();
	for(i=1; i<=3; i++)
	{
		newLayer[i] = new Array()	
		newLayer[i][1] = "scrollCar" + i;
		//newLayer[i][i+1] = "scrollCar" + i;
		//alert(newLayer[i][1]);
	}
	
	newLayer[1][2] = one*30;
	newLayer[2][2] = two*30;
	newLayer[3][2] = three*30;
		//alert(newLayer[1][2]);
		
	//alert(maxDistance);	
	hideLayer("flag");
	
	for(i=1; i<=3; i++)
	{
		//alert("hello" + i);
		textLyr = eval(doc + '["' + newLayer[i][1] + '"]' + sty);
		//lyrheight = text.offsetHeight;
		destination_pos = newLayer[i][2];
		if(Mac_OS == false)
			speed = Math.ceil(destination_pos/350*5);
		else
			speed = destination_pos/350*10;
			
		
		var x_pos = parseInt(textLyr.left);
		
		if(x_pos != destination_pos)
		{
			//alertNumber =  destination_pos + x_pos	
				//alert('destination_pos - x_pos '+alertNumber);
			if(destination_pos >= x_pos)
			{
				x_pos += speed;
				textLyr.left = x_pos;
			}
		}
	}


	textLyr = eval(doc + '["' + newLayer[1][1] + '"]' + sty);
	//alert(textLyr);
	if(maxDistance >= parseInt(textLyr.left) && newLayer[1][2] != 0)
	{
		clearTimeout(timer1);
		timer1 = setTimeout("carScroll(one, two, three, maxDistance)", 2);
	}
	else
	{
		timer2 = setTimeout("showNames(one, two, three)", 0);
		timer3 = setTimeout("showStandings()", 1000);
	}
	
	return;
}	

function stopScroll()
{
	if (timer1) clearTimeout(timer1);
}






function prepLyr2()
{
	textLyr2 = eval(doc + '["scrollText2"]' + sty);
	if (is.ns4)
	{
		lyrheight2 = textLyr2.clip.bottom;
		lyrheight2 += 20;
		textLyr2.clip.top = clipTop2;
		textLyr2.clip.left = 0;
		//textLyr.clip.right = 233;
		textLyr2.clip.bottom = clipBottom2;
	}
	else
	{
		if(is.ns6)
			lyrheight2 = lyrheightNS62;
		else
			lyrheight2 = scrollText2.offsetHeight;
			
		textLyr2.clip = 'rect('+clipTop2+' '+lyrwidth2+' '+clipBottom2+' 0)'
	}
	textLyr2.visibility = "visible";
}

var loop2 = false;
//var direction = "up";
var timer2 = null;
function scroll2(dir)
{
	textLyr2 = eval(doc + '["scrollText2"]' + sty);
	//lyrheight = text.offsetHeight;
    direction = dir;
    speed = 1;
    var y_pos = parseInt(textLyr2.top);
    //var x_pos = parseInt(textLyr.left);
	if(direction == "down") 
	{
		if(clipBottom2 > lyrheight2)
			return;
		textLyr2.top = (y_pos-(speed));
		clipTop2 += speed;
		clipBottom2  += speed;
		if (is.ns4)
		{
			textLyr2.clip.top = clipTop2;
			textLyr2.clip.bottom = clipBottom2;
			//alert(textLyr.clip.top);
		}
		else
		{
			clipstring = 'rect('+clipTop2+' '+lyrwidth2+' '+clipBottom2+' 0)';
			textLyr2.clip = clipstring;
		}
		clearTimeout(timer2);
		timer2 = setTimeout("scroll2(direction,speed)", 2);
	} 
	else if(direction == "up") 
	{
		if(y_pos > top2)
			return;
		textLyr2.top = (y_pos+(speed));
		clipTop2 -= speed;
		clipBottom2  -= speed;
		if (is.ns4)
		{
			textLyr2.clip.top = clipTop2;
			textLyr2.clip.bottom = clipBottom2;
			//alert(textLyr.clip.top);
		}
		else
		{
			clipstring = 'rect('+clipTop2+' '+lyrwidth2+' '+clipBottom2+' 0)';
			textLyr2.clip = clipstring;
			//textLyr.top = topper;
		}
		clearTimeout(timer2);
		timer2 = setTimeout("scroll2(direction,speed)", 2);
	}
	return;
}	

function stopScroll2()
{
	if (timer2) clearTimeout(timer2);
}

function dsp(loc){
   if(document.getElementById){
      var foc=loc.firstChild;
      foc=loc.firstChild.innerHTML?
         loc.firstChild:
         loc.firstChild.nextSibling;
		 if(foc.innerHTML=='<IMG height=1 src="http://www.cfvatterott.com/images/spacer.gif" width=10 border=0><IMG src="http://www.cfvatterott.com/images/plus.gif" align=absMiddle border=0>')
		 {
		 	foc.innerHTML='<IMG height=1 src="http://www.cfvatterott.com/images/spacer.gif" width=10 border=0><IMG src="http://www.cfvatterott.com/images/minus.gif" align=absMiddle border=0>';
		 }
		 else
		 {
			//alert(foc.innerHTML);
			foc.innerHTML='<IMG height=1 src="http://www.cfvatterott.com/images/spacer.gif" width=10 border=0><IMG src="http://www.cfvatterott.com/images/plus.gif" align=absMiddle border=0>';	
		 }
      foc=loc.parentNode.nextSibling.style?
         loc.parentNode.nextSibling:
         loc.parentNode.nextSibling.nextSibling;
      foc.style.display=foc.style.display=='block'?'none':'block';}}  

/*function preLoad(page) {

	slide1 = new Image();
	slide1.src = "images/benzel-site.jpg";
	slide2 = new Image();
	slide2.src = "images/P1010030.jpg";
	slide3 = new Image();
	slide3.src = "images/bren-site.jpg";
}
*/
var step=1
var whichimage=1
function slideit(){
	if (!document.images)
		return
	//If the browser is IE 4.x
	if (document.all)
		slide.filters.blendTrans.apply()
	if(!is.ns4)
		document.slide.src=eval("image"+step+".src")
	//If the browser is IE 4.x
	if (document.all)
		slide.filters.blendTrans.play()
	whichimage=step
	if (step<3)
		step++
	else
		step=1
	setTimeout("slideit()",5000)
}

function slideitIndex(){
	if (!document.images)
		return
	//If the browser is IE 4.x
	if (document.all)
		slide.filters.blendTrans.apply()
	if(!is.ns4)
		document.slide.src=eval("image"+step+".src")
	//If the browser is IE 4.x
	if (document.all)
		slide.filters.blendTrans.play()
	whichimage=step
	if (step<5)
		step++
	else
		step=1
	setTimeout("slideitIndex()",4000)
}

function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition=(screen.width)?(screen.width-w)/2:100;
	TopPosition=(screen.height)?(screen.height-h)/2:100;
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
}

function lite(obj) {
	if(document.all&&!window.opera) 
	{
		obj.filters.blendTrans.apply(); 
		obj.filters.blendTrans.play(); 
	} 
} 

