/* Matchmaker 3 v0.8 - Details View JS */
/* Copyright 2009 Autofusion.com */

(function(){

/* indexOf() for Arrays */

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

/* Autofusion Object */

if(typeof(YAHOO.AUTOFUSION) == 'undefined'){
	YAHOO.namespace('AUTOFUSION');
}
if(typeof(YAHOO.AUTOFUSION.items) == 'undefined'){
	YAHOO.AUTOFUSION.items = new Object();
}
if(typeof(YAHOO.AUTOFUSION.JWS) == 'undefined'){
	YAHOO.AUTOFUSION.JWS = new Object(); // Instantiation must wait for confid.
}
var AF = YAHOO.AUTOFUSION;
var JWS = YAHOO.AUTOFUSION.JWS;

/* Details View Plugin */

// Matchmaker Object
AF.Matchmaker = new Object;
var MM = AF.Matchmaker;

// Details Object
MM.Details = function(mmConfig){
	this.config = new Object();
	this.defaults = new Object();
	this.prefs = new Object();
	this.user = new Object();
	this.params = new Object();
	this.vocab = new Object();
	this.phrases = new Object();
	this.vehicle = new Object();
	this.price = 0;
	this.image = this.image = document.getElementById("details_CurrentPhoto");
	this.imageArray = new Array();
	this.imageIndex = 0;
	this.ext360 = "";
	this.int360 = "";
	this.tabView = new Object();
	var that = this;
	this.stringCap = function(pString){
		return(pString.charAt(0).toUpperCase()+pString.substr(1).toLowerCase());
	}; // this.stringCap()
	this.isEmpty = function(pObj){
		for (var prop in pObj) {
			if (pObj.hasOwnProperty(prop)) return false;
		}
		return true;
	}; // this.isEmpty()
	this.bounceOver = function(e){
		var oTarget = YAHOO.util.Event.getTarget(e);
		if(oTarget.nodeName.toUpperCase() != "A"){
			oTarget = YAHOO.util.Dom.getAncestorByTagName(oTarget, "a");
		}
		var oOver = new YAHOO.util.Anim(oTarget, {
				paddingLeft: { to: parseInt(this.config.mmBounceAfter) }
			}, parseFloat(this.config.mmBounceSpeed), YAHOO.util.Easing[this.config.mmBounceEasing]);
		oOver.animate();
	}; // this.bounceOver()
	this.bounceOut = function(e){
		var oTarget = YAHOO.util.Event.getTarget(e);
		if(oTarget.nodeName.toUpperCase() != "A"){
			oTarget = YAHOO.util.Dom.getAncestorByTagName(oTarget, "a");
		}
		var oOut = new YAHOO.util.Anim(oTarget, {
				paddingLeft: { to: parseInt(this.config.mmBounceBefore) }
			}, parseFloat(this.config.mmBounceSpeed), YAHOO.util.Easing[this.config.mmBounceEasing]);
		oOut.animate();
	}; // this.bounceOut()
	this.initBounce = function(){
		var oGettingStarted = document.getElementById("details_GettingStarted");
		var oAs = oGettingStarted.getElementsByTagName("a");
		YAHOO.util.Event.addListener(oAs, "mouseover", this.bounceOver, this, true);
		YAHOO.util.Event.addListener(oAs, "mouseout", this.bounceOut, this, true);
	}; // this.initBounce()
	this.newSearch = function(e){
		if(typeof(e) != "undefined"){
			YAHOO.util.Event.preventDefault(e);
		}
		if(that.user.mode == that.defaults.mode){
			window.location.href = that.config.mmIndex;
		} else {
			window.location.href = that.config.mmIndex + '?mode=' + that.user.mode;
		}
	}; // this.newSearch()
	this.googleMap = function(e){
		YAHOO.util.Event.preventDefault(e);
		if(YAHOO.util.Dom.inDocument("details_MapPanel")){
			var oMapRemove = document.getElementById("details_MapPanel");
			document.body.removeChild(oMapRemove.parentNode);
		} else {
			YAHOO.util.Event.addListener(document.body, "unload", GUnload);
		}
		var oPanel = new YAHOO.widget.Panel("details_MapPanel", {
			fixedcenter: true,
			constraintoviewport: true,
			close: true,
			effect: { effect: YAHOO.widget.ContainerEffect.FADE, duration: 0.25 },
			zIndex: 30000
		});
		oPanel.setHeader(this.vocab['Map to Vehicle']);
		oPanel.setBody('<div id="details_GoogleMap"></div>');
		oPanel.render(document.body);
		var oGMap = new GMap2(document.getElementById("details_GoogleMap"), { size: new GSize(480, 385) });
		if(GBrowserIsCompatible()){
			var oPoint = new GLatLng(this.vehicle.basic.latitude, this.vehicle.basic.longitude);
			oGMap.setCenter(oPoint, 14);
			oGMap.setUIToDefault();
			var oDealerIcon = new GIcon();
			oDealerIcon.image = this.config.mmGMapIcon;
			oDealerIcon.shadow = this.config.mmGMapIconShadow;
			oDealerIcon.iconSize = new GSize(40, 40);
			oDealerIcon.iconAnchor = new GPoint(20, 20);
			oDealerIcon.infoWindowAnchor = new GPoint(20, 20);
			var oMarker = new GMarker(oPoint, { icon: oDealerIcon });
			oGMap.addOverlay(oMarker);
			oMarker.openInfoWindowHtml('\
				' + this.vehicle.basic.year + ' ' + this.vehicle.basic.make + ' ' + this.vehicle.basic.model + ' ' + this.vehicle.basic.trim + '\
				<br />at ' + this.vehicle.dealer.name + '.<br /><br />\
				<a href="http://maps.google.com/maps?daddr=' + this.vehicle.dealer.addr1 + ', ' + this.vehicle.dealer.city + ', ' + this.vehicle.dealer.state + ' ' + this.vehicle.dealer.zip + '" target="_blank">' + this.vocab['Get Directions'] + '</a>\
			', { noCloseOnClick: true });
		} else {
			oGMap.innerHTML = '<p>Sorry, but your browser does not support Google Maps.</p>';
		}
	} // this.googleMap()
	this.getQuote = function(pTitle){
		if(YAHOO.util.Dom.inDocument("details_QuoteForm")){
			var oQuoteRemove = document.getElementById("details_QuoteForm");
			document.body.removeChild(oQuoteRemove.parentNode);
		}
		
		// Privacy Popup?
		var oPrivacyInput = (this.config.mmPrivacyPopup == 'true') ? 'no': 'yes';
		
		var oQuoteElement = document.createElement("div");
		oQuoteElement.id = "details_QuoteForm";
		oQuoteElement.className = "details_FormDialog";
		document.body.appendChild(oQuoteElement);
		oQuoteElement.innerHTML = '\
			<div class="hd">' + pTitle + '</div>\
			<div class="bd">\
				<form id="details_ContactForm" name="details_ContactForm" method="post" action="/AF2/ContactForm.php">\
					<input type=hidden name="ContactFormId" value="details_ContactForm">\
					<input type=hidden name="program" value="inventory_lead">\
					<input type=hidden name="return" value="' + this.config.mmThankYou + '">\
					<input type=hidden name="partner" value="' + document.getElementById('details_Partner').value + '">\
					<input type=hidden name="charge" value="">\
					<input type=hidden name="year" value="' + this.vehicle.basic.year + '">\
					<input type=hidden name="make" value="' + this.vehicle.basic.make + '">\
					<input type=hidden name="model" value="' + this.vehicle.basic.model + '">\
					<input type=hidden name="trim" value="' + this.vehicle.basic.trim + '">\
					<input type=hidden name="car_id" value="' + this.vehicle.basic.car_id + '">\
					<input type=hidden name="vin" value="' + this.vehicle.basic.vin + '">\
					<input type=hidden name="dealer" value="' + this.vehicle.basic.loc_id + '">\
					<input type=hidden name="vehicle_type" value="' + this.stringCap(this.vehicle.basic.type) + '">\
					<input type=hidden name="sent_to" value="">\
					<input type="hidden" name="privacy" value="' + oPrivacyInput + '"/>\
					<table width="100%">\
						<tr>\
							<td colspan="2" class="section_title">' + this.vocab['Vehicle Information'] + '</td>\
						</tr>\
						<tr valign="top">\
							<td class="vehicle_detail">&nbsp;&nbsp;' + this.vehicle.basic.year + ' ' + this.vehicle.basic.make + '<br />&nbsp;&nbsp;' + this.vehicle.basic.model + ' ' + this.vehicle.basic.trim + '<br />&nbsp;&nbsp;<span class="vin_number">' + this.vocab['VIN'] + ': ' + this.vehicle.basic.vin + '</span><br /></td>\
							<td class="vehicle_detail">' + this.vocab['Exterior Color'] + ': <input type="hidden" name="exterior" value="' + this.vehicle.basic.exterior + '">' + this.vehicle.basic.exterior + '<br />' + this.vocab['Interior Color'] + ': <input type="hidden" name="interior" value="' + this.vehicle.basic.interior + '">' + this.vehicle.basic.interior + '</td>\
						</tr>\
						<tr valign="top">\
							<td><b>' + this.vocab['Timeframe to Purchase'] + '</b></td>\
							<td><b>' + this.vocab['Purchase Method'] + '</b></td>\
						</tr>\
						<tr valign="top">\
							<td>&nbsp;&nbsp;\
								<select name="timeframe" style="width:150px">\
								<option value="1">' + this.vocab['Within'] + ' 48 ' + this.vocab['Hours'] + '</option>\
								<option value="2">' + this.vocab['Within'] + ' ' + this.vocab['a'] + ' ' + this.vocab['Week'] + '</option>\
								<option value="3">' + this.vocab['Within'] + ' ' + this.vocab['Two'] + ' ' + this.vocab['Week'] + 's</option>\
								<option value="4">' + this.vocab['Within'] + ' ' + this.vocab['a'] + ' ' + this.vocab['Month'] + '</option>\
								</select>\
							</td>\
							<td>&nbsp;&nbsp;\
								<select name="method" style="width:150px">\
								<option value="0">' + this.vocab['Lease'] + '</option>\
								<option value="1">' + this.vocab['Loan'] + '</option>\
								<option value="2">' + this.vocab['Cash'] + '</option>\
								<option value="3">' + this.vocab['Credit Union'] + '</option>\
								</select>\
							</td>\
						</tr>\
						<tr>\
							<td colspan="2"><b>' + this.vocab['Other Comments'] + '</b></td>\
						</tr>\
						<tr>\
							<td colspan="2">&nbsp;&nbsp;\
								<textarea name="comments" rows="4" style="width:90%" wrap="soft"></textarea>\
							</td>\
						</tr>\
						<tr>\
							<td colspan="2" class="section_title">' + this.vocab['Personal Information'] + '</td>\
						</tr>\
						<tr valign="top">\
							<td><b>' + this.vocab['First Name'] + ' *</b></td>\
							<td><b>' + this.vocab['Last Name'] + ' *</b></td>\
						</tr>\
						<tr valign="top">\
							<td>&nbsp;&nbsp;<input type="text" name="firstname" value="" style="width:150px"></td>\
							<td>&nbsp;&nbsp;<input type="text" name="lastname" value="" style="width:150px"></td>\
						</tr>\
						<tr>\
							<td><b>' + this.vocab['Address'] + '</b></td>\
						</tr>\
						<tr>\
							<td colspan=2>&nbsp;&nbsp;<input type="text" name="addr1" style="width:90%" value=""></td>\
						</tr>\
						<tr valign="top">\
							<td><b>' + this.vocab['Zip Code'] + ' *</b></td>\
							<td><b>' + this.vocab['Best Time to Contact'] + '</b></td>\
						</tr>\
						<tr valign="top">\
							<td>&nbsp;&nbsp;<input type="text" name="zip" size="7" maxlength="7" value=""></td>\
							<td>&nbsp;&nbsp;\
								<select name="besttime" style="width:150px">\
								<option value="1">' + this.vocab['Anytime'] + '</option>\
								<option value="2">' + this.vocab['Morning'] + '</option>\
								<option value="3">' + this.vocab['Afternoon'] + '</option>\
								<option value="4">' + this.vocab['Evening'] + '</option>\
								<option value="5">' + this.vocab['Business Hours'] + '</option>\
								<option value="6">' + this.vocab['Weekend'] + '</option>\
								</select>\
							</td>\
						</tr>\
						<tr valign="top">\
							<td><b>' + this.vocab['Email'] + ' *</b></td>\
							<td><b>' + this.vocab['Phone'] + ' *</b></td>\
						</tr>\
						<tr valign="top">\
							<td>&nbsp;&nbsp;<input type="text" name="email" style="width:200px" value=""></td>\
							<td>&nbsp;&nbsp;(\
								<input type="text" name="phone_area" size="3" maxlength="3" value=""> )\
								<input type="text" name="phone_pre" size="3" maxlength="3" value=""> -\
								<input type="text" name="phone_last" size="4" maxlength="4" value=""> ext.\
								<input type="text" name="phone_ext" size="5" maxlength="5" value=""></td>\
						</tr>\
						<tr>\
							<td colspan="2" align="center"><br />\
								<input type="submit" value="' + this.vocab['Submit'] + '">\
							</td>\
						</tr>\
					</table>\
				</form>\
			</div>\
		';
		var oQuoteForm = new YAHOO.widget.Dialog("details_QuoteForm", {
			width: "640px",
			fixedcenter: true,
			visible: false,
			constraintoviewport: true,
			close: true,
			effect: { effect: YAHOO.widget.ContainerEffect.FADE, duration: 0.25 },
			zIndex: 30000
		});
		oQuoteForm.callback = {
			success: function(o){
				window.location.href = that.config.mmThankYou + '?i=quote';
			},
			failure: function(o){
				alert("We're sorry, there was a problem submitting your form: " + o.status);
			}
		};
		oQuoteForm.validate = function() {
			function check_privacy(){
				if(document.details_ContactForm.privacy.value == 'yes'){
					return true;
				} else {
					window.open(that.config.mmPrivacyPopupURL + '?form=mm3&formname=details_ContactForm', 'privacy_policy');
					return false;
				}
			}
			function checkSubmit(form) {
				if (chk_text_min_len('First Name', form.firstname, 2, true))
				if (chk_text_min_len('Last Name', form.lastname, 2, true))
				if (chk_zip(form.zip, true))
				if (chk_email('E-mail Address', form.email, true))
				if (chk_num_len('Area Code', form.phone_area, 3, true))
				if (chk_num_len('Phone Prefix', form.phone_pre, 3, true))
				if (chk_num_len('Phone Suffix', form.phone_last, 4, true))
				if (chk_phone('Phone Number', form.phone_pre, form.phone_last))
				if (check_privacy())
					return true;
				return false;
			}
			var oForm = document.getElementById("details_ContactForm");
			return checkSubmit(oForm);
		};
		oQuoteForm.render(document.body);
		oQuoteForm.show();
	}; // this.getQuote()
	this.printPage = function(){
		window.print();
	}; // this.printPage()
	this.sendLink = function(){
		if(YAHOO.util.Dom.inDocument("details_LinkForm")){
			var oLinkRemove = document.getElementById("details_LinkForm");
			document.body.removeChild(oLinkRemove.parentNode);
		}
		
		// Privacy Popup?
		var oPrivacyInput = (this.config.mmPrivacyPopup == 'true') ? 'no': 'yes';
		
		var oLinkElement = document.createElement("div");
		oLinkElement.id = "details_LinkForm";
		oLinkElement.className = "details_FormDialog";
		document.body.appendChild(oLinkElement);
		oLinkElement.innerHTML = '\
			<div class="hd">' + this.vocab['Email Link to Friend'] + '</div>\
			<div class="bd">\
				<form id="details_EmailFriendForm" name="details_EmailFriendForm" method="post" action="/inventory/emailfriend2.php">\
					<input type="hidden" name="send" value="1" />\
					<input type="hidden" name="vin" value="' + this.vehicle.basic.vin + '" />\
					<input type="hidden" name="privacy" value="' + oPrivacyInput + '"/>\
					<input type="hidden" name="url" value="' + document.location.href + '" />\
					<table border="0" class="ContactForm">\
						<tr>\
							<td align="left" class="a12">' + this.vocab['Your'] + ' ' + this.vocab['Name'] + ':</td>\
							<td><input type="text" name="yourname" size="40" /></td>\
						</tr>\
						<tr>\
							<td align="left" class="a12">' + this.vocab['Your'] + ' ' + this.vocab['Email'] + ':</td>\
							<td><input type="text" name="youremail" size="40" /></td>\
						</tr>\
						<tr>\
							<td align="left" class="a12" nowrap>' + this.vocab['Name'] + ' ' + this.vocab['of'] + ' ' + this.vocab['Friend'] + ':</td>\
							<td><input type="text" name="friendname" size="40" /></td>\
						</tr>\
						<tr>\
							<td align="left" class="a12">' + this.vocab['Email'] + ' ' + this.vocab['of'] + ' ' + this.vocab['Friend'] + ':</td>\
							<td><input type="text" name="friendemail" size="40" /></td>\
						</tr>\
						<tr>\
							<td colspan="2" class="a12">' + this.vocab['Comments'] + ':<br /><textarea name="comments" cols="60" rows="5"></textarea></td>\
						</tr>\
						<tr>\
							<td colspan="2" align="center"><input type="submit" value="' + this.vocab['Send'] + '" /></td>\
						</tr>\
					</table>\
				<form>\
			</div>\
		';
		var oLinkForm = new YAHOO.widget.Dialog("details_LinkForm", {
			width : "540px",
			fixedcenter : true,
			visible : false,
			constraintoviewport: true,
			close: true,
			effect: { effect: YAHOO.widget.ContainerEffect.FADE, duration: 0.25 },
			zIndex: 30000
		});
		oLinkForm.callback = {
			success: function(o){
				window.location.href = that.config.mmThankYou + '?i=email';
			},
			failure: function(o){
				alert("We're sorry, there was a problem submitting your form: " + o.status);
			}
		};
		oLinkForm.validate = function() {
			function check_privacy(){
				if(document.details_EmailFriendForm.privacy.value == 'yes'){
					return true;
				} else {
					window.open(that.config.mmPrivacyPopupURL + '?form=mm3&formname=details_EmailFriendForm', 'privacy_policy');
					return false;
				}
			}
			function checkSubmit(form) {
				if (chk_text_min_len(that.vocab['Your'] + ' ' + that.vocab['Name'], form.yourname, 2, true))
				if (chk_email(that.vocab['Your'] + ' ' + that.vocab['Email'], form.youremail, true))
				if (chk_text_min_len(that.vocab['Name'] + ' ' + that.vocab['of'] + ' ' + that.vocab['Friend'], form.friendname, 2, true))
				if (chk_email(that.vocab['Email'] + ' ' + that.vocab['of'] + ' ' + that.vocab['Friend'], form.friendemail, true))
				if (check_privacy())
					return true;
				return false;
			}
			var oForm = document.getElementById("details_EmailFriendForm");
			return checkSubmit(oForm);
		};
		oLinkForm.render(document.body);
		oLinkForm.show();
	}; // this.sendLink()
	this.calculatePayments = function(){
		if(YAHOO.util.Dom.inDocument("details_PaymentsPanel")){
			var oPaymentRemove = document.getElementById("details_PaymentsPanel");
			document.body.removeChild(oPaymentRemove.parentNode);
		}
		var oPanel = new YAHOO.widget.Panel("details_PaymentsPanel", {
			fixedcenter: true,
			constraintoviewport: true,
			close: true,
			effect: { effect: YAHOO.widget.ContainerEffect.FADE, duration: 0.25 },
			zIndex: 30000
		});
		oPanel.setHeader(this.vocab['Calculate Payments']);
		if(parseInt(this.vehicle.basic.sale_price) != 0){
			var oTerms = this.config['mmCalculatorTerms'].split(',');
			var oTermString = '';
			for(var i=0; i<oTerms.length; i++){
				var oSelected = (oTerms[i] == this.config['mmCalculatorDefault']) ? 'selected="selected"': '';
				oTermString += '<option ' + oSelected + ' value="' + oTerms[i] + '">' + oTerms[i] + ' ' + this.vocab['Month'] + 's</option>';
			}
			oPanel.setBody('\
				<form name="lease_loan_calc">\
					<input type="hidden" name="price" value="' + this.vehicle.basic.sale_price + '" />\
					<input type=hidden name="loan_amnt_due" />\
					<input type=hidden name="loan_total_interest" />\
					<input type="hidden" name="lease_deposit" value="1" />\
					<input type=hidden name="residual_rating" value="high" />\
					<input type="hidden" name="lease_amnt_due" />\
					<input type="hidden" name="lease_payment" />\
					<p><em>' + this.vocab['Sales Tax'] + ':</em> <input name="tax" type="text" value="' + this.config['mmCalculatorTax'] +'" />%<br class="mm3_ClearDiv" /></p>\
					<p><em>' + this.vocab['Cash'] + '/' + this.vocab['Trade'] + ':</em> $<input name="downpayment" type="text" value="' + parseInt(parseFloat(this.vehicle.basic.sale_price) * parseFloat(this.config['mmCalculatorDeposit'])) + '" /><br class="mm3_ClearDiv" /></p>\
					<p>\
						<em>' + this.vocab['Terms'] + ':</em>\
						<select name="term">\
							' + oTermString + '\
						</select>\
						<br class="mm3_ClearDiv" />\
					</p>\
					<p><em>Rate:</em> <input name="apr" type="text" value="' + this.config['mmCalculatorRate'] +'" />%<br class="mm3_ClearDiv" /></p>\
					<p id="details_Recalculate"><button id="details_CalcButton" type="button">' + this.vocab['Calculate'] + '</button></p>\
					<p><em>' + this.vocab['Estimated Payment'] + ':</em> $<input name="loan_payment" type="text" /><br class="mm3_ClearDiv" /></p>\
					<p>&nbsp;</p>\
				</form>\
			');
			YAHOO.util.Event.addListener("details_CalcButton", "click", recalculate);
			oPanel.render(document.body);
			recalculate();
		} else {
			oPanel.setBody('<p>' + this.phrases['Details No Calculator'] + '</p>');
			oPanel.render(document.body);
		}
	}; // this.calculatePayments()
	this.viewBrochure = function(){
		window.open('/inventory/details.php/VIN_' + this.params.VIN + '/UI_brochure/ID_' + this.config['mmConfID'],'_blank','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=640, height=480');
	}; // this.viewBrochure()
	this.viewExt360 = function(){
		if(YAHOO.util.Dom.inDocument("details_Ext360")){
			var oPhotosFull = document.getElementById("details_PhotosFull");
			var oExt360 = document.getElementById("details_Ext360");
			oPhotosFull.removeChild(oExt360);
		}
		if(YAHOO.util.Dom.inDocument("details_Int360")){
			var oPhotosFull = document.getElementById("details_PhotosFull");
			var oInt360 = document.getElementById("details_Int360");
			oPhotosFull.removeChild(oInt360);
		}
		var oPhotosFull = document.getElementById("details_PhotosFull");
		var oExt360 = document.createElement("div");
		oExt360.id = "details_Ext360";
		oPhotosFull.appendChild(oExt360);
		var o360Replace = document.createElement("div");
		o360Replace.id = "details_360Replace";
		oExt360.appendChild(o360Replace);
		swfobject.embedSWF(this.ext360, "details_360Replace", "320", "240", "9.0.0", false, {}, { wmode: 'opaque' }, {});
	}; // this.viewExt360()
	this.viewInt360 = function(){
		if(YAHOO.util.Dom.inDocument("details_Ext360")){
			var oPhotosFull = document.getElementById("details_PhotosFull");
			var oExt360 = document.getElementById("details_Ext360");
			oPhotosFull.removeChild(oExt360);
		}
		if(YAHOO.util.Dom.inDocument("details_Int360")){
			var oPhotosFull = document.getElementById("details_PhotosFull");
			var oInt360 = document.getElementById("details_Int360");
			oPhotosFull.removeChild(oInt360);
		}
		var oPhotosFull = document.getElementById("details_PhotosFull");
		var oInt360 = document.createElement("div");
		oInt360.id = "details_Int360";
		oPhotosFull.appendChild(oInt360);
		var o360Replace = document.createElement("div");
		o360Replace.id = "details_360Replace";
		oInt360.appendChild(o360Replace);
		swfobject.embedSWF(this.int360, "details_360Replace", "320", "240", "9.0.0", false, {}, { wmode: 'opaque' }, {});
	}; // this.viewInt360()
	this.imageFadeIn = function(){
		var oPhotosThumbs = document.getElementById("details_PhotosThumbs");
		var oIMGs = oPhotosThumbs.getElementsByTagName("img");
		for(var i=0; i<oIMGs.length; i++){
			oIMGs[i].className = "";
			if(oIMGs[i].id == ("details_Thumb" + this.imageIndex)){
				oIMGs[i].className = "details_CurrentThumb";
			}
		}
		var oFadeIn = new YAHOO.util.Anim(this.image, {
				opacity: { to: 1 }
			}, 0.25, YAHOO.util.Easing.easeOut);
		oFadeIn.animate();
	}; // this.imageFadeIn()
	this.changeImage = function(pIndex){
		if(YAHOO.util.Dom.inDocument("details_Ext360")){
			var oPhotosFull = document.getElementById("details_PhotosFull");
			var oExt360 = document.getElementById("details_Ext360");
			oPhotosFull.removeChild(oExt360);
		}
		if(YAHOO.util.Dom.inDocument("details_Int360")){
			var oPhotosFull = document.getElementById("details_PhotosFull");
			var oInt360 = document.getElementById("details_Int360");
			oPhotosFull.removeChild(oInt360);
		}
		this.imageIndex = pIndex;
		var oImageCounter = document.getElementById("details_ImageCounter");
		var oFadeOut = new YAHOO.util.Anim(this.image, {
				opacity: { to: 0 }
			}, 0.25, YAHOO.util.Easing.easeOut);
		oFadeOut.animate();
		oFadeOut.onComplete.subscribe(function(){
			oImageCounter.innerHTML = (this.imageIndex + 1) + ' of ' + this.imageArray.length;
			this.image.src = this.imageArray[this.imageIndex];
		}, this, true);
	}; // this.changeImage()
	this.loadImages = function(){
		// Sort Out 360 Spins:
		this.imageArray = this.params.carImages;
		if(typeof(this.params.car360s) != "undefined"){
			for(var i=0; i<this.params.car360s.length; i++){
				if(this.params.car360s[i].indexOf("exterior") != -1){
					this.ext360 = this.params.car360s[i];
				} else {
					this.int360 = this.params.car360s[i];
				}
			}
		}
		// Full Photo and Nav:
		var oPhotosFull = document.getElementById("details_PhotosFull");
		var oPhotosNav = document.createElement("div");
		oPhotosNav.id = "details_PhotosNav";
		oPhotosFull.appendChild(oPhotosNav);
		YAHOO.util.Dom.setStyle(oPhotosNav, "opacity", "0.85");
		oPhotosNav.appendChild(document.createTextNode(this.phrases['Details Enlarge']));
		var oBody = document.createElement("span");
		oBody.className = "details_Body";
		oPhotosNav.appendChild(oBody);
		var oThumbsPrev = document.createElement("a");
		oThumbsPrev.id = "details_ThumbsPrev";
		oThumbsPrev.href = "javascript:void(0)";
		oBody.appendChild(oThumbsPrev);
		YAHOO.util.Event.addListener(oThumbsPrev, "click", function(){
			if(this.imageIndex > 0){
				this.changeImage(this.imageIndex - 1);
			}
		}, this, true);
		var oSPAN = document.createElement("span");
		oSPAN.id = "details_ImageCounter";
		oBody.appendChild(oSPAN);
		oSPAN.innerHTML = '1 ' + this.vocab['of'] + ' ' + this.imageArray.length;
		var oThumbsNext = document.createElement("a");
		oThumbsNext.id = "details_ThumbsNext";
		oThumbsNext.href = "javascript:void(0);";
		oBody.appendChild(oThumbsNext);
		YAHOO.util.Event.addListener(oThumbsNext, "click", function(){
			if(this.imageIndex < (this.imageArray.length - 1)){
				this.changeImage(this.imageIndex + 1);
			}
		}, this, true);
		var oBounceIn = new YAHOO.util.Anim(oPhotosNav, {
			bottom: { from: -30, to: 10 }
			}, 0.25, YAHOO.util.Easing.easeOut);
		oBounceIn.animate();
		YAHOO.util.Event.addListener(this.image, "load", this.imageFadeIn, this, true);
		YAHOO.util.Event.addListener(this.image, "click", function(e){
			window.open('/carresearch/viewer.html?vin=' + this.params.VIN,'_blank','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=800, height=575');
		}, this, true);
		// Thumbnails:
		var oPhotosThumbs = document.getElementById("details_PhotosThumbs");
		if(YAHOO.util.Dom.inDocument("details_ThumbExt")){
			YAHOO.util.Event.addListener("details_ThumbExt", "click", this.viewExt360, this, true);
		}
		if(YAHOO.util.Dom.inDocument("details_ThumbInt")){
			YAHOO.util.Event.addListener("details_ThumbInt", "click", this.viewInt360, this, true);
		}
		var oIMGs = oPhotosThumbs.getElementsByTagName("img");
		for(var i=0; i<oIMGs.length; i++){
			if(oIMGs[i].id.indexOf("Ext") == -1 && oIMGs[i].id.indexOf("Int") == -1){
				YAHOO.util.Event.addListener(oIMGs[i], "click", function(e){
					var oTarget = YAHOO.util.Event.getTarget(e);
					var oID = oTarget.id.replace(/details_Thumb/, "");
					this.changeImage(parseInt(oID));
				}, this, true);
			}
		}
		YAHOO.util.Event.addListener("details_MorePhotos", "click", function(e){
			YAHOO.util.Event.preventDefault(e);
			window.open('/carresearch/viewer.html?vin=' + this.params.VIN,'_blank','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=800, height=575');
		}, this, true);
	}; // this.loadImages()
	this.loadDealerInfo = function(){
		YAHOO.util.Event.addListener(["details_MiniMap", "details_LocationLink"], "click", this.googleMap, this, true);
	}; // this.loadDealerInfo()
	this.loadGettingStarted = function(){
		var oGettingStarted = document.getElementById("details_GettingStarted");
		var oAs = oGettingStarted.getElementsByTagName("a");
		for(var i=0; i<oAs.length; i++){
			if(oAs[i].className == "details_GSQuote"){YAHOO.util.Event.addListener(oAs[i], "click", function(e){
				YAHOO.util.Event.preventDefault(e);
				this.getQuote(this.vocab['Get a Quote']);
			}, this, true);}
			else if(oAs[i].className == "details_GSPrint"){YAHOO.util.Event.addListener(oAs[i], "click", function(e){
				YAHOO.util.Event.preventDefault(e);
				this.printPage();
			}, this, true);}
			else if(oAs[i].className == "details_GSOffer"){YAHOO.util.Event.addListener(oAs[i], "click", function(e){
				YAHOO.util.Event.preventDefault(e);
				this.getQuote(this.vocab['Make an Offer']);
			}, this, true);}
			else if(oAs[i].className == "details_GSEmail"){YAHOO.util.Event.addListener(oAs[i], "click", function(e){
				YAHOO.util.Event.preventDefault(e);
				this.sendLink();
			}, this, true);}
			else if(oAs[i].className == "details_GSInfo"){YAHOO.util.Event.addListener(oAs[i], "click", function(e){
				YAHOO.util.Event.preventDefault(e);
				this.getQuote(this.vocab['Request More Info']);
			}, this, true);}
			else if(oAs[i].className == "details_GSCalc"){YAHOO.util.Event.addListener(oAs[i], "click", function(e){
				YAHOO.util.Event.preventDefault(e);
				this.calculatePayments();
			}, this, true);}
			else if(oAs[i].className == "details_GSBrochure"){YAHOO.util.Event.addListener(oAs[i], "click", function(e){
				YAHOO.util.Event.preventDefault(e);
				this.viewBrochure();
			}, this, true);}
		}
	}; // this.loadGettingStarted()
	this.initTabs = function(){
		this.tabView = new YAHOO.widget.TabView("details_TabsBody");
	}; // this.initTabs()
	this.initIncentive = function(){
		if(YAHOO.util.Dom.inDocument('details_IncentiveLink')){
			YAHOO.util.Event.addListener('details_IncentiveLink', 'click', function(){
				if(YAHOO.util.Dom.inDocument("details_IncentivePanel")){
					var oIncentiveRemove = document.getElementById("details_IncentivePanel");
					document.body.removeChild(oIncentiveRemove.parentNode);
				}
				var oPanel = new YAHOO.widget.Panel("details_IncentivePanel", {
					fixedcenter: true,
					constraintoviewport: true,
					close: true,
					effect: { effect: YAHOO.widget.ContainerEffect.FADE, duration: 0.25 },
					zIndex: 30000
				});
				oPanel.setHeader(that.vocab['Disclaimer']);
				//var oComments = YAHOO.util.Dom.getElementsByClassName('inctv_comment');
				var oDisclaimers = YAHOO.util.Dom.getElementsByClassName('inctv_disclaimer');
				var oText = '<div>';
				/*for(var i=0; i<oComments.length; i++){
					if(i > 0){
						oText += '<p>OR</p>';
					}
					oText += '<p>[' + (i + 1) + '] ' + oComments[i].innerHTML + '</p>';
				}
				oText += '</div>';
				if(oDisclaimers.length > 0){
					oText += '<p class="details_Separator"></p>';
				}
				oText += '<div>';*/
				for(var i=0; i<oDisclaimers.length; i++){
					if(i > 0){
						oText += '<p class="details_Separator"></p>';
					}
					oText += '<p>[' + (i + 1) + ']</p>';
					oText += oDisclaimers[i].innerHTML;
				}
				oText += '</div>';
				oPanel.setBody(oText);
				YAHOO.util.Event.addListener("details_CalcButton", "click", recalculate);
				oPanel.render(document.body);
			});
		}
	}; // this.initIncentive()
	this.init = function(){
		// Make sure BODY has skin class:
		if(YAHOO.util.Dom.hasClass(document.body, "yui-skin-sam") == false){
			YAHOO.util.Dom.addClass(document.body, "yui-skin-sam");
		}
		// Populate setup objects:
		this.config = mmConfig.config;
		this.defaults = mmConfig.defaults;
		this.vocab = mmConfig.vocab;
		this.phrases = mmConfig.phrases;
		this.render = mmConfig.render;
		this.custom = mmConfig.custom;
		
		// JWS:
		JWS = new JWSAPI(this.config.mmConfID);
		
		// Hash params?
		if(window.location.hash != ''){
			this.hashParams = {};
			var oHash = window.location.hash.substr(2).split('&');
			for(var i=0; i<oHash.length; i++){
				var oItem = oHash[i].split('=');
				this.hashParams[oItem[0]] = oItem[1];
			}
		}
		
		// Populate this.prefs and this.params:
		this.prefs.per_page = this.defaults.per_page;
		this.prefs.sort = this.defaults.sort;
		var oParamsArray = YAHOO.util.Dom.getChildren("mm3_Parameters");
		var oName = new Array();
		var oValue = new Array();
		for(var i=0; i<oParamsArray.length; i++){
			oName[i] = oParamsArray[i].getAttribute("name");
			oValue[i] = oParamsArray[i].getAttribute("value");
			if(oValue[i] != null && oValue[i] != "undefined" && oValue[i] != "" && oName[i].indexOf('utm_') == -1){
				// User:
				if(oName[i] == "newsearch" || oName[i] == "display" || oName[i] == "mode"){
					this.user[oName[i]] = oValue[i];
				// Prefs (will overwrite default prefs):
				} else if(oName[i] == "per_page" || oName[i] == "sort"){
					this.prefs[oName[i]] = oValue[i];
				// Other params:
				} else {
					if(oValue[i].indexOf(",") != -1){
						oValue[i] = oValue[i].split(",");
					} else if(oName[i].indexOf("Min") == -1 && oName[i].indexOf("Max") == -1 && oName[i].indexOf("Email") == -1 && oName[i].indexOf("StockNum") == -1 && oName[i].indexOf("Zip") == -1){
						// Force Array for anything other than Min/Max, Email, StockNum:
						oValue[i] = [oValue[i]];
					}
					if(oName[i] == "VehicleType"){
						// Change "CPO" to "Certified Pre-Owned" for VehicleType:
						for(var j=0; j<oValue[i].length; j++){
							if(oValue[i][j] == "CPO"){
								oValue[i][j] = "Certified Pre-Owned";
							}
						}
					}
					this.params[oName[i]] = oValue[i];
				}
			} // if()
		} // for()
		if(typeof(this.user.newsearch) != "undefined"){
			this.params = {};
		}
		if(typeof(this.user.mode) == "undefined"){
			this.user.mode = this.defaults.mode;
		}
		// Call setPref and setParam:
		var oPrefs = {
			'function':'i',
			'condition':'all',
			'cars_table':this.config.mmTable,
			'location':this.config.mmQSource,
			'per_page':this.prefs.per_page,
			'sort':this.prefs.sort,
			'use_evox':'Y'
		};
		JWS.setPref(oPrefs, function(pObj){
			// pObj = this!
			JWS.getVehicle(pObj.params.VIN[0], true, function(pObj){
				// pObj = this!
				pObj.params.make = JWS.JSON.vehicle.basic.make;
				pObj.params.model = JWS.JSON.vehicle.basic.model;
				pObj.params.year = JWS.JSON.vehicle.basic.year;
				pObj.params.trim = JWS.JSON.vehicle.basic.trim;
				pObj.params.price = JWS.JSON.vehicle.basic.price;
				pObj.vehicle = JWS.JSON.vehicle;
				if(pObj.config.mmForceLocID != ''){
					pObj.vehicle.basic.loc_id = pObj.config.mmForceLocID;
				}
				YAHOO.util.Event.addListener('details_NewSearch', 'click', that.newSearch);
				pObj.initBounce();
				pObj.loadImages();
				pObj.loadDealerInfo();
				pObj.loadGettingStarted();
				pObj.initTabs();
				pObj.initIncentive();
			}, pObj); // JWS.getVehicle()
		}, this); // JWS.setPref;
	}; // this.init()
}; // MM.Details()

})();