(function(a){a.fn.extend({jq_shopping:function(u){var D={list:"#pricelist",button:"#togglePricing",passwordButton:"#changePassword",tab:"#pricetab",topMost:"-275px",bottomMost:"0px",selectClass:".selectProduct",selectDiv:"#prices_",url:"index/shopping",loginUrl:"index/login",pwUrl:"index/password",formUrl:"index/getforms",heading:"#shop_top",container:"#shoplisting",cart:"#wagonBed",order:"#wagonTally",contactinfo:"#wagonContact",sendtoinfo:"#wagonSendto",shippinginfo:"#wagonshipping",loginDiv:"#wagonLogin",loginForm:"#shopping_Login",loginButton:"#wagonLoginButton",passwordElement:"#shopping_password",newAccountMessage:"#newAccountMessage",footer:"#wagonTail",clear:"#cancelOrder",edit:".wagonEdit",pi:"#existingAccount",deleteable:".deleteable"};var u=a.extend(D,u);var G=a(u.button);var J=false;var c=0;var y=0;var F=0;var e=false;var A=false;var H=null;var P=null;var s=null;var z=a(u.selectDiv+(F+1)).html();var g=new Array();var C=null;var h=false;var V=false;var o=false;var Q=false;var f=function(){var Z=a(this).attr("name");a("#"+Z).slideToggle()};var I=function(){var Z="#"+a(this).attr("name");s=a(Z).serialize();P=Z;M("discreetChange=makechanges&"+s,u.url)};var S=function(){if(a(u.container).html().length<3){z='<span id="wagonDirections">';z+="<h3>Select items</h3>";z+='<p class="shopping_controls">Use panel controls to view prices</p>';z+="</span>";a(u.container).append(z);a(u.container).show(300)}};var W=function(){var Z=jQuery.Event("toggleShopping");jQuery("body").trigger(Z);r(this)};a("body").delegate(".deleteButton","click",function(aa){var Z=a(this).attr("value");aa.preventDefault();a("quantity_"+Z).val("").trigger("change")});a(u.list).html(z);N();G.click(function(){B()});a(".shopping-priclist").each(function(){var aa=g.length;var Z=a(this).attr("value");g[aa]=Z});a("body").bind("sliderkitChange",function(ab,ac){var Z=g[ac];var aa=a(u.selectDiv+(Z)).html();a(u.list).html(aa);N()});setTimeout(function(){b("check=anything",u.url,"check")},5000);a("#shopping_close").click(function(){J=false;r(this);if(Q){X();b("clear=itall",u.url,"dumpWagon");setTimeout(function(){q();U();y=0},500)}else{setTimeout(function(){q();U();y=0},500)}});a("body").bind("startShopping",function(){J=true;setTimeout(function(){S();m();y=1},500)});a("body").bind("stopShopping",function(){J=false;setTimeout(function(){q();U();y=0},500)});a("body").bind("toggleShopping",function(){B()});return;function B(){switch(y){case 0:y=1;m();S();J=true;var Z=jQuery.Event("stopAccounting");jQuery("body").trigger(Z);break;case 1:y=0;U();J=false;break}}function m(){setTimeout(function(){var Z=jQuery.Event("click");jQuery(".go-play").trigger(Z)},1000);J=true;a("#pricetab").animate({marginTop:"-=15px"},200).animate({marginTop:"+=15px"},100).animate({marginTop:"-=15px"},200).animate({marginTop:"+=15px"},100).animate({marginTop:u.topMost},250,function(){a("#shoppingwagon").show(100).animate({marginTop:"-=15px"},200).animate({marginTop:"+=15px"},100).animate({marginTop:"-=15px"},200).animate({marginTop:"+=15px"},100)})}function U(){var Z=jQuery.Event("click");jQuery(".go-play").trigger(Z);J=false;a("#pricetab").animate({marginTop:"-=10px"},100).animate({marginTop:"+=10px"},100).animate({marginTop:"-=25px"},100).animate({marginTop:"+=25px"},100).animate({marginTop:u.bottomMost},300).animate({marginTop:"-=15px"},100).animate({marginTop:"+=15px"},100).animate({marginTop:u.bottomMost},250,function(){q()})}function d(ab){a(".shoppingSpinner").hide(200);a(".errors").slideUp(200,function(){a("."+u.spinnerClass).hide(200)});var ac=new Object();var Z=0;var aa;for(i in ab){aa=i;if(aa=="errors"){T(ab.errors)}if(aa=="resetKeys"){b("reform=get",u.url,"reform")}if(aa=="changePage"){if(ab.changePage==true){R(3);c=3}else{A=true;R(2);c=2}}if(aa=="password"){if(ab[aa]=="pass"){h=true;H="existingAccount";b("getLogin=get",u.formUrl,"loginPanel");b("reform=get",u.url,"reform")}}if(aa=="loggedIn"){if(ab[aa]==true){h=true;H="existingAccount";b("reform=get",u.url,"reform")}}if(aa=="emailExists"){V=false;if(ab[aa]==true){o=true;V=true;w()}else{V=false;if(ab.errors.shopping_email.length==0){V=true;H="newAccount"}else{H=null;o=false}k()}}if(aa=="passwordChanged"){if(ab[aa]==true){a("#existingPassword").slideUp();a(".errors").remove();a("#change_password").val("");a("#change_password_confirm").val("")}}if(aa=="html"){if(P!=null){a(P).empty();a(P).append(ab.html);a(P).show("slide",{direction:"left"},800);a(".editExisting").unbind("click",f);a(".makeEdit").unbind("click",I);a(".editExisting").bind("click",f);a(".makeEdit").bind("click",I)}}if(aa=="newAccount"||aa=="orderComplete"){Q=true;a(u.cart).hide();a(u.sendtoinfo).hide();a("#existingAccount").hide();a("#orderNavButtons").hide();a("#nextPage").hide(200);a("#previousPage").hide(200);a("#cancelOrder").hide(200);a("#complete").show(200);a("#wagonComplete").show(200);if(aa=="newAccount"){a("#newAccount").slideDown();a("#newOrder").slideDown()}if(aa=="orderComplete"){a("#newOrder").slideDown()}}}}function T(ab){var ac=new Object();var Z=0;var aa;for(i in ab){aa=i;for(j in ab[i]){ac[Z]={field:aa,type:j,body:ab[i][j]};Z++}ac.index=Z}l(ac)}function l(ab){var Z=false;a(".errors").slideUp(500,function(){a(".errors").remove();for(var ac=0;ac<ab.index;ac++){a("#"+ab[ac].field+"-element").append('<p class="errors" style="display:none;">'+ab[ac].body+"</p>");a("."+ab[ac].field+"Tag").append('<p class="errors" style="display:none;">'+ab[ac].body+"</p>")}Z=true;a(".errors").slideDown(1000)});if(Z==false){for(var aa=0;aa<ab.index;aa++){a("#"+ab[aa].field+"-element").append('<p class="errors" style="display:none;">'+ab[aa].body+"</p>");a("."+ab[aa].field+"Tag").append('<p class="errors" style="display:none;">'+ab[aa].body+"</p>")}a(".errors").slideDown(900)}}function M(aa,Z){var ab=new Array();a.ajax({type:"POST",url:Z,data:aa,dataType:"json",success:function(ac){var ad=d(ac)}});return false}function b(aa,Z,ab){a.ajax({type:"POST",url:Z,data:aa,dataType:"html",success:function(ac){switch(ab){case"wagon":if(ac!=""){O();e=true;a(u.container).slideUp(100,function(){if(!e){a(u.container).append(ac)}else{a(u.container).empty();a(u.container).append(ac)}v()}).slideDown(200)}else{ac="<h4>Select items from the list drawer</h4>";a(u.container).append(ac)}break;case"check":if(ac!=""&&ac.length>5){a("#wagonDirections").remove();a("#wagonDirections").remove();O();e=true;a(u.container).slideUp(400,function(){a(u.container).append(ac);v()}).slideDown(200);K()}break;case"reform":if(ac!=""){O();e=true;a(u.container).slideUp(400,function(){a(u.container).empty();a(u.container).append(ac);a(u.container).append(n());E();a("#nextPage").show(200);a("#previousPage").show(200);a("#nextPage").attr("value","submit");a("#nextPage").css({color:"green"});R(2);c=2;if(h==false){setTimeout(function(){w()},400)}}).slideDown(400)}break;case"dumpWagon":a(u.container).slideUp(300,function(){a(u.container).empty();a("#orderNavButtons").hide();a(u.footer).empty()});setTimeout(function(){p();if(!J){setTimeout(function(){q()},600)}},200);c=1;break;case"loginPanel":a("#login_panel").hide(1000,function(){a(".errors").remove();a("#login_panel").replaceWith(ac);setTimeout(function(){a("#accountdetails").click(function(){toggleAccount()});a("#wagonButton").click(W)},700)}).show(1000);case"replaceDiv":if(P!=null){a(P).empty();a(P).append(ac);a(P).show("slide",{direction:"left"},800);a(".editExisting").unbind("click",f);a(".makeEdit").unbind("click",I);a(".editExisting").bind("click",f);a(".makeEdit").bind("click",I)}break}}})}function q(){a("#shoppingwagon").animate({left:"-=25px"},100).animate({left:"+=25px"},100).animate({left:"-=500px"},200).animate({left:"+=500px"},200);x()}function x(){setTimeout(function(){document.getElementById("shoppingwagon").style.display="none";document.getElementById("shoppingwagon").style.left=35+"px"},300)}function p(){a("#shoppingwagon").animate({marginTop:"-=15px"},200).animate({marginTop:"+=15px"},100).animate({marginTop:"-=15px"},200).animate({marginTop:"+=15px"},100)}function r(Z){a(Z).animate({marginTop:"+=5px"},200).animate({marginTop:"-=5px"},100)}function O(){a("#shoppingwagon").show();a("#shoppingwagon").animate({marginTop:"-=15px"},200).animate({marginTop:"+=15px"},100).animate({marginTop:"-=15px"},200).animate({marginTop:"+=15px"},100)}function N(){a(u.selectClass).click(function(ab){var ac=a(this).attr("selector").replace("prodId_","");var Z=a(this).attr("size");var aa=a(this).attr("descript");b("pid="+ac+"&selectTrans="+Z+"&descript="+aa,u.url,"wagon")})}function E(){setTimeout(function(){var Z=true;a("#shopping_email").change(function(){L();var aa="email="+a("#shopping_email").val();aa+="&context=shopping";Y(aa,u.url,"checkAddresses");A=true;a(".shoppingSpinner").show(200)});a(u.clear).click(function(){X();b("clear=itall",u.url,"dumpWagon")});a(u.edit).change(function(){var aa=a("#orderform").serialize()+"&editTrans=form";b(aa,u.url,"wagon")});a(u.deleteable).hover(function(){a(this).children(".deleteButton").show(500)},function(){a(this).children(".deleteButton").hide(500)});a(u.loginButton).click(function(){var aa=a("#shopping_Login").serialize();a(".errors").slideUp(200,function(){a(".errors").remove()});a(".shoppingSpinner").show(200);Y(aa,u.loginUrl,"post")});a("#expandShipping").click(function(){a(u.shippinginfo).slideToggle(200)});a(".deleteButton").click(function(ab){var aa=a(this).attr("value");a("quantity_"+aa).remove().trigger("change");ab.preventDefault()});a("#personform input").change(function(){if(A){var aa=a("#personform").serialize();M("checkForm=checkAll&"+aa,u.url)}});a(".phone").focus(function(){$size=a(this).attr("maxlength");if(a(this).val().length==$size){Z=false}a(this).css({border:"1px blue solid"});a(this).css({position:"relative"});a(this).animate({top:"-=5px"},200).animate({top:"+=5px"},100)});a(".phone").keyup(function(aa){$size=a(this).attr("maxlength");if(aa.which!=16){if(Z){if(a(this).val().length==$size){a(this).next("input").focus()}}else{Z=true}}});a(".phone").blur(function(){a(this).css({border:"1px green solid"})});a("#nextPage").click(function(){if(h==false){M("checkLogin=now",u.url)}if(H=="existingAccount"&&h==true){if(c>=2){var aa=a("#personForm").serialize();M("placeOrder=now&"+aa,u.url)}else{c++;a(u.heading).append(R(c))}}else{if(H=="newAccount"){if(c>=3){var aa=a("#personForm").serialize();M("placeOrder=now&"+aa,u.url)}else{c++;a(u.heading).append(R(c))}}if(H==null){R(2);c=2;w()}}});a("#previousPage").click(function(){c--;a(u.heading).append(R(c))});a(".editExisting").bind("click",f);a(".makeEdit").bind("click",I);a("#shoppingReset").click(function(){M("reset="+a("#email").val(),u.url);a(u.passwordElement+"-label").hide(200);a(u.passwordElement+"-element").hide(200);a("#shoppingReset").hide(200);a("#wagonLoginButton").hide(200);a("#ecosaveLogin").append("<p>Check your email for a reset message.</p>")});a("#wagonComplete").click(function(){X();b("clear=itall",u.url,"dumpWagon");setTimeout(function(){q();U();y=0},500)});a(u.passwordButton).click(function(){var aa=a("#passwordForm").serialize();M(aa,u.pwUrl)})},200)}function w(){a(u.passwordButton).hide();a(u.pi).hide();a(u.cart).hide();a(u.contactinfo).hide();a(u.sendtoinfo).hide();a(u.loginDiv).show();a("#cancelOrder").hide();a("#nextPage").hide();a("#previousPage").hide();a(u.passwordElement+"-label").hide();a(u.passwordElement+"-element").hide();if(o){a(u.newAccountMessage).hide();a(u.passwordElement+"-label").slideDown();a(u.passwordElement+"-element").slideDown();a("#shoppingReset").slideDown();a(u.loginButton).show(200);setTimeout(function(){a("#shopping_password").focus()},900)}else{a(u.passwordElement+"-label").slideUp();a(u.passwordElement+"-element").slideUp();a("#shoppingReset").slideUp()}}function k(){a(u.passwordElement+"-label").slideUp();a(u.passwordElement+"-element").slideUp();a("#shoppingReset").hide();a(u.loginButton).hide(200);if(V){setTimeout(function(){a(".errors").remove(100)},300);a("#orderEmail").val(a("#shopping_email").val());a("#nextPage").show(200);a("#newAccountMessage").show(200);c=1}if(V==false){L()}}function L(){a("#newAccountMessage").hide();a("#nextPage").hide()}function t(){setTimeout(function(){a("#wagonOrderTrigger").click(function(){a("#orderNavButtons").remove();R(1);c=1});a("#wagonContactTrigger").click(function(){a("#orderNavButtons").remove();R(2);c=2});a("#wagonMailTrigger").click(function(){a("#orderNavButtons").remove();R(3);c=3});a("#orderFormLogin").click(function(){z="<p>refresh your browser if you do not have an acccount</p>";a("#wagonLogin").append(z);H="login";R(2);c=2})},1000)}function n(){var Z="";Z='<div id="nextWagonPage">';Z+='<input type="button" id="nextPage" class="shopping" style="float:right;position:relative;top:15px;" value="next" />';Z+='<input type="button" id="previousPage" class="shopping" style="display:none;float:left;position:relative;top:15px;left:35px;" value="back" />';Z+='<input type="button" id="cancelOrder" class="shopping" style="color:red;display:none;float:left;position:relative;top:15px;left:3px;" value="clear" />';Z+="</div>";return Z}function R(ab){a("#orderNavButtons").remove();var aa="";if(H=="login"){a(u.loginButton).show(200);a(u.newAccountMessage).hide(200);a("#wagonContact").hide(200);a("#wagonSendto").hide(200);a("#previousPage").hide(200);a("#orderNavButtons").hide(200);a("#wagonLogin").show(200);a(u.passwordElement+"-label").slideDown();a(u.passwordElement+"-element").slideDown();a("#nextPage").hide(200);return}if(H=="existingAccount"){switch(ab){case 1:a(u.cart).show();a(u.sendtoinfo).hide();a("#existingAccount").hide(200);a("#nextPage").show(200);a("#nextPage").attr("value","next");a("#nextPage").css({color:"black"});a("#previousPage").hide(200);a("#cancelOrder").show(200);c=1;break;case 2:a(u.cart).hide();a(u.sendtoinfo).hide();a("#existingAccount").show(200);a("#nextPage").show(200);a("#nextPage").attr("value","submit");a("#nextPage").css({color:"green"});a("#previousPage").show(200);a("#cancelOrder").hide(200);c=2;break}if(c==3){c=2}return}if(H!=null){a(u.loginDiv).hide();a("#existingAccount").hide();switch(ab){case 1:aa='<div id="orderNavButtons"><a id="wagonOrderTrigger" style="font-weight:bold;color:blue;">order&rarr;</a><a id="wagonContactTrigger">contact&nbsp;</a><a id="wagonMailTrigger">send to</></div>';a(u.cart).show(200);a(u.contactinfo).hide(200);a(u.sendtoinfo).hide(200);a("#nextPage").show(200);a("#nextPage").attr("value","next");a("#nextPage").css({color:"black"});a("#previousPage").hide(200);a("#cancelOrder").show(200);break;case 2:aa='<div id="orderNavButtons"><a id="orderFormLogin" class="wagonlogin" >login</a><a id="wagonOrderTrigger">order&nbsp;</a><a id="wagonContactTrigger" style="font-weight:bold;color:blue;">contact&rarr;</a><a id="wagonMailTrigger">send to</></div>';a(u.cart).hide(200);a(u.contactinfo).show(200);a(u.sendtoinfo).hide(200);a("#nextPage").show(200);a("#nextPage").attr("value","next");a("#nextPage").css({color:"black"});a("#previousPage").show(200);a("#cancelOrder").hide(200);break;case 3:aa='<div id="orderNavButtons"><a id="orderFormLogin" class="wagonlogin" >login</a><a id="wagonOrderTrigger">order&nbsp;</a><a id="wagonContactTrigger">contact&nbsp;</a><a id="wagonMailTrigger" style="font-weight:bold;color:blue;">send to</a></div>';a(u.cart).hide(200);a(u.contactinfo).hide(200);a(u.sendtoinfo).show(200);a("#nextPage").show(200);a("#nextPage").attr("value","submit");a("#nextPage").css({color:"green"});a("#previousPage").show(200);a("#cancelOrder").hide(200);var Z=a("#personForm").serialize();M("save=now&"+Z,u.url);break}}else{a(u.cart).show(200);a(u.contactinfo).hide(200);a(u.sendtoinfo).hide(200);a("#nextPage").show(200);a("#nextPage").attr("value","next");a("#nextPage").css({color:"black"});a("#previousPage").hide(200);a("#cancelOrder").show(200)}a(u.heading).append(aa);setTimeout(function(){t()},200)}function v(){c=1;a(u.container).append(n());E();a(u.heading).append(R(1));t()}function K(){a("#wagonMessage").hide(500,function(){a("#wagonMessage").append("You have items in your cart");a("#wagonEmpty").hide(500);a("#wagonFull").show(500)}).show(1000)}function X(){a("#wagonMessage").hide(500,function(){a("#wagonMessage").empty();a("#wagonEmpty").show(500);a("#wagonFull").hide(500)}).show(1000)}function Y(ac,ab,aa){if(C==null){var Z="index/params/rc/"+a("#shopping_key").val();a.jCryption.getKeys(Z,function(ad){C=ad;a.jCryption.encrypt(ac,ad,function(ae){M(aa+"="+ae,ab)})})}else{a.jCryption.encrypt(ac,C,function(ad){M(aa+"="+ad,ab)})}}}})})(jQuery);
