/* $Id: carconfigurator.js 8457 2010-02-15 13:21:18Z jharth $ */
(function(e,d,b){var c,a;c={sent:{},send:{},lastPrice:0,bFirstFeatureClick:true,addEvent:function(h,g,f){if(!(h in this.send)){this.send[h]={}}if(!(f in this.send[h])){this.send[h][f]=[]}if(!(h in this.sent)){this.sent[h]={}}if(!(f in this.sent[h])){this.sent[h][f]=[]}e.merge(this.send[h][f],g.replace(/[ ]*,[ ]*/g,",").split(","))},eventAlreadySent:function(h,f,g){g=g||"events";return e.inArray(f,this.sent[h][g])>-1},call:function(f){e("<img>").attr("src",f)},omniture:(function(){var f="omniture";return{eventAlreadySent:function(g,h){h=h||"events";return e.inArray(g,c.sent[f][h])>-1},addEvent:function(h,g){g=g||"events";c.addEvent(f,h,g)},track:function(g){g=g||"tl";var h;if(typeof s==="object"&&e.isFunction(s[g])){for(h in c.send[f]){if(c.send[f].hasOwnProperty(h)){s[h]=c.send[f][h].join(",");e.unique(e.merge(c.sent[f][h],c.send[f][h]))}}s[g]();for(h in c.send[f]){if(c.send[f].hasOwnProperty(h)){s[h]="";c.send[f][h]=[]}}}}}})(),trackPriceChange:function(f){var g=this.lastPrice;this.lastPrice=f;return g!==f},isConfigured:function(f){if(typeof this.oConfig!=="object"){this.oConfig=typeof oCarConfiguratorTrackingConfig==="function"?oCarConfiguratorTrackingConfig(this):{}}return f in this.oConfig&&e.isFunction(this.oConfig[f])},trackSectionClicks:function(f){if(this.isConfigured("sectionClicked")){this.oConfig.sectionClicked(f)}},trackFeatureClicks:function(){if(this.isConfigured("featureClicked")){var f=e("#configSections").data("aTotalSum")[0];this.oConfig.featureClicked(this.bFirstFeatureClick,f,this.trackPriceChange(f))}if(this.bFirstFeatureClick){this.bFirstFeatureClick=false}},trackConfiguratorStart:function(){if(this.isConfigured("configuratorStart")){this.oConfig.configuratorStart(e("#configSections").data("aTotalSum")[0])}}};String.prototype.firstToUpperCase=function(f){return(f||"")+this.charAt(0).toUpperCase()+this.substr(1)};Array.prototype.addArray=function(f,g){g=g||2;if(Object.prototype.toString.call(f)!=="[object Array]"){f=[f]}for(var h=0;h<this.length;h+=1){this[h]=!isNaN(this[h])?this[h]*1:0;f[h]=!isNaN(f[h])?f[h]*1:0;this[h]+=f[h];this[h]=Math.round(this[h]*Math.pow(10,g))/Math.pow(10,g)}return this};Array.prototype.sumInitialize=function(f){for(var g=0;g<f.length;g+=1){this[g]=0}return this};jQuery.fn.extend({check:function(){return this.each(function(){this.checked=!this.disabled})},uncheck:function(){return this.each(function(){this.checked=false})},checkToggle:function(f){if(typeof f==="boolean"&&f===false){return this}return this.each(function(){if(!this.disabled){this.checked=this.type!=="radio"?!this.checked:true}})},setDisabled:function(){return this.each(function(){e(this).addClass("disabled").find("input").get(0).disabled=true})},setEnabled:function(){return this.each(function(){e(this).removeClass("disabled").find("input").get(0).disabled=false})},clickable:function(){return this.each(function(){e(this).andSelf().css({visibility:"visible",cursor:"pointer"})})}});a=(function(){var g,f,j,h,i=", ";h={priceBuildHTML:function(m,n){n=n||"";for(var l=0,k="";l<m.length;l+=1){k+=l===0?"<span>"+m[l]+"</span>\t\n":'<span class="xPrice">('+n+m[l]+")</span>\t\n"}return k},priceFormat:function(m){for(var l=0,k=[];l<m.length;l+=1){k[l]=(b.currencySymbols&&e.isArray(b.currencySymbols)&&b.currencySymbols.length>=m.length?b.currencySymbols[l]:b.currencies[l])+" "+m[l].toFixed(2)}return k},writeSectionSum:function(m,l){var k=this.priceBuildHTML(l);e("h1.sectionHead",m).find("span:not(.info, .sectionName)").remove().end().find("span.sectionName").after(k)},writeTotalSum:function(l){var k=this.priceBuildHTML(l);e("#topSum, #bottomSum").find("span.price").each(function(){e(this).html(k)})},fullPriceUpdate:function(){var l,o,m=[].sumInitialize(b.currencies),k={country:b.priceFormatter.country},n={currencies:b.currencies,formatterName:b.priceFormatter.name,prices:{}};f.each(function(){var p=e(this).data("aSectionSum");n.prices[this.id]=p;m.addArray(p)});n.prices.sum=m;e("#configSections").data("aTotalSum",m);k.priceData=JSON.stringify(n);l={data:k,url:b.priceFormatter.uri,timeout:b.priceFormatter.timeout,success:function(q){var p;if(q.error){return this.error()}if(q.prices){q=q.prices}for(p in q){if(p in q){if(p!="sum"){h.writeSectionSum(e("#"+p),q[p])}else{h.writeTotalSum(q[p])}}}},error:function(){var p;for(p in n.prices){if(n.prices.hasOwnProperty(p)){if(p!=="sum"){h.writeSectionSum(e("#"+p),h.priceFormat(n.prices[p]))}else{h.writeTotalSum(h.priceFormat(n.prices[p]))}}}}};if(b.priceFormatter.useCrossSiteJSONP){o="jsonp";l.url+="?jsonpCallback=?"}else{o="ajax";l.dataType="json"}e[o](l)},updateColors:function(l){var n="",k,m=e("input",l).val();e("#carNavigation > .carNav").show();for(k in b.model.perspectiveNameParts){if(b.model.perspectiveNameParts.hasOwnProperty(k)){n=b.oImagePath.cars+b.model.perspectiveNameParts[k].prefix+b.model.prefix+b.model.name+"_"+m+b.model.perspectiveNameParts[k].postfix+".png";e("#"+k+"View").attr("src",n);e("#carNavigation .show > #"+k+"Wrp").show()}}},updateRims:function(k){var m="",l=e("input",k).val();m=b.oImagePath.rims+b.model.name+"/"+l+"_"+b.model.name+".gif";e("#rimLayer").attr("src",m)},variantSetFeatures:function(k){f.each(function(){var m,l=e(this);e("ul.features",l).each(function(){var o=[],n=e(this);e("li:not(.group, .conflict li)",n).each(function(){if(!(this.id in d)){o.push(this);e(this).setDisabled()}else{if(e.isArray(d[this.id].excludingVariants)&&e.inArray(k,d[this.id].excludingVariants)>-1){o.push(this);e(this).setDisabled()}else{e(this).setEnabled()}}});m=e("input:checked",o).uncheck();if(m.is(":radio")){if(n.children("li:not(.group, .disabled, .conflict li):eq(0)").find("input:radio[name="+m.attr("name")+"]").check().length===0){n.siblings("ul.features").add(n.parent(".third, .twothird").siblings(".third, .twothird").children("ul.features")).children("li:not(.group, .disabled, .conflict li):eq(0)").find("input:radio[name="+m.attr("name")+"]").check()}}})})},sectionSelectionUpdates:function(m,l){var k=[],n=[].sumInitialize(b.currencies);e.each(m,function(){var p=e(this),o=p.attr("id");k.push(h.getFeatureName(p));if(o in d&&"price" in d[o]){n.addArray(d[o].price)}});if(f.index(l)===0){k=e.merge([l.data("sSelectedVariantName")],k);n.addArray(l.data("sSelectedVariantPrice"))}e("h1.sectionHead span.info",l).text(k.join(i));l.data("aSectionSum",n)},getFeatureName:function(k){return e("label strong",k).text()},checkForConflicts:function(l){var k=this;f.find("ul.features li.conflict").removeClass("conflict").removeData("aConflictSources").find(".message").remove();f.find("ul.features li.selected").each(function(){var n=this.id,m=[];if(!"excludes" in d[n]||!e.isArray(d[n].excludes)||d[n].excludes.length===0){return}e.each(d[n].excludes,function(){if(e("#"+this).hasClass("selected")){m.push(this)}});if(m.length>0){k.setConflict(n,m)}})},setConflict:function(l,o){var k=[],n,m=e("#"+l);if(!e.isArray(o)){o=[o]}e.each(o,function(){var q=e("#"+this),p=q.closest("li.section");k.push({name:h.getFeatureName(q),sectionId:p.attr("id")});if(p.hasClass("closed")){p.find("h1.sectionHead").click()}});n='<ul class="conflictSources">';e.each(k,function(){n+="<li>"+b.conflictMsg.details.replace("%FEATURE%",'<span class="conflictSource">'+this.name+"</span>").replace("%SECTION%",'<a href="#'+this.sectionId+'">'+e("#"+this.sectionId).data("sSectionName")+"</a>")+"</li>"});n+="</ul>";m.addClass("conflict").append('<div class="message">'+b.conflictMsg.intro+n+"</div>")}};return{init:function(k){g=this;f=k;f.each(function(){e(this).data("sSectionName",e("h1.sectionHead .sectionName",this).text())});g.handleEngineTypes()},handleSelectedFeatures:function(k){k=k||f;k.each(function(){var n=e(this),l=n.attr("id"),m=[];e("ul.features li:not(.group)",n).removeClass("selected");e("ul.features li:not(.group) input:checked",n).each(function(){m.push(e(this).closest("li").addClass("selected").get(0))}).siblings().removeClass("selected");h.sectionSelectionUpdates(m,n);if(l.firstToUpperCase("update") in h){h[l.firstToUpperCase("update")](e("ul.features li.selected",n))}});h.fullPriceUpdate();h.checkForConflicts()},handleEngineTypes:function(l){var n,o=f.slice(0,1),k,m;o.find("tr.selected").removeClass("selected");if(l instanceof jQuery&&l.length===1){l.addClass("selected")}else{l=o.find("td:first-child input:checked").closest("tr").addClass("selected")}k=o.find("tr:not(:first-child)").index(l);m=o.find("table tr.selected + tr").hasClass("lpgFeature");$rowsBefore=o.find("table tr:lt("+(k+1)+")");rowsBeforeLpgCount=$rowsBefore.filter("tr.lpgFeature").length;if(m){o.find("table tr.selected + tr").addClass("selected")}k+=1-rowsBeforeLpgCount;o.data("sSelectedVariantName",o.find("table tr.selected td:nth-child(2) label").text());if(b.variants[k].price){n=b.variants[k].price}else{n=[0]}if(m){if(e("#lpgIcon").length!==1){e("#carPicWrp").append("<img id='lpgIcon' src='/assets/images/global/carconfigurator-lpg.png' style='position:absolute;left:35px;top:270px;'/>")}}else{e("#lpgIcon").remove()}o.data("sSelectedVariantPrice",b.variants[k].price);e("#topSum, #bottomSum").each(function(){e(this).find("h1 span.modelName em").text(b.variants[k].name)});h.variantSetFeatures(k);g.handleSelectedFeatures()}}})();e(document).ready(function(){e("body").addClass("jsReady");if(oCtaHelper){oCtaHelper.refreshGroup(e("#carPicWrp a.button"));oCtaHelper.refreshGroup(e("#carConfFooter a.button"))}var f=e("#configSections > li.section");f.addClass("closed").children(".sectionContent").hide().slice(0,1).slideDown("slow",function(){e(this).closest("li").removeClass("closed")});f.find("h1.sectionHead").clickable().click(function(h){var g=e(this).closest("li");c.trackSectionClicks(g.hasClass(".closed"));e(this).next(".sectionContent").slideToggle("slow");g.toggleClass("closed")});e(".toggleListView span.utilityLink","#carConfigurator").clickable().click(function(g){if(e(this).closest("li.collapse").length){f.addClass("closed").find(".sectionContent").slideUp("slow")}else{f.removeClass("closed").find(".sectionContent").slideDown("slow");c.trackSectionClicks(true)}});e("#engine tr:not(':first-child', '.lpgFeature')").clickable().click(function(h){var g=e(this).closest("tr").find("td:first-child input").is("tr.selected input:radio:checked, :disabled");if(e(h.target).is("label, label *")){h.preventDefault()}if(!g){if(e(h.target).is(":not(input)")){e(this).find("td:first-child input").check()}a.handleEngineTypes(e(this));c.trackFeatureClicks()}});e("#configSections ul.features li:not(.group)").clickable().click(function(i){var g=e(i.target),j,h=e(this).closest("li").find("input").is("li.selected>input:radio:checked, :disabled");if(!e(this).closest("li").hasClass("conflict")||!g.is(".message a")){if(g.is("label, label *")){i.preventDefault()}if(!h){if(g.is(":not(input)")){e("input:radio, input:checkbox",this).checkToggle()}a.handleSelectedFeatures(e(this).closest(".section"));c.trackFeatureClicks()}}else{j=e(g.attr("href").match(/(#.*)$/i)[0]);if(j.hasClass("closed")){j.find("h1.sectionHead").click()}}});e("#carNavigation>.carNav").clickable().click(function(i){var h,g=e(this);if(!g.hasClass("active")){e("#carNavigation .carNav").removeClass("active");g.addClass("active");h=e("#carPicWrp #"+g.attr("id").match(/(.*)ViewBtn/)[1]+"Wrp").show();if(e.support.opacity){h.find("img").fadeIn("slow").parent("div").addClass("show").siblings(".show").removeClass("show").find(".car, #rimLayer").fadeOut("slow")}else{h.addClass("show").siblings(".show").removeClass("show")}}});a.init(f);c.trackConfiguratorStart();oCustomToolTip.setContentGetter(function(g){return e("#Content"+g).html()});oCustomToolTip.setTriggerClass("tooltip");oCustomToolTip.setAlignment("top","right");oCustomToolTip.init("15px","-42px")})})(jQuery,oCarConfiguratorFeatureData,oCarConfiguratorGlobalSettings);