
var strControlPrefix;
strControlPrefix = "";


var mCurrentVIN;
mCurrentVIN = "";

var intIntervalID;
var intIntervalMilliseconds = 5000;


var arySpecialData;
var intCurrentIndex;
var intervalRotator;

function GetInternetSpecials(){

	intCurrentIndex = -1;
	//clearInterval(intervalPhotoRotator);
	arySpecialData = null;
	
	var url;
	url = '/ajax/hp-layout2-getInternetSpecials.aspx?r='+randomString(10);
	
	var http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType) {
					http_request.overrideMimeType('text/xml');                    
			}
	} else if (window.ActiveXObject) { // IE
			try {
					http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
					try {
							http_request = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e) {}
			}
	}

	if (!http_request) {
			alert('Giving up :( Cannot create an XMLHTTP instance');
			return false;
	}

	http_request.onreadystatechange = function() { analyzeResponse_GetInternetSpecials(http_request); };
	http_request.open('GET', url, true);
	http_request.send(null);

}


function analyzeResponse_GetInternetSpecials(http_request) {
		//alert('Ready State: '+http_request.readyState+'\nHTTP Status: '+http_request.status);
		if ((http_request.readyState == 4) && (http_request.status == 200)) {
				
			var strResponse;
			strResponse = http_request.responseText;	
			
			arySpecialData = strResponse.split("\n");
			
			RotatePhotos(1);
			intervalRotator = setInterval('RotatePhotos(1)', 5000);					
		
		}
}	


function RotatePhotos(intDirection){

	if (intDirection > 0){
		intCurrentIndex += 1;
	}
	else{
		intCurrentIndex -= 1;
	}
	
	if (intCurrentIndex < 0){
		intCurrentIndex = arySpecialData.length-1;
	}
			
	if (intCurrentIndex >= arySpecialData.length){
		intCurrentIndex = 0
	}
	
	
	var aryVehicleData;
	aryVehicleData = arySpecialData[intCurrentIndex].split("|");
	
	
	//load photo
	var strURLToPhoto;
	strURLToPhoto = "/img/getVehiclePhoto.aspx?return=FIRSTFOUND&maxwidth=195&maxHeight=140&vin="+aryVehicleData[0];
	
	var strURLToVehiclePage;
	strURLToVehiclePage = "/inventory/Used-Vehicle-Detail-Page.aspx?vin="+aryVehicleData[0];
	
	
	var imgSpecialPhoto;
	imgSpecialPhoto = document.getElementById('imgSpecialPhoto');
	imgSpecialPhoto.src=strURLToPhoto;
	
	var ancSpecialVehiclePhoto;
	ancSpecialVehiclePhoto = document.getElementById('ancSpecialVehiclePhoto');
	ancSpecialVehiclePhoto.href=strURLToVehiclePage;
	
	var ancSpecialVehicleText;
	ancSpecialVehicleText = document.getElementById('ancSpecialVehicleText');
	ancSpecialVehicleText.href=strURLToVehiclePage;
	
	var divSpecialYearMakeModel;
	divSpecialYearMakeModel = document.getElementById('divSpecialYearMakeModel');
	divSpecialYearMakeModel.innerHTML = aryVehicleData[1];
	
	var divSpecialPrice;
	divSpecialPrice = document.getElementById('divSpecialPrice');
	divSpecialPrice.innerHTML = aryVehicleData[2];
	
					

}


function GoRight(){
	clearInterval(intervalRotator);
	RotatePhotos(1);
}


function GoLeft(){
	clearInterval(intervalRotator);
	RotatePhotos(-1);
}

function initModule2(){	
	GetInternetSpecials();	
}


