/* Homepage Quick Start v0.2 JS by Josh Lizarraga */
/* Copyright 2009 Autofusion.com */

/* Firebug Console Helper */
(function(){
	if(!window.console || !console.firebug){
		var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
		window.console = {};
		for (var i = 0; i < names.length; ++i)
			window.console[names[i]] = function() {}
	}
})();

(function(){

/* AF Library */

if(typeof(YAHOO.AUTOFUSION) == "undefined"){
	YAHOO.namespace("AUTOFUSION");
}
if(typeof(YAHOO.AUTOFUSION.items) == "undefined"){
	YAHOO.AUTOFUSION.items = new Object();
}
var AF = YAHOO.AUTOFUSION;

/* Homepage Quick Start */

AF.HomepageQuickStart = function(pID, pConfig){
	
	// Properties:
	
	this.confid = false;
	this.incentivesConfid = false;
	this.config = (pConfig) ? pConfig : false;
	this.MIL = [];
	this.completedRequests = 0;
	this.models = [];
	this.results = [];
	this.currentResults = [];
	this.currentResultIndex = 0;
	this.detailsConfid = false;
	this.detailsURLs = false;
	this.altTemplate = false;
	this.altResearchTemplate = false;
	this.followClick = false;
	this.busy = false;
	
	this.slider = document.getElementById(pID);
	this.slidee = this.slider.getElementsByTagName('div')[0];
	this.links = this.slidee.getElementsByTagName('a');
	this.sliderWidth = parseInt(this.slider.offsetWidth);
	this.slideeWidth = (parseInt(this.links[0].offsetWidth) + 1) * this.links.length;
	this.sliderEvent = 'click';
	
	this.scrollLeft = false;
	this.scrollRight = false;
	
	this.scrollInterval = false;
	
	this.scrollSpeed = 5;
	this.scrollIncrement = 5;
	
	this.autoplay = false;
	this.slides = false;
	this.autoLinks = false;
	this.autoInstant = false;
	this.autoInterval = 4000;
	this.autoIndex = -1;
	
	this.incentives = false;
	this.incentivesEnabled = false;
	this.incentivesLoaded = false;
	this.oldestFirst = false;
	
	// Element Properties:
	
	this.hide = false;
	
	this.slideDisplay = 'block';
	
	this.image = false;
	this.imageFlag = false;
	this.imagePath = '/hqs/';
	this.imageDisplay = 'block';
	
	this.inventory = false;
	this.inventoryPath = '/inventory.php?VehicleType=New&Model=';
	this.inventoryDisplay = 'block';
	
	this.research = false;
	this.researchPath = '';
	this.researchDisplay = 'block';
	
	this.quote = false;
	this.quotePath = '/quick_quote.html?model=';
	this.quoteDisplay = 'block';
	
	this.heading = false;
	this.headingDisplay = 'block';
		
	this.xmlLink = false;
	this.xmlPrice = false;
	this.xmlMPG = false;
	this.xmlLinkDisplay = 'block';
	this.xmlPricePrefix = 'Starting at ';
	this.xmlPriceSuffix = '';
	this.xmlPriceDisplay = 'block';
	this.xmlMPGPrefix = 'As high as ';
	this.xmlMPGSuffix = ' MPG';
	this.xmlMPGDisplay = 'block';
	this.xmlPath = '/hmpg_javascript_mm.xml';
	this.xmlObject = {};
		
	this.previous = false;
	this.previousDisplay = 'block';
	
	this.next = false
	this.nextDisplay = 'block';
	
	this.viewing = false;
	this.viewingPrefix = 'Viewing ';
	this.viewingBridge = ' of ';
	this.viewingSuffix = ' Results';
	this.viewingDisplay = 'block';
	
	this.rebate = false;
	this.rebatePrefix = '';
	this.rebateSuffix = ' Factory Rebate!';
	this.rebateDisplay = 'block';
	
	this.aprLow = false;
	this.aprPrefix = 'As low as ';
	this.aprSuffix = '% APR!';
	this.aprDisplay = 'block';
	
	this.rates = false;
	this.ratesPrefix = '';
	this.ratesBridge = '% up to ';
	this.ratesSuffix = '';
	this.ratesDisplay = 'block';
	
	this.lease = false;
	this.leasePrefix = 'Lease Offer: ';
	this.leaseBridge = ' (Trim: ';
	this.leaseSuffix = ')';
	this.leaseDisplay = 'block';
	
	this.disclaimer = false;
	this.disclaimerDisplay = 'block';
	
	this.details = false;
	this.detailsDisplay = 'block';
	
	// Config:
	if(this.config != false){
		for(var i in this.config){
			this[i] = this.config[i];
		}
	}
		
	var that = this;
	
	// Methods:
	
	this.resultObject = function(pIncentive, pIndex){
		// Basic:
		this.year = that.MIL[0].getValue(pIncentive.getElementsByTagName("year")[0]);
		this.make = that.MIL[0].getValue(pIncentive.getElementsByTagName("make")[0]);
		this.model = that.MIL[0].getValue(pIncentive.getElementsByTagName("model")[0]);
		// Rebate:
		this.rebate = false;
		if(pIncentive.getElementsByTagName("amount").length > 0){
			this.rebate = that.MIL[0].getValue(pIncentive.getElementsByTagName("amount")[1]);
		}
		// Rates:
		var oRates = pIncentive.getElementsByTagName("rate");
		this.lowestAPR = 100.00;
		this.rates = [];
		for(var i=0; i<oRates.length; i++){
			var oAPR = parseFloat(that.MIL[0].getValue(oRates[i]));
			if(oAPR < this.lowestAPR){
				this.lowestAPR = oAPR;
			}
			var oTerm = oRates[i].getAttribute("term");
			oTerm = (oTerm.toLowerCase().indexOf("months") > -1) ? oTerm : oTerm + " Months";
			this.rates.push({
				term: oTerm,
				apr: oAPR
			});
		}
		// Lease Special:
		this.lease = false;
		var oLeases = pIncentive.getElementsByTagName("special_lease");
		if(oLeases.length > 0){
			this.lease = [];
			for(var i=0; i<oLeases.length; i++){
				this.lease.push({
					trim: that.MIL[0].getValue(oLeases[i].getElementsByTagName("trim")[0]),
					text: that.MIL[0].getValue(oLeases[i].getElementsByTagName("text")[0])
				});
			}
		}
		// Trims:
		this.appliesTo = that.MIL[0].getValue(pIncentive.getElementsByTagName("trims")[0]) + '.';
		// URL:
		this.url = that.MIL[0].getValue(pIncentive.getElementsByTagName("details_link")[0]);
		if(that.altTemplate != false){
			this.url = this.url.replace(/TrimsIncentives/, that.altTemplate);
		}
		if(that.detailsConfid != false){
			this.url = this.url.replace(/confid_.*\//, 'confid_' + that.detailsConfid + '/');
		}
		if(that.detailsURLs != false){
			this.url = that.detailsURLs[pIndex] + this.url;
		}
		// Disclaimer:
		this.disclaimer = "<strong>Model Year: " + this.year + "<br />Applies to: " + this.appliesTo + "</strong><br />" + that.MIL[0].getValue(pIncentive.getElementsByTagName("comment")[0]) + "<br />Expires " + that.MIL[0].getValue(pIncentive.getElementsByTagName("expiration")[0]) + '.<br /><a href="' + this.url + '#trims_incentives">Click here</a> for complete terms and conditions.';
		// Push:
		if(typeof(that.models[this.model]) == 'undefined'){
			that.models[this.model] = [];
		}
		that.models[this.model].push(this);
		if(that.oldestFirst){
			var compareYears = function(a, b){
				return parseInt(a.year, 10) - parseInt(b.year, 10);
			}
			that.models[this.model].sort(compareYears);
		}
	}; // resultObject()
	
	this.sortIncentives = function(pXML, pIndex){
		var oIncentives = pXML.getElementsByTagName("incentive");
		for(var i=0; i<oIncentives.length; i++){
			that.results.push(new that.resultObject(oIncentives[i], pIndex));
		}
	}; // sortIncentives()
	
	this.doClicks = function(pTarget){
		that.imageClick(pTarget);
		that.headingClick(pTarget);
		that.inventoryClick(pTarget);
		that.researchClick(pTarget);
		that.quoteClick(pTarget);
		that.defaultClick(pTarget);
		that.incentivesClick(pTarget);
		that.xmlClick(pTarget);
	}; // doClicks()
			
	this.carClick = function(e){
		if(that.followClick == false){
			YAHOO.util.Event.stopPropagation(e);
			YAHOO.util.Event.preventDefault(e);
		}
		var oTarget = YAHOO.util.Event.getTarget(e);
		if(oTarget.nodeName.toUpperCase() != 'A'){
			oTarget = YAHOO.util.Dom.getAncestorByTagName(oTarget, 'a');
		}
		if(that.autoplay != false){
			clearInterval(that.autoplay);
			if(that.slides != false){
				YAHOO.util.Dom.setStyle(that.slides, 'opacity', 0);
			}
		}
		if(that.hide != false){
			YAHOO.util.Dom.setStyle(that.hide, 'display', 'none');
			that.hide = false;
		}
		that.doClicks(oTarget);
	}; // carClick()
	
	this.defaultClick = function(pTarget){
		if(that.image == false && that.inventory == false && that.research == false && that.quote == false && that.incentives == false && that.xmlLink == false){
			document.location.href = pTarget.href;
		}
	}; // defaultClick()
	
	this.headingClick = function(pTarget){
		if(that.heading != false){
			YAHOO.util.Dom.setStyle(that.heading, 'display', that.headingDisplay);
			that.heading.innerHTML = pTarget.title;
		}
	}; // imageClick()
	
	this.imageClick = function(pTarget){
		if(that.image != false){
			if(that.imageFlag){
				YAHOO.util.Event.addListener(that.image, 'load', that.fadeImageIn);
				that.imageFlag = false;
			}
			that.fadeImageOut(pTarget);
		}
	}; // imageClick()
	
	this.inventoryClick = function(pTarget){
		if(that.inventory != false){
			YAHOO.util.Dom.setStyle(that.inventory, 'display', that.inventoryDisplay);
			that.inventory.href = that.inventoryPath + pTarget.title;
		}
	}; // inventoryClick()
	
	this.researchClick = function(pTarget){
		if(that.research != false){
			YAHOO.util.Dom.setStyle(that.research, 'display', that.researchDisplay);
			that.research.href = that.researchPath + pTarget.title;
		}
	}; // researchClick()
	
	this.quoteClick = function(pTarget){
		if(that.quote != false){
			YAHOO.util.Dom.setStyle(that.quote, 'display', that.quoteDisplay);
			that.quote.href = that.quotePath + pTarget.title;
		}
	}; // quoteClick()
	
	this.incentivesClick = function(pTarget){
		if(that.incentives != false){
			// Reset index:
			that.currentResultIndex = 0;
			// Load incentive(s):
			if(typeof(that.models[pTarget.title]) == 'object'){
				that.currentResults = that.models[pTarget.title];
				that.loadIncentive();
				if(that.currentResults.length < 2){
					YAHOO.util.Dom.setStyle([that.previous, that.next], 'display', 'none');
				} else {
					YAHOO.util.Dom.setStyle(that.previous, 'display', that.previousDisplay);
					YAHOO.util.Dom.setStyle(that.next, 'display', that.nextDisplay);
				}
			} else {
				YAHOO.util.Dom.setStyle([
					that.previous,
					that.next,
					that.viewing,
					that.rebate,
					that.aprLow,
					that.rates,
					that.disclaimer,
					that.details
				], 'display', 'none');
			}
		}
	}; // incentivesClick()
	
	this.autoClick = function(){
		// If current autoLink is a slide, fade it out:
		if(that.autoIndex > -1){
			if(that.autoLinks[that.autoIndex].type == 'slide'){
				var oNode = that.autoLinks[that.autoIndex].node;
				var oFadeOut = new YAHOO.util.Anim(oNode, {
						opacity: { to: 0 }
					}, 0.25, YAHOO.util.Easing.easeOut);
				oFadeOut.animate();
				oFadeOut.onComplete.subscribe(function(){
					YAHOO.util.Dom.setStyle(oNode, 'display', 'none');
				});				
			}
		}
		// Increment index:
		if(that.autoIndex < that.autoLinks.length - 1){
			that.autoIndex++;
		} else {
			that.autoIndex = 0;
		}
		// Link or slide?
		if(that.autoLinks[that.autoIndex].type == 'link'){
			that.doClicks(that.autoLinks[that.autoIndex].node);
		} else {
			that.hideEverything();
			YAHOO.util.Dom.setStyle(that.autoLinks[that.autoIndex].node, 'display', that.slideDisplay);
/*			var oFadeOut = new YAHOO.util.Anim(that.image, {
					opacity: { to: 0 }
				}, 0.25, YAHOO.util.Easing.easeOut);
			oFadeOut.animate(); */
			var oFadeIn = new YAHOO.util.Anim(that.autoLinks[that.autoIndex].node, {
					opacity: { from: 0, to: 1 }
				}, 0.25, YAHOO.util.Easing.easeOut);
			oFadeIn.animate();
		}
	}; // autoClick()
	
	this.xmlClick = function(pTarget){
		if(that.xmlLink != false){
			if(typeof(that.xmlObject[pTarget.title]) != 'undefined'){
				if(typeof(that.xmlLink.id) == 'string'){
					that.xmlLink.href = that.xmlObject[pTarget.title].url;
				} else {
					for(var i=0; i<that.xmlLink.length; i++){
						that.xmlLink[i].href = that.xmlObject[pTarget.title].url;
					}
				}
				YAHOO.util.Dom.setStyle(that.xmlLink, 'display', that.xmlLinkDisplay);
			} else {
				YAHOO.util.Dom.setStyle(that.xmlLink, 'display', 'none');
			}
		}
		if(that.xmlPrice != false){
			if(typeof(that.xmlObject[pTarget.title]) != 'undefined'){
				that.xmlPrice.innerHTML = that.xmlPricePrefix + that.xmlObject[pTarget.title].price + that.xmlPriceSuffix;
				YAHOO.util.Dom.setStyle(that.xmlPrice, 'display', that.xmlPriceDisplay);
			} else {
				YAHOO.util.Dom.setStyle(that.xmlPrice, 'display', 'none');
			}
		}
		if(that.xmlMPG != false){
			if(typeof(that.xmlObject[pTarget.title]) != 'undefined'){
				if(parseInt(that.xmlObject[pTarget.title].mpg, 10) > 0){
					that.xmlMPG.innerHTML = that.xmlMPGPrefix + that.xmlObject[pTarget.title].mpg + that.xmlMPGSuffix;
					YAHOO.util.Dom.setStyle(that.xmlMPG, 'display', that.xmlMPGDisplay);
				} else {
					YAHOO.util.Dom.setStyle(that.xmlMPG, 'display', 'none');
				}
			} else {
				YAHOO.util.Dom.setStyle(that.xmlMPG, 'display', 'none');
			}
		}
	}; // xmlClick()
	
	this.nextPrevClick = function(e){
		YAHOO.util.Event.stopPropagation(e);
		var oTarget = YAHOO.util.Event.getTarget(e);
		switch(oTarget.id){
			case that.previous.id:
				if(that.currentResultIndex > 0 && that.busy == false){
					that.currentResultIndex--;
					that.loadIncentive();
				}
				break;
			case that.next.id:
				if(that.currentResultIndex + 1 < that.currentResults.length && that.busy == false){
					that.currentResultIndex++;
					that.loadIncentive();
				}
				break;
			default:
				return true;
		}
	}; // this.nextPrevClick()
	
	this.loadIncentive = function(pIndex){
		var oIndex = (pIndex) ? pIndex : that.currentResultIndex;
		that.currentResultIndex = oIndex;
		var oResult = that.currentResults[oIndex];
		// Viewing:
		that.viewing.innerHTML = that.viewingPrefix + (that.currentResultIndex + 1) + that.viewingBridge + (that.currentResults.length) + that.viewingSuffix;
		YAHOO.util.Dom.setStyle(that.viewing, 'display', that.viewingDisplay);
		// Rebate:
		if(oResult.rebate != false){
			that.rebate.innerHTML = that.rebatePrefix + oResult.rebate + that.rebateSuffix;
			YAHOO.util.Dom.setStyle(that.rebate, 'display', that.rebateDisplay);
		} else {
			YAHOO.util.Dom.setStyle(that.rebate, 'display', 'none');
		}
		// Rates:
		if(oResult.rates.length > 0){
			that.aprLow.innerHTML = that.aprPrefix + oResult.lowestAPR + that.aprSuffix;
			that.rates.innerHTML = '';
			for(var i=0; i<oResult.rates.length; i++){
				that.rates.innerHTML += '<li>' + that.ratesPrefix + oResult.rates[i].apr + that.ratesBridge + oResult.rates[i].term + that.ratesSuffix + '</li>';
			}
			YAHOO.util.Dom.setStyle(that.aprLow, 'display', that.aprDisplay);
			YAHOO.util.Dom.setStyle(that.rates, 'display', that.ratesDisplay);
		} else {
			YAHOO.util.Dom.setStyle([that.aprLow, that.rates], 'display', 'none');
		}
		// Lease:
		if(oResult.lease != false){
			that.lease.innerHTML = '';
			for(var i in oResult.lease){
				that.lease.innerHTML += '<li>' + that.leasePrefix + oResult.lease[i].text + that.leaseBridge + oResult.lease[i].trim + that.leaseSuffix + '</li>';
			}
			YAHOO.util.Dom.setStyle(that.lease, 'display', that.ratesDisplay);
		} else {
			YAHOO.util.Dom.setStyle(that.lease, 'display', 'none');
		}
		// Image:
		YAHOO.util.Dom.setStyle(that.image, 'display', that.imageDisplay);
		// Disclaimer:
		that.disclaimer.innerHTML = oResult.disclaimer;
		YAHOO.util.Dom.setStyle(that.disclaimer, 'display', that.disclaimerDisplay);
		// Details:
		that.details.href = oResult.url;
		YAHOO.util.Dom.setStyle(that.details, 'display', that.detailsDisplay);
	}; // loadIncentive()
	
	this.fadeImageOut = function(pTarget){
		var oFadeOut = new YAHOO.util.Anim(that.image, {
				opacity: { to: 0 }
			}, 0.25, YAHOO.util.Easing.easeOut);
		oFadeOut.animate();
		oFadeOut.onComplete.subscribe(function(){
			that.image.src = that.imagePath + pTarget.title.toLowerCase().replace(/\s/g, '-') + '.jpg';
			that.image.alt = pTarget.title;
		});
	}; // fadeImageOut()
	
	this.fadeImageIn = function(){
		YAHOO.util.Dom.setStyle(that.image, 'display', that.imageDisplay);
		var oFadeIn = new YAHOO.util.Anim(that.image, {
				opacity: { to: 1 }
			}, 0.25, YAHOO.util.Easing.easeOut);
		oFadeIn.animate();
	}; // fadeImageIn()
	
	this.hideEverything = function(){
		for(var i in that){
			if(typeof(that[i].nodeType) != 'undefined'){
				if(that[i].nodeType === 1 && i != 'slider' && i != 'slidee' && i != 'links' && i != 'scrollLeft' && i != 'scrollRight'){
					YAHOO.util.Dom.setStyle(that[i], 'display', 'none');
				}
			}
		}
	}; // hideEverything()
	
	this.scrollOver = function(e){
		var oTarget = YAHOO.util.Event.getTarget(e);
		if(oTarget.id != that.scrollLeft.id && oTarget.id != that.scrollRight.id){
			if(YAHOO.util.Dom.isAncestor(that.scrollLeft, oTarget)){
				oTarget = that.scrollLeft;
			} else {
				oTarget = that.scrollRight;
			}
		}
		switch(oTarget.id){
			case that.scrollLeft.id:
				that.scrollInterval = setInterval(that.scrollLeftLoop, that.scrollIncrement);
				break;
			case that.scrollRight.id:
				that.scrollInterval = setInterval(that.scrollRightLoop, that.scrollIncrement);
				break;
			default:
				// Do nothing.
		}
	}; // scrollOver()
	
	this.scrollOut = function(e){
		clearInterval(that.scrollInterval);
	}; // scrollOver()
	
	this.scrollRightLoop = function(){
		var oLeft = parseInt(YAHOO.util.Dom.getStyle(that.slidee, 'left'));
		var oAbsoluteLeft = (oLeft > 0) ? oLeft : -(oLeft);
		var oMax =  that.slideeWidth - that.sliderWidth;
		if(oAbsoluteLeft < oMax){
			YAHOO.util.Dom.setStyle(that.slidee, 'left', (oLeft - that.scrollIncrement) + 'px');
		}
	}; // scrollRightLoop()
	
	this.scrollLeftLoop = function(){
		var oLeft = parseInt(YAHOO.util.Dom.getStyle(that.slidee, 'left'));
		if(oLeft < 0){
			YAHOO.util.Dom.setStyle(that.slidee, 'left', (oLeft + that.scrollIncrement) + 'px');
		}
	}; // scrollLeftLoop()
	
	this.initSlider = function(){
		if(this.scrollLeft != false && this.scrollRight != false){
			YAHOO.util.Dom.setStyle(this.slidee, 'width', this.slideeWidth + 'px');
			this.scrollLeft = document.getElementById(this.scrollLeft);
			this.scrollRight = document.getElementById(this.scrollRight);
			YAHOO.util.Event.addListener([this.scrollLeft, this.scrollRight], 'mouseover', this.scrollOver);
			YAHOO.util.Event.addListener([this.scrollLeft, this.scrollRight], 'mouseout', this.scrollOut);
			YAHOO.util.Event.addListener(this.links, this.sliderEvent, this.carClick);
		}
	}; // initSlider()
	
	this.initHeading = function(){
		if(this.heading != false){
			this.heading = document.getElementById(this.heading);
		}
	}; // initHeading()
	
	this.initImage = function(){
		if(this.image != false){
			this.image = document.getElementById(this.image);
			this.imageFlag = true;
		}
	}; // initImage()
	
	this.initInventory = function(){
		if(this.inventory != false){
			this.inventory = document.getElementById(this.inventory);
		}
	}; // initInventory()
	
	this.initResearch = function(){
		if(this.research != false){
			this.researchPath = '/carresearch/TrimsBuildDealer/confid_' + this.confid + '/model_';
			if(this.altResearchTemplate != false){
				this.researchPath = this.researchPath.replace(/TrimsBuildDealer/, this.altResearchTemplate);
			}
			this.research = document.getElementById(this.research);
		}
	}; // initResearch()
	
	this.initQuote = function(){
		if(this.quote != false){
			this.quote = document.getElementById(this.quote);
		}
	}; // initQuote()
	
	this.initIncentives = function(){
		if(this.incentives != false){
			// STOP! Hammer time:
			this.incentivesEnabled = true;
			this.incentives = false;
			// Setup elements:
			if(this.previous != false){ this.previous = document.getElementById(this.previous); }
			if(this.next != false){ this.next = document.getElementById(this.next); }
			if(this.viewing != false){ this.viewing = document.getElementById(this.viewing); }
			if(this.rebate != false){ this.rebate = document.getElementById(this.rebate); }
			if(this.aprLow != false){ this.aprLow = document.getElementById(this.aprLow); }
			if(this.rates != false){ this.rates = document.getElementById(this.rates); }
			if(this.lease != false){ this.lease = document.getElementById(this.lease); }
			if(this.disclaimer != false){ this.disclaimer = document.getElementById(this.disclaimer); }
			if(this.details != false){ this.details = document.getElementById(this.details); }
			// Make requests:
			this.incentivesConfid = this.confid.split(',');
			for(var i=0; i<this.incentivesConfid.length; i++){
				var antiRace = i;
				this.MIL[i] = new MILAPI(this.incentivesConfid[i]);
				this.MIL[i].getAll(function(pIndex){
					that.sortIncentives(that.MIL[pIndex].XML, pIndex);
					that.completedRequests++;
					if(that.completedRequests == that.incentivesConfid.length){
						YAHOO.util.Event.addListener([that.previous, that.next], 'click', that.nextPrevClick);
						that.incentives = true;
						that.incentivesLoaded = true;
					}
				}, antiRace + ''); // this.MIL.getAll()
			}
		}
	}; // initIncentives()
	
	this.initAutoplay = function(){
		if(this.autoplay != false){
			this.autoLinks = [];
			// Slides?
			if(this.slides != false && this.image != false){
				this.autoIndex = 0;
				//this.autoLinks = [];
				YAHOO.util.Dom.setStyle(this.image, 'opacity', 0);
				for(var i=0; i<this.slides.length; i++){
					this.autoLinks.push({
						type: 'slide',
						node: document.getElementById(this.slides[i])
					});
				}
			}
			// Links:
			for(var i=0; i<this.links.length; i++){
				this.autoLinks.push({
					type: 'link',
					node: this.links[i]
				});
			}
			// Start:
			var autoStart = function(){
				if(that.autoInstant){
					that.autoClick();
				}
				that.autoplay = setInterval(that.autoClick, that.autoInterval);
			};
			if(this.incentivesEnabled){
				var oLoop = setInterval(function(){
					if(that.incentivesLoaded){
						autoStart();
						clearInterval(oLoop);
					}
				}, 100);
			} else {
				autoStart();
			}
		}
	}; // initAutoplay()
	
	this.initXML = function(o){
		if(this.xmlLink || this.xmlPrice || this.xmlMPG){
			var oResults = o.responseXML.getElementsByTagName('special');
			for(var i=0; i<oResults.length; i++){
				var oTitle = oResults[i].getElementsByTagName('description')[0].childNodes[0].nodeValue;
				var oPrice = oResults[i].getElementsByTagName('price')[0].childNodes[0].nodeValue;
				var oMPG = oResults[i].getElementsByTagName('mpg')[0].childNodes[0].nodeValue;
				if(oResults[i].getElementsByTagName('year').length > 0){
					var oYear = oResults[i].getElementsByTagName('year')[0].childNodes[0].nodeValue;
				} else {
					var oYear = new Date().getFullYear();
				}
				var oURL = oResults[i].getElementsByTagName('url')[0].childNodes[0].nodeValue;
				that.xmlObject[oTitle] = {
					model: oTitle,
					price: oPrice,
					mpg: oMPG,
					year: oYear,
					url: oURL
				};
			}
			if(this.xmlLink){
				if(typeof(that.xmlLink) == 'string'){
					that.xmlLink = document.getElementById(that.xmlLink);
				} else {
					var oTemp = [];
					for(var i=0; i<that.xmlLink.length; i++){
						oTemp.push(document.getElementById(that.xmlLink[i]));
					}
					that.xmlLink = oTemp;
				}
			}
			if(this.xmlPrice){
				that.xmlPrice = document.getElementById(that.xmlPrice);
			}
			if(this.xmlMPG){
				that.xmlMPG = document.getElementById(that.xmlMPG);
			}
		}
	}; // initXML()
	
	// Init:
	
	this.init = function(){
		var delay = function(o){
			that.initSlider();
			that.initHeading();
			that.initImage();
			that.initInventory();
			that.initResearch();
			that.initQuote();
			that.initIncentives();
			that.initAutoplay();
			if(typeof(o) != 'undefined'){
				that.initXML(o);
			}
		};
		if(this.xmlLink || this.xmlPrice || this.xmlMPG){
			var oRequest = YAHOO.util.Connect.asyncRequest('GET', this.xmlPath, {
				success:  delay,
				failure: function(){}
			}, null);
		} else {
			delay();
		}
	}; // init()
	
};

})();