(function(D,A,F){var C=null,B=null,E={call:new A(),vehicleInfo:{},init:function(H){var G=this;this.data=D.extend({yearLimit:(function(){if(H.yearLimit){return parseInt(H.yearLimit,10);}else{var I=new Date();return I.getFullYear();}})()},H);this.call.reseller="ddc";this.call.accountId=this.data.accountId;this.call.service="builder";this.data.labels.make=D("#quickQuoteForm label.make option:eq(0)").text();this.data.labels.year=D("#quickQuoteForm label.year option:eq(0)").text();this.data.labels.model=D("#quickQuoteForm label.model option:eq(0)").text();D("#quickQuoteForm select").change(function(){G.whichSelect(this);});D("#quickQuote .widgetWrap").prepend(this.data.message);D("#quickQuoteForm select:gt(0)").not("select[name*=account]").attr("disabled","true");this.buildLogos(H);this.prepDom();this.doLoadMakes();},buildLogos:function(H){var G=H.bgColor;for(C in this.data.franchises){if(this.data.franchises.hasOwnProperty(C)){this.data.franchises[C].logo="http://static.dealer.com/v8/global/images/franchise/"+G+"/logo-"+C.toString().toLowerCase().replace(" ","-")+"-lrg.jpg";}}},prepDom:function(){var H=this.data.labels,G=D("#quickQuoteForm .submit").clone(true);D("#quickQuoteForm .submit").remove();D("#quickQuoteForm fieldset:eq(0) div:eq(0)").prepend('<span class="qqStep">'+H.STEP_1+": "+H.CHOOSE_YOUR_VEHICLE+"</span>");D("#quickQuoteForm fieldset:eq(0) div:eq(0)").after('<div id="showCase"><div id="qqVehiclePicture" /><div id="qqColorInfo"><div id="qqColorLabel" /><div id="qqColors"><ul class="qqColorInfo"><li class="qqExColorSwatch" /></ul><ul class="qqColorInfo"><li class="qqExColorSwatch" /></ul><ul class="qqColorInfo"><li class="qqExColorSwatch" /></ul><ul class="qqColorInfo"><li class="qqExColorSwatch" /></ul><ul class="qqColorInfo"><li class="qqExColorSwatch" /></ul></li></ul></div> </div></div>');D("#qqVehiclePicture").wrap('<div class="qqVehiclePicture"><div class="north"><div class="east"><div class="south"><div class="west"><div class="northeast"><div class="southeast"><div class="southwest"><div class="northwest"></div></div></div></div></div></div></div></div></div>');D("#qqColorInfo").wrap('<div class="qqColorInfoWrap"><div class="north"><div class="east"><div class="south"><div class="west"><div class="northeast"><div class="southeast"><div class="southwest"><div class="northwest"></div></div></div></div></div></div></div></div></div>');D("#quickQuoteForm .group1.fieldset1 div:eq(0)").prepend('<span class="qqStep">'+H.STEP_2+": "+H.ENTER_YOUR_INFORMATION+"</span>");D("#quickQuoteForm .group1.fieldset1").wrap('<div class="fieldsetWrap"><div class="north"><div class="east"><div class="south"><div class="west"><div class="northeast"><div class="southeast"><div class="southwest"><div class="northwest"></div></div></div></div></div></div></div></div></div>').append(G);D("#quickQuoteForm .submit").css("width",(D('#quickQuoteForm .group1.fieldset1 label[class*="comments"] textarea').width()+"px"));},getModelData:function(G){this.call.operation="models";this.call.callback="DDC.QuickQuote.attachModelData";this.call.param("make",G);this.call.execute();},attachModelData:function(K){var H,J,I,G;for(B=0;B<K.models.length;B++){H=K.models[B].make;J=K.models[B].year;this.data.franchises[H][J]={};}for(B=0;B<K.models.length;B++){H=K.models[B].make;J=K.models[B].year;I=K.models[B].model;this.data.franchises[H][J][I]={};}for(B=0;B<K.models.length;B++){H=K.models[B].make;J=K.models[B].year;I=K.models[B].model;G=K.models[B].bodyStyle;this.data.franchises[H][J][I].bodyStyle={};}for(B=0;B<K.models.length;B++){H=K.models[B].make;J=K.models[B].year;I=K.models[B].model;G=K.models[B].bodyStyle;this.data.franchises[H][J][I].bodyStyle[G]=G;}this.doLoadYears(H);},getTrimData:function(G){this.call.operation="trims";this.call.callback="DDC.QuickQuote.attachTrimData";this.call.param("year",G.year);this.call.param("make",G.make);this.call.param("model",G.model);this.call.param("bodystyle",G.bodyStyle);this.call.execute();},attachTrimData:function(H){var G=this.vehicleInfo;G.interiorColors={};G.exteriorColors={};G.photos={};G.exteriorColors=H.exteriorColors;G.interiorColors=H.interiorColors;if(H.trims.length>0){G.trims=H.trims;if(H.exteriorColors){for(C in H.exteriorColors){if(H.hasOwnProperty(C)){G.photos=H.exteriorColors[C].photos;}}}if((G.photos.large&&G.photos.large.length===0)||(!G.photos.large)){G.photos.large=H.trims[0].picture;G.photos.large=H.trims[0].picture;}}this.prepVehicleData(G);this.doLoadTrims(G.trims);},doLoadYears:function(H){var G=this.select("year"),I;G.options[0]=new Option(this.data.labels.year,this.data.labels.year);for(C in this.data.franchises[H]){if(C!=="logo"&&parseInt(C,10)>=parseInt(this.data.yearLimit,10)){G.options[G.length]=new Option(C,C);}}this.select("year").disabled=false;if(this.vehicleInfo.make!=="Nissan"){I=this.vehicleInfo.logo;D("#qqVehiclePicture").css("background-image","url("+I+")").css("background-position","50%");}},buildModels:function(I){var G=this.select("model"),H=this.vehicleInfo.make,J;G.options[0]=new Option(this.data.labels.model,"");for(C in this.data.franchises[H][I]){if(this.data.franchises[H][I].hasOwnProperty(C)&&(this.data.exclude.models.indexOf(C)===-1)){for(J in this.data.franchises[H][I][C].bodyStyle){if(this.data.franchises[H][I][C].bodyStyle.hasOwnProperty(J)){G.options[G.length]=new Option(C+" "+J.toString().replace("Sport Utility Vehicle","SUV"),C+" "+J.toString().replace("Sport Utility Vehicle","SUV"));}}}}this.select("model").disabled=false;this.autoSelect(G);},doLoadTrims:function(H){var G=this.select("trim"),I;G.options[0]=new Option(this.data.labels.trim,"");for(trim in H){G.options[G.length]=new Option(H[trim].trim,H[trim].trim);}this.select("trim").disabled=false;this.autoSelect(G);},clearSelect:function(G){var I="",H=D("#quickQuoteForm select").get(),J;for(C in H){if(G===H[C]){I=C;}}D("#quickQuoteForm select:gt("+I+")").not("select[name*=account]").each(function(){J=this.options.length;for(B=(J-1);B>=1;B--){this.options[B]=null;}}).attr("disabled","true");},doLoadMakes:function(){var G=this.select("make");for(C in this.data.franchises){if(C!=="Preowned"){G.options[G.length]=new Option(C,C);}}this.autoSelect(G);},doLoadVehicleData:function(P,N,O){var M=this.data.labels,L=this.vehicleInfo,K,H,G,J,I=this.vehicleInfo.logo;D("#showCase").fadeOut("slow",function(){if(P!==undefined){D("#qqVehiclePicture").html("<a class='thickbox' href='"+P+"'><img src='"+P+"'/></a>");}else{D("#qqVehiclePicture").html("<span class='naImage'>"+M.NO_IMAGE_AVAILABLE+"</span>");if(L.make!=="Nissan"){var Q=L.logo;D("#qqVehiclePicture").css("background-image","url("+Q+")").css("background-position","50%");}}if(N!==undefined){D("#qqColorInfo").html(O+'<div class="qqColor">'+N+"</div>").css("display","block");}else{D("#qqColorInfo").html('<div id="qqColorLabel"></div>').css("display","none");}if(typeof document.body.style.maxHeight==="undefined"){K=D(".qqExColorSwatch").size();H=(14+8)*K;G=410;J=(G-H)/2;D(".qqColorInfoWrap").css("margin-left",J/2);}else{K=D(".qqExColorSwatch").size();H=(14+8)*K;G=410;J=(G-H)/2;D(".qqColorInfoWrap").css("margin-left",J);}D("#showCase").fadeIn("slow",function(){D("ul.qqColorInfo").hover(function(){D(this).addClass("hand");},function(){D(this).removeClass("hand");});D("ul.qqColorInfo").click(function(){var R=D("li.qqExColorLabel",this).text();var S=(D("li.qqExColorImage.large img",this).attr("src")==="")?false:D("li.qqExColorImage.large img",this).attr("src");D("#qqVehiclePicture span.naImage").remove();if(!!S){D("#qqVehiclePicture").css("background-image","none");D(this).siblings().removeClass("selected").end().addClass("selected");D("#qqColorLabel span").text(R);D("#qqVehiclePicture img").fadeOut("fast");D("#qqVehiclePicture a").attr("href",S);D("#qqVehiclePicture img").attr("src",S);D("#qqVehiclePicture img").fadeIn();D('textarea[name*="comments"]').val(M.textarea+" "+L.year+" "+L.make+" "+R+" "+L.model.replace("Sport Utility Vechicle","SUV")+" "+L.bodyStyle);}else{if(D("#qqVehiclePicture span.naImage").length===0){D("#qqVehiclePicture").prepend('<span class="naImage">'+M.NO_COLORIZED_IMAGE_AVAILABLE+"</span>");}}D('textarea[name*="comments"]').val(M.textarea+" "+L.year+" "+L.make+" "+R+" "+L.model.replace("Sport Utility Vechicle","SUV")+" "+L.bodyStyle);});F("a.thickbox");D('textarea[name*="comments"]').val(M.textarea+" "+L.year+" "+L.make+" "+L.model.replace("Sport Utility Vechicle","SUV")+" "+L.bodyStyle);});});},prepVehicleData:function(O){var R,H,P,J,I,Q,L,G,K,N,M;for(C in O){if(O.hasOwnProperty(C)){switch(C){case"exteriorColors":for(C in O.exteriorColors){if(O.exteriorColors.hasOwnProperty(C)){if(L===undefined){if(O.exteriorColors[C].swatch.length!==0){I="<li class='qqExColorLabel'><span>"+C+"</span></li>";J="<li class='qqExColorSwatch'><img src='"+O.exteriorColors[C].swatch+"' title='"+C+"'</img></li>";Q='<div id="qqColorLabel"><span>Choose your color</span></div>';H="<li class='qqExColorImage medium'><img src='"+O.exteriorColors[C].photos.medium+"'></li>";P="<li class='qqExColorImage large'><img src='"+O.exteriorColors[C].photos.large+"'>";L="<ul class='qqColorInfo'>"+I+J+H+P+"</ul>";}}else{if(O.exteriorColors[C].swatch.length!==0){I="<li class='qqExColorLabel'><span>"+C+"</span></li>";J="<li class='qqExColorSwatch'><img src='"+O.exteriorColors[C].swatch+"' title='"+C+"'</img></li>";H="<li class='qqExColorImage medium'><img src='"+O.exteriorColors[C].photos.medium+"'></li>";P="<li class='qqExColorImage large'><img src='"+O.exteriorColors[C].photos.large+"'>";L+="<ul class='qqColorInfo'>"+I+J+H+P+"</ul>";}}}}break;case"photos":R=O[C].large;break;default:break;}}}this.doLoadVehicleData(R,L,Q,G,K,N,M);},selectAction:function(L,G){var K,I,H;switch(L){case"make":I=G.options[G.selectedIndex].value;K=this.data.franchises[I].logo;this.clearSelect(G);this.vehicleInfo.make=I;this.vehicleInfo.logo=K;this.getModelData(this.vehicleInfo.make);if(this.vehicleInfo.make!=="Nissan"){K=this.vehicleInfo.logo;D("#qqVehiclePicture").css("background-image","url("+K+")").css("background-position","50%");D("#qqVehiclePicture").css("background-image",'url("http://static.dealer.com/v8/tools/automotive/showroom/basic/images/loading.gif")').css("background-position","50%");}D("#qqVehiclePicture span").fadeOut();D("#qqVehiclePicture img").fadeOut();D("#qqColorInfo").fadeOut();break;case"year":K=this.vehicleInfo.logo;this.clearSelect(G);this.vehicleInfo.year=G.options[G.selectedIndex].value;this.buildModels(this.vehicleInfo.year);if(this.vehicleInfo.make!=="Nissan"){K=this.vehicleInfo.logo;D("#qqVehiclePicture").css("background-image","url("+K+")").css("background-position","50%");}D("#qqVehiclePicture span").fadeOut();D("#qqVehiclePicture img").fadeOut();D("#qqColorInfo").fadeOut();break;case"model":this.clearSelect(G);H=G.options[G.selectedIndex].value.toString().split(" ");this.vehicleInfo.model=H[0];this.vehicleInfo.bodyStyle=H[1].toString().replace("SUV","Sport Utility Vehicle");if(H.length>2){if(H[0]!=="Rondo"){this.vehicleInfo.model=H[0]+" "+H[1];}if(H[0]==="Rondo"){this.vehicleInfo.bodyStyle=H[1]+" "+H[2].toString().replace("SUV","Sport Utility Vehicle");}else{this.vehicleInfo.bodyStyle=H[2].toString().replace("SUV","Sport Utility Vehicle");}}this.getTrimData(this.vehicleInfo);D("#qqVehiclePicture").css("background-image",'url("http://static.dealer.com/v8/tools/automotive/showroom/basic/images/loading.gif")').css("background-position","50%");D("#qqVehiclePicture span").fadeOut();D("#qqVehiclePicture img").fadeOut();D("#qqColorInfo").fadeOut();break;case"trim":var J=this.vehicleInfo.trims;selectedTrim=G.options[G.selectedIndex].value;this.clearSelect(G);for(trim in J){if(J[trim].trim===selectedTrim){D("#qqVehiclePicture img").attr("src",J[trim].picture);D('textarea[name*="comments"]').val(this.data.labels.textarea+" "+this.vehicleInfo.year+" "+this.vehicleInfo.make+" "+this.vehicleInfo.model.replace("Sport Utility Vechicle","SUV")+" "+this.vehicleInfo.bodyStyle+" "+selectedTrim);}}default:break;}},whichSelect:function(G){var H="";if(G.getAttribute("name").indexOf("make")>-1&&G.selectedIndex!==0){H="make";}else{if(G.getAttribute("name").indexOf("year")>-1&&G.selectedIndex!==0){H="year";}else{if(G.getAttribute("name").indexOf("model")>-1&&G.selectedIndex!==0){H="model";}else{if(G.getAttribute("name")==="vehicle.bodystyle"&&G.selectedIndex!==0){H="bodystyle";}else{if(G.getAttribute("name")==="trim"&&G.selectedIndex!==0){H="trim";}}}}}this.selectAction(H,G);},select:function(H,G){return(G)?D("#quickQuoteForm select[name*="+H+"]"):D("#quickQuoteForm select[name*="+H+"]").get(0);},infoListClear:function(){D("ul#vehicleInfo").html("");},autoSelect:function(G){if(G.options.length===2){this.whichSelect(this.select(G.name,true).find("option:eq(1)").attr("selected",true).end().get(0));}}};window.DDC.QuickQuote=E;})(jQuery,ApiCall,tb_init);