var pos=105;
var cPos=105;
var carimage = document.getElementById("carimg");
var divPos = 50;
var dispElm = "hometext";
var sPos = 855;
var secondPos = 0;
var maxSecondPos;
var speed = 5;
function moveCar()
{
	if (pos != cPos)
{		
	if (pos <= cPos)
	if ((pos+speed) <= cPos)	
	pos = pos + speed;
	else
	pos = pos + (cPos-pos);
	else
	if ((pos-speed) >= cPos)	
	pos = pos - speed;
	else
	pos = pos - (pos-cPos);	
	
	carimage.style.marginLeft = pos + "px";		
}

}
window.setInterval(" setCar(); moveText();  moveCar(); moveSecond();", 5);

function redCar()
{
	carimage.src = "images/car2.jpg";
	carimage.style.cursor = "pointer";

	if (pos == 105 )
	document.getElementById("home").style.color="white";
	else if (pos == 265)
	document.getElementById("aboutus").style.color = "white";
	else if (pos == 415)
	document.getElementById("services").style.color = "white";
	else if (pos == 570)
	document.getElementById("estimates").style.color = "white";
	else if (pos == 725)
	document.getElementById("contactus").style.color = "white";
}

function redCar()
{
	carimage.src = "images/car2.jpg";
	carimage.style.cursor = "pointer";

	if (pos == 105 )
	document.getElementById("home").style.color="white";
	else if (pos == 265)
	document.getElementById("aboutus").style.color = "white";
	else if (pos == 415)
	document.getElementById("services").style.color = "white";
	else if (pos == 570)
	document.getElementById("estimates").style.color = "white";
	else if (pos == 725)
	document.getElementById("contactus").style.color = "white";
}

function grayCar()
{
	carimage.src = "images/car1.jpg";
	carimage.style.cursor = "default";
    
    if (pos == 105 )
	document.getElementById("home").style.color="#414b55";
	else if (pos == 265)
	document.getElementById("aboutus").style.color = "#414b55";
	else if (pos == 415)
	document.getElementById("services").style.color = "#414b55";
	else if (pos == 570)
	document.getElementById("estimates").style.color = "#414b55";
	else if (pos == 725)
	document.getElementById("contactus").style.color = "#414b55";	
}

function grayText(inputElm)
{    
    if ((inputElm.id == "home" && pos == 105 ) || (inputElm.id == "aboutus" && pos == 265 ) || (inputElm.id == "services" && pos == 415 ) || (inputElm.id == "estimates" && pos == 570 ) || (inputElm.id == "contactus" && pos == 725 ))
    {
    carimage.src = "images/car1.jpg";
	inputElm.style.cursor = "default";	
	inputElm.style.color = "#414b55"; 
}
}

function redText(inputElm)
{
    if ((inputElm.id == "home" && pos == 105 ) || (inputElm.id == "aboutus" && pos == 265 ) || (inputElm.id == "services" && pos == 415 ) || (inputElm.id == "estimates" && pos == 570 ) || (inputElm.id == "contactus" && pos == 725 ))
    {
    carimage.src = "images/car2.jpg";
	inputElm.style.cursor = "pointer";
	inputElm.style.color = "white"; 
	}
}

function dispText(inputElm)
{
document.getElementById("hometext").style.display = "none";
document.getElementById("aboutustext").style.display = "none";
document.getElementById("servicestext").style.display = "none";
document.getElementById("estimatestext").style.display = "none";
document.getElementById("contactustext").style.display = "none";
/*document.getElementById("hometext").style.height = "135px";
'document.getElementById("aboutustext").style.height = "135px";
'document.getElementById("servicestext").style.height = "135px";
'document.getElementById("estimatestext").style.height = "135px";
'document.getElementById("contactustext").style.height = "135px";*/

document.getElementById(inputElm).style.display = "inline"; 
document.getElementById(inputElm).style.overflow = "hidden";
divPos = 50;
dispElm = inputElm;
sPos = 845;
if (pos > cPos)
var distance = pos - cPos;
else
var distance = cPos - pos;

if (distance > 450)
speed = 20;
else if (distance > 300)
speed = 15;
else if (distance > 150)
speed = 10;
else
speed = 5;
secSecond();
}

function secSecond()
{
if (dispElm == "hometext")
{
    document.getElementById("secondFlash").style.display = "inline";
    document.getElementById("secondImg").style.display = "none";
    document.getElementById("secondFlash").style.marginLeft = "0px";
}
else
{

    
    if (dispElm == "aboutustext")
    document.getElementById("secondImg").src = "images/AboutUs.jpg";
    else if (dispElm == "servicestext")
    document.getElementById("secondImg").src = "images/Services.jpg";
    else if (dispElm == "estimatestext")
    document.getElementById("secondImg").src = "images/Estimates.jpg";
    else if (dispElm == "contactustext")
    document.getElementById("secondImg").src = "images/Contact.jpg";
    document.getElementById("secondImg").style.marginLeft = "0px";
	
	    document.getElementById("secondFlash").style.display = "none";
    document.getElementById("secondImg").style.display = "inline";
}
secondPos = 0;
}

function moveSecond()
{
    if (secondPos < maxSecondPos )
        secondPos = secondPos + 15;
    else
        secondPos = maxSecondPos;
  if (dispElm == "hometext")
  document.getElementById ("secondFlash").style.marginLeft = secondPos + "px";
  else
  document.getElementById ("secondImg").style.marginLeft = secondPos + "px";  
}

function setCar()
{
var calMargin = ((document.body.clientWidth-990)/2);
if (document.body.clientWidth > 990)
{
document.getElementById("topimg").style.left = (document.body.clientWidth - 152)+"px";
//document.getElementById("bottomimg").style.left = (document.body.clientWidth - 399)+"px";
maxSecondPos = ((document.body.clientWidth - 790 )/2);
}
else
{
document.getElementById("topimg").style.left = (990 - 152)+"px";
//document.getElementById("bottomimg").style.left = (990 - 399)+"px";
maxSecondPos = (990/2);
}
carimage = document.getElementById("carimg");
document.getElementById(dispElm).style.display = "inline";
}

function setContactUs()
{
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);

	if ((browser=="Microsoft Internet Explorer")&& (version<=4))
	document.getElementById("topimg").src = "images/Strip.jpg";
	else
	document.getElementById("topimg").src = "images/Strip.png";
}

function moveText()
{
if (divPos < 800)
	{
		divPos = divPos + 25;
		sPos = sPos - 25;
		document.getElementById(dispElm).style.width = divPos + "px";
		document.getElementById(dispElm).style.marginLeft = sPos + "px";
	}
else if (divPos >= 800)
{
//document.getElementById(dispElm).style.overflow = "auto";
//document.getElementById(dispElm).style.height = "250px";
}
/*var ctimgleft = document.body.clientWidth;

if (ctimgleft < 990 )
    ctimgleft = 824;
else
    ctimgleft = document.body.clientWidth - 166;
document.getElementById("contactusimage").style.left = ctimgleft; */
}


	function validate()
	{
	
 if( check()==true)
 {
 document.form1.submit();
 }
	
	}
	
	function check()
	{
			if ((document.form1.first.value=="") || (document.form1.email.value==""))
		{
			alert("Please, Enter all Mandatory Fields");
			return false;
		}	
		var emailID=document.form1.email
	
		if ((emailID.length>0)||(emailID.value!=""))
		{
			if (echeck(emailID.value)==false)
			{
				emailID.value=""
				emailID.focus()
				return false
			}
		}
	
	return true;
	}
	
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}	
