var homeLoaderObj = new ajaxObject('http://www.conradbrothersconstruction.com/AJAX/home-loader.php', updateHomePhotos);
var portfolioLoaderObj = new ajaxObject('http://www.conradbrothersconstruction.com/AJAX/portfolio-loader.php', updatePortfolioPhotos);


function loadHomePhoto(photo){
	document.getElementById("homePhotos").innerHTML = '<div id="homeLoading"><img src="http://www.conradbrothersconstruction.com/IMG/LOADING/loading.gif" width="208" height="13" border="0" alt="loading..." /><br /><span class="white t10">LOADING...</span></div>';
	
	pVars = "photo="+photo;
	homeLoaderObj.update(pVars, 'GET');
}

function loadPortfolioPhoto(pType, project, num){
	document.getElementById("portfolioPhotos").innerHTML = '<div id="homeLoading"><img src="http://www.conradbrothersconstruction.com/IMG/LOADING/loading.gif" width="208" height="13" border="0" alt="loading..." /><br /><span class="white t10">LOADING...</span></div>';
	
	pVars = "type="+pType+"&project="+project+"&num="+num;
	portfolioLoaderObj.update(pVars, 'GET');
}


function updateHomePhotos(responseText, responseStatus){
	
	if (responseStatus==200) {
		document.getElementById("homePhotos").innerHTML = responseText;
	}else {
		alert(responseStatus + ' -- Error Processing Request');
	}
}

function updatePortfolioPhotos(responseText, responseStatus){
	if (responseStatus==200) {
		var responses = responseText.split("|"); //the split is the two data sets
		document.getElementById('portDesc').innerHTML = responses[0];
		document.getElementById("portfolioPhotos").innerHTML = responses[1];
	}else {
		alert(responseStatus + ' -- Error Processing Request');
	}
}

var homePos = 0;
var sliderOn = true;


function slideHomePhotos(photoNum){
	if(sliderOn){
		num = photoNum + 1;
		if(num > 5) num = 0;
		if(num >= 0){
			moveHomePhotos(6,num);
		}
		the_timeout = setTimeout('slideHomePhotos('+num+');',4000);
		//moveHomePhotos(6,1);	
	}
}

function moveHomePhotos(steps, pos){
	if(pos == homePos) return false;
	else if(steps < 0){
		homePos = pos;
		return false;
	}
	else{
		dif = pos - homePos;
				
		var step = 0;
		
		if(steps == 6) {
			step = 150;
		}else if(steps == 5) step = 275;
		else if(steps == 4) step = 375;
		else if(steps == 3) step = 450;
		else if(steps == 2) step = 500;
		else if(steps == 1) step = 535;
		else if(steps == 0) step = 549;
		
		
		
		if(dif > 0){
			newX = (-homePos*549) - ((step * dif));
		}else{
			newX = (-homePos*549) + (-step*dif);
		}
		
		//alert("here with x: "+newX);
				
		newXS = newX.toString()+"px";
		document.getElementById('homePhotoHolder').style.left = newXS;
		
		var newStep = steps - 1;
		the_timeout2 = setTimeout('moveHomePhotos('+newStep+','+pos+');',75);	
	}
}
