var Config={requesting:false,webroot:"/page/index.php",loading:{},lightbox:false,params:{},wait:800,account:"UA-24288019-1"};function SvsMain(){this.set();this.init()}SvsMain.prototype.set=function(){Extends.set(this,[Config])};SvsMain.prototype.init=function(){$j("body").append('<div id="timer">');$j("body").append('<div class="blockAll">');if($j("#MerlinApp").length>0){new Merlin()}if($j("#RMAApp").length>0){$j.ajax({url:this.webroot+"/replacements/parts/",type:"GET",dataType:"json",success:this.rmaApp,context:this})}if($j("#WarrantyApp").length>0){new WarrantyParts()}};SvsMain.prototype.rmaApp=function(a){$j("#RMAApp").html(a.html)};$j=jQuery.noConflict();$j(window).load(function(){new SvsMain()});function WarrantyParts(){this.set();this.init()}WarrantyParts.prototype.set=function(){Extends.set(this,[Config])};WarrantyParts.prototype.init=function(){var a=window.location.pathname.replace("/","");$j.ajax({url:this.webroot+"/replacements/warranty/path:"+a,type:"GET",dataType:"json",success:this.renderUi,context:this})};WarrantyParts.prototype.renderUi=function(a){$j("#WarrantyApp").html(a.html);this.setListeners()};WarrantyParts.prototype.setListeners=function(){$j("#formWarrantyRma").click($j.proxy(this.showForm,this));$j(".closeWarranty").click($j.proxy(this.hideForm,this));$j("#formWarrantySubmit").submit($j.proxy(this.requestWarranty,this))};WarrantyParts.prototype.showForm=function(a){if(!$j(".textWarranty").is(":animated")){$j(".textWarranty").animate({opacity:0},{complete:function(){$j(this).addClass("hide");$j(".formWarranty").removeClass("hide").css({opacity:0}).animate({opacity:1})}})}};WarrantyParts.prototype.hideForm=function(a){if(!$j(".formWarranty").is(":animated")){$j(".formWarranty").animate({opacity:0},{complete:function(){$j(this).addClass("hide");$j(".textWarranty").removeClass("hide").css({opacity:0}).animate({opacity:1})}})}};WarrantyParts.prototype.requestWarranty=function(a){a.preventDefault();if(!this.requesting){this.requesting=true;this.loading=$j(a.target).find(".loading").removeClass("invisible");$j(".error").addClass("hide");$j.ajax({url:this.webroot+"/replacements/rma/",type:"POST",data:$j("#formWarrantySubmit").serialize(),dataType:"json",success:this.responseWarranty,context:this})}};WarrantyParts.prototype.responseWarranty=function(c){this.loading.addClass("invisible");this.requesting=false;if(c.validationErrors){for(var b in c.validationErrors){$j("#error_"+b).removeClass("hide").css({opacity:0}).animate({opacity:1})}}if(c.success){$j(".success").html(c.html);$j(".formWarranty").animate({opacity:0},{complete:function(){$j(this).addClass("hide");$j(".success").removeClass("hide").css({opacity:0}).animate({opacity:1})}})}};function Merlin(){this.set();this.init()}Merlin.prototype.set=function(a){Extends.set(this,[Config])};Merlin.prototype.init=function(a){$j.ajax({url:this.webroot+"/merlin/index/",type:"GET",dataType:"json",success:this.renderUi,context:this})};Merlin.prototype.renderUi=function(a){$j("#MerlinApp").html(a.html);this.setListeners();this.addLightbox();this.renderUrl()};Merlin.prototype.renderUrl=function(){var f=window.location.hash.replace("#","");var e=f.split("&");var d={};for(var b=0;b<e.length;b++){var c=e[b].split("=");d[c[0]]=c[1]}if(d.brand&&d.model){this.params=d;$j("#brand-list").attr("value",d.brand);$j("#timer").animate({opacity:1},{duration:this.wait,complete:function(){$j("#brand-list").trigger("change")}})}};Merlin.prototype.addLightbox=function(){var a=$j("#brand-model-box").html();$j("#brand-model-box").remove();$j("body").append('<div id="brand-model-box" class="hide">');$j("#brand-model-box").html(a)};Merlin.prototype.setListeners=function(){$j("#brand-list").change($j.proxy(this.requestModels,this));$j("#model-list").change($j.proxy(this.requestProducts,this));$j(".tellUsModal").click($j.proxy(this.showTellUs,this));$j(".closeModal").live("click",$j.proxy(this.hideTellUs,this));$j("#tellUsForm").live("submit",$j.proxy(this.requestTellUs,this));$j("#quickStartGuide").live("click",$j.proxy(this.quickStartGuide,this));$j(window).resize($j.proxy(this.onResize,this))};Merlin.prototype.onResize=function(){if(this.lightbox){$j("#blockAll").css("width","100%").css("height",$j(window).height())}};Merlin.prototype.requestModels=function(b){var a=$j(b.target);if(a.attr("value")&&!this.requesting){this.requesting=true;this.loading=a.parent().find(".loading").removeClass("hide");Analytic.track("/merlin/selected/brand/"+a.find("option:selected").text());$j.ajax({url:this.webroot+"/merlin/models/"+a.attr("value"),dataType:"json",type:"GET",success:this.responseModels,context:this})}};Merlin.prototype.responseModels=function(c){$j("#step-2").removeClass("hide");this.loading.addClass("hide");this.requesting=false;var d="";for(var b=0;b<c.models.length;b++){d+='<option value="'+c.models[b].BrandModel.id+'">'+c.models[b].BrandModel.model+"</option>"}$j("#model-list").html('<option value="">select one</option>'+d);var e=$j("#step-2").height();$j("#step-2").css({opacity:0,height:0,overflow:"hidden"}).animate({opacity:1,height:e});if(this.params.model){$j("#model-list").attr("value",this.params.model);$j("#timer").animate({opacity:1},{duration:this.wait,complete:function(){$j("#model-list").trigger("change")}})}};Merlin.prototype.requestProducts=function(c){var b=$j(c.target);if(b.attr("value")&&!this.requesting){this.requesting=true;this.loading=b.parent().find(".loading").removeClass("hide");var a="/brand:"+$j("#brand-list").attr("value")+"/model:"+b.attr("value");Analytic.track("/merlin/selected/model/"+b.find("option:selected").text());$j.ajax({url:this.webroot+"/merlin/products"+a,dataType:"json",type:"GET",success:this.responseProducts,context:this})}};Merlin.prototype.responseProducts=function(b){this.loading.addClass("hide");this.requesting=false;$j("#finalStep").html(b.html);new showOneByOne({paths:[".step .recomended-pd"],duration:600,complete:$j.proxy(this.waitFour,this)});var a=$j("body").scrollTop();if(!a){$j("html:not(:animated),body:not(:animated)").animate({scrollTop:a+$j(window).height()/2},900)}if(this.params.model&&this.params.brand){this.params={}}};Merlin.prototype.waitFour=function(){$j("#timer").animate({opacity:1},{duration:600,complete:function(){$j("#step-4").removeClass("invisible").css({opacity:0,marginTop:20}).animate({opacity:1,marginTop:0},{duration:600})}})};Merlin.prototype.showTellUs=function(a){$j(".blockAll").css({width:"100%",opacity:0,height:$j(window).height()}).animate({opacity:1},{duration:500});$j("#brand-model-box").removeClass("hide").css({opacity:0}).animate({opacity:1},{duration:500});this.lightbox=true;$j("#tellUsForm").get(0).reset();$j("#tellUsForm").removeClass("hide").parent().find(".success").addClass("hide");$j("#tellUsForm .error").addClass("hide");if(this.heightForm){$j("#tellUsForm").css({height:this.heightForm})}Analytic.track("/merlin/tell-us/form/")};Merlin.prototype.hideTellUs=function(a){$j(".blockAll").animate({opacity:0},{duration:500,complete:function(){$j(this).css({width:0,height:0})}});$j("#brand-model-box").animate({opacity:0},{duration:500,complete:function(){$j(this).addClass("hide")}});this.lightbox=false};Merlin.prototype.requestTellUs=function(a){a.preventDefault();if(!this.requesting){this.requesting=true;$j("#tellUsForm .error").addClass("hide");this.loading=$j(a.target).parent().find(".loading").removeClass("hide");Analytic.track("/merlin/tell-us/sending/form/");$j.ajax({url:this.webroot+"/merlin/tellus/",type:"POST",data:$j("#tellUsForm").serialize(),dataType:"json",success:this.responseTellUs,context:this})}};Merlin.prototype.responseTellUs=function(c){this.requesting=false;this.loading.addClass("hide");if(c.validationErrors){for(var b in c.validationErrors){$j("#error_"+b).removeClass("hide").css({opacity:0}).animate({opacity:1})}}if(c.success){this.heightForm=$j("#tellUsForm").height();$j("#tellUsForm").animate({height:0},{duration:600,complete:function(){$j(this).parent().find(".success").removeClass("hide").css({opacity:0}).animate({opacity:1})}})}};Merlin.prototype.quickStartGuide=function(b){var c=$j("#brand-list").attr("value");var a=$j("#model-list").attr("value");window.open(this.webroot+"/merlin/guide/brand:"+c+"/model:"+a)};var Analytic={account:Config.account,track:function(a){_gaq._createAsyncTracker(this.account)._trackPageview(a)}};function showOneByOne(c){this.options=c;this.current=0;this.elements=new Array();if(c.paths){for(var b=0;b<this.options.paths.length;b++){$j(this.options.paths[b]).css("opacity",0).prop("scope",this).each(function(a){this.scope.elements.push(this)})}}if(this.options.start){this.options.start()}this.show()}showOneByOne.prototype.show=function(){var a=this.options.duration?this.options.duration:600;$j(this.elements[this.current]).removeClass("invisible").css({marginTop:20}).animate({opacity:1,marginTop:0},{duration:a,complete:$j.proxy(this.show,this)});this.current++;if(this.current==this.elements.length){if(this.options.complete){this.options.complete()}}};var Extends={showError:false,override:false,set:function(d,f,b){b!=undefined?this.override=b:this.override;var a=f.length;while(a--){var c=typeof f[a].prototype!="undefined"?f[a].prototype:f[a];for(var e in c){var g=c[e];if(this.override){d[e]=g}else{if(!this.override){if(!d[e]){d[e]=g}else{this.showErrorMsg(d,c,e)}}}}}},showErrorMsg:function(d,b,c){if(this.showError){var e=b.Name?currentName.Name+"."+c:c;var a=d.Name?d.Name:"";if(window.console){console.log("trying to override a property or method ("+e+") already defined in parent class "+a)}else{throw new Error("trying to override a property or method ("+e+") already defined in parent class "+a)}}}};
