$(document).ready(function(){$(".gallery div:nth-child(4n)").css({"margin-right":"0px"});$(".swatch:nth-child(15n)").css({"margin-right":"0px"});$(".swatch:nth-child(16n)").css({"margin-left":"0px"});$(".swatch:eq(0)").css({"margin-left":"0px"});$(".swatch").dropShadow({left:3,top:3,blur:2,opacity:0.4});var origColor=$(".slidebox img").attr("alt");$(".slidebox .color").text(origColor);$(".picChange").attr("loaded","no");$(".picChange:lt(8)").each(function(){var preloadImage=$(this).attr("href");$("#into").append('<img src="'+preloadImage+'">').hide();$(this).attr("loaded","yes");});$(".colorChange").each(function(){var preloadImage=$(this).attr("href");$("#into").append('<img src="'+preloadImage+'">').hide();});$(".next").click(function(){$("a[loaded='yes']").attr("loaded","prior");$(".picChange[loaded='no']:lt(8)").each(function(){var preloadImage=$(this).attr("href");$("#into").append('<img src="'+preloadImage+'">').hide();$(this).attr("loaded","yes");});});$(".picChange").click(function(){if($(".visiblePic").is(":animated")){var theLink=$(this);var theNew=$(theLink).attr("href");var theOffset=$(".visiblePic").width();var newestImage=$(".slidebox img:last");$(newestImage).after('<img src="'+theNew+'" class="sidePic"');$(".visiblePic").attr("class","deleteMe");$(".sidePic").css({"left":theOffset+"px"});$(".deleteMe").animate({left:"-"+theOffset+"px"},1000);$(".sidePic").animate({left:"0px"},1000);$(".sidePic").attr("class","visiblePic");$(".slidebox .color").text("");return false;}
else{$(".deleteMe").remove();$(".slidebox img:first").addClass("visiblePic");var theLink=$(this);var theNew=$(theLink).attr("href");var theOffset=$(".visiblePic").width();$(".visiblePic").after('<img src="'+theNew+'" class="sidePic"');$(".sidePic").css({"left":theOffset+"px"});$(".visiblePic").animate({left:"-"+theOffset+"px"},1000);$(".sidePic").animate({left:"0px"},1000);$(".visiblePic").attr("class","deleteMe");$(".sidePic").attr("class","visiblePic");$(".slidebox .color").text("");return false;}});$(".colorChange").click(function(){if($(".visiblePic").is(":animated")){var theLink=$(this);var theNew=$(theLink).attr("href");var theOffset=$(".visiblePic").width();var newestImage=$(".slidebox img:last");var newColor=$(this).attr("title");$(newestImage).after('<img src="'+theNew+'" class="sidePic"');$(".visiblePic").attr("class","deleteMe");$(".sidePic").css({"left":theOffset+"px"});$(".deleteMe").animate({left:"-"+theOffset+"px"},1000);$(".sidePic").animate({left:"0px"},1000);$(".sidePic").attr("class","visiblePic");$(".slidebox .color").text(newColor);return false;}
else{$(".deleteMe").remove();$(".slidebox img:first").addClass("visiblePic");var theLink=$(this);var theNew=$(theLink).attr("href");var theOffset=$(".visiblePic").width();var newColor=$(this).attr("title");$(".visiblePic").after('<img src="'+theNew+'" class="sidePic"');$(".sidePic").css({"left":theOffset+"px"});$(".visiblePic").animate({left:"-"+theOffset+"px"},1000);$(".sidePic").animate({left:"0px"},1000);$(".visiblePic").attr("class","deleteMe");$(".sidePic").attr("class","visiblePic");$(".slidebox .color").text(newColor);return false;}});$(".gallery div:first").attr("id","first");$(".gallery div:last").attr("id","last");$('.gallery').serialScroll({items:'div',prev:'a.prev',next:'a.next',duration:700,force:true,axis:'y',lazy:true,step:8,cycle:false,exclude:0,onAfter:function(elem){var currentView=$(elem).attr("id");if(currentView=="first"){$("a.prev").fadeOut("fast");}else{$("a.prev").fadeIn("slow");}
if(currentView=="last"){$("a.next").fadeOut("fast");}else{$("a.next").fadeIn("slow");}}});var cityMileage=parseInt($(".invisible_stats").attr("city"));var hwyMileage=parseInt($(".invisible_stats").attr("hwy"));var mileageDifference=Math.max(cityMileage,hwyMileage)-Math.min(cityMileage,hwyMileage);var mileageAverage=(cityMileage+hwyMileage)/2;var lowerBound=Math.round(mileageAverage-mileageDifference);var upperBound=Math.round(mileageAverage+mileageDifference);var cityAdjusted=cityMileage-lowerBound;var hwyAdjusted=hwyMileage-lowerBound;var cityRange=upperBound-lowerBound;var hwyRange=upperBound-lowerBound;var steps=Math.round(hwyRange/4);var maxMove=221;if(isNaN(lowerBound)==false){var cityMove=(cityAdjusted/cityRange)*221;var hwyMove=(hwyAdjusted/hwyRange)*221;$("#city").animate({left:"+="+cityMove},1500);$("#hwy").animate({left:"+="+hwyMove},1500);$(".first").text(lowerBound);$(".second").text(lowerBound+steps);$(".third").text(lowerBound+steps+steps);$(".fourth").text(lowerBound+steps+steps+steps);$(".fifth").text(upperBound);}
else{$('.fuel .graph').css('background-image','none');$('.fuel .graph').html('No Mileage Information Available');$('.fuel .graph').next('div').html('');}
$("#viewMore").click(function(){$(".trim_details_box").toggle();if($(".trim_details_box").is(":visible")){$("#viewMore").text('Hide Details');var scrollNum=$('.trim_details_box').offset();var scrollDown=scrollNum.top;$(window).scrollTop(scrollDown);}
else{$("#viewMore").text('View More Details');}
return false;});$("#viewOpt").click(function(){$(".options_box").toggle();if($(".options_box").is(":visible")){$("#viewOpt").text('Hide Options');}
else{$("#viewOpt").text('View Options');}
var scrollNum=$('.options_box').offset();var scrollDown=scrollNum.top;$(window).scrollTop(scrollDown);return false;});$("#viewCalc").click(function(){$(".trim_calc_box").show();var scrollNum=$('.trim_calc_box').offset();var scrollDown=scrollNum.top;$(window).scrollTop(scrollDown);return false});$("#hideCalc").click(function(){$(".trim_calc_box").hide();return false});var rawPrice=$(".invisible_stats").attr("price");var barePrice=rawPrice.replace(/,/g,"");$("#p").val(barePrice);$("#p").blur(function(){var atext=$("#p").val();if($("#p").val().indexOf("$")!=-1){$("#p").val(atext);}
else if($("#p").val()==""){$("#p").val()}
else{$("#p").val("$"+atext);}});$("#r").blur(function(){var rtext=$("#r").val();if($("#r").val().indexOf("%")!=-1){$("#r").val(rtext);}
else if($("#r").val()==""){$("#r").val()}
else{$("#r").val(rtext+"%");}});$("#d").blur(function(){var dtext=$("#d").val();if($("#d").val().indexOf("$")!=-1){$("#d").val(dtext);}
else if($("#d").val()==""){$("#d").val()}
else{$("#d").val("$"+dtext);}});$("#box").click(function(){var apr=$("#r").val().substr(0,$("#r").val().length-1);var months=$("#n").val();var down=Number($("#d").val().substr(1,$("#d").val().length));var price=Number($("#p").val().substr(1,$("#p").val().length))-down;if(apr!=0){var convertPercent=apr/100;var monthlyApr=convertPercent/12;var topPart=Number(price*monthlyApr);var toPower=Number(1+monthlyApr);var powerd=Math.pow(toPower,(0-months));var bottomPart=1-powerd;var toPrint=topPart/bottomPart;}
else{var toPrint=(price-Number(down))/months;}
if(toPrint==0||isNaN(toPrint)==true){$("#output").text("Please Fill in All Boxes");}
else{toPrint=toPrint.toFixed(2);toPrint=toPrint+"";var printLength=toPrint.length;var first999=toPrint.substr(printLength-6,printLength);var last999=toPrint.substr(0,printLength-6)
if(printLength>6){var finalPrint=last999+","+first999;}
else{var finalPrint=first999;}
$("#output").text("Your monthly payment is $"+finalPrint);}});});
