$.fn.startProcessing=function(){var a=$(this),b=a.find("button.submit");if(b.length>0){var g=b.offset();if(a.data("processing"))return false;var d=$("img#loading-image");if(!d.length){d=$('<img src="/images/shared/loading.gif" id="loading-image" style="display:none;z-index:9999999999" />');d.appendTo(document.body)}a.data("processing",true);d.css({position:"absolute",left:g.left+b.outerWidth()+5,top:g.top,height:b.outerHeight(),width:b.outerHeight()}).show()}return true};
$.fn.stopProcessing=function(){var a=$(this);$("img#loading-image").hide();a.data("processing",false)};$.fn.submitJSON=function(a,b){$(this).submit(function(g){g.preventDefault();var d=$(this).closest("form");d.showErrors();if(!d.startProcessing())return false;$.postJSON(d.attr("action"),d.serialize(),function(f){d.stopProcessing();a&&a(f)},function(f){d.stopProcessing();d.showErrors(f);b&&b(f)});return null})};
$.fn.showErrors=function(a){return $(this).each(function(){var b=$(this);b.find(".has-tip").removeClass("has-tip").qtip("destroy");a&&a.errors&&$.each(a.errors,function(g,d){var f=b.attr("data-error-prefix"),h="<ul>";$.each(d,function(c,e){h+="<li>"+e+"</li>"});h+="</ul>";var i=null;i=f?b.find('*[name="'+f+"["+g+']"]'):b.find("*[name="+g+"]");switch(i.attr("data-qtip")||b.attr("data-qtip")){case "left":g="rightMiddle";d="leftMiddle";break;case "bottom":g="topMiddle";d="bottomMiddle";break;case "top":g=
"bottomMiddle";d="topMiddle";break;case "right":default:g="leftMiddle";d="rightMiddle";break}i.addClass("has-tip");i.qtip({content:h,style:{name:"red",tip:g,border:{radius:5},classes:{tooltip:b.closest("#facebox").length==0?"":"huge-z"}},position:{corner:{target:d,tooltip:g},adjust:{screen:true}},show:{delay:0,ready:true,when:"focus"},hide:"blur",api:{onHide:function(){i.removeClass("has-tip").qtip("destroy")}}})})})};
$.postJSON=function(a,b,g,d,f){var h=$("meta[name=csrf-token]").attr("content"),i=$("meta[name=csrf-param]").attr("content");if($.isPlainObject(b)){var c={};c[i]=h;$.extend(b,c)}else if(b!=null)b+="&"+i+"="+i;else b={csrf_param:h};$.ajax({type:f||"POST",url:a,data:b,success:function(e,k){if(e.reload)window.location.reload(true);else if(e.redirect)if(window.location.href.substr(-1*e.redirect.length)==e.redirect)window.location.reload(true);else{window.location=e.redirect;window.location.pathname==
e.redirect.replace(/#.*$/,"")&&window.location.reload(true)}else{if(e.update)for(var j in e.update)$("#"+j).replaceWith(e.update[j]);e.facebox&&$.facebox(e.facebox);$.isFunction(g)&&g(e,k)}},error:function(e,k){if(e.status>399&&e.status<500){var j=$.parseJSON(e.responseText);j.facebox&&$.facebox(j.facebox);$.isFunction(d)&&d(j,k,e.status)}else if(e.status===0||e.status>499&&e.status<600){$.facebox("Something bad happened. Try again!");$.isFunction(d)&&d(null)}},dataType:"json"})};
$.postHTML=function(a,b,g,d){$.ajax({type:"POST",url:a,data:b,success:function(f,h){$.isFunction(g)&&g(f,h)},error:function(f,h){if(f.status>399&&f.status<500)$.isFunction(d)&&d($.parseJSON(f.responseText),h,f.status);else f.status>499&&f.status<600&&$.facebox("Something bad happened. Try again!")},dataType:"html"})};$.formatCurrency=function(a){if(!a||isNaN(a))return"$0";return"$"+a.toString().match(/\d*(\.\d{0,2})?/)[0].replace(/\.00?$/,"")};
$("form button.submit, form a.submit").live("click",function(a){a.preventDefault();$(this).closest("form").submit()});$("img.fb-share").live("click",function(a){a.preventDefault();var b=$(this);if(!b.hasClass("processing")){b.addClass("processing");FB.ensureInit(function(){FB.Connect.requireSession(function(){$.ajax({dataType:"script",url:"/share/facebook",data:{deal_id:b.attr("data-deal-id")},complete:function(){b.removeClass("processing")}})})})}});
$("button[data-href]").live("click",function(){if($(this).attr("target")=="_blank")window.open($(this).attr("data-href"));else window.location=$(this).attr("data-href")});
$("#import-email-widget form#get-addresses").live("submit",function(a){a.preventDefault();a=$(this);var b=a.closest("#import-email-widget");a.submit(function(){var g=$(this).find("input[type=password]"),d=g.val();g.val("");d=KEY.encrypt(UTF8.encode(d));$(this).find("input[type=hidden][name=hidden_pass]").val(d)}).submitJSON(function(g){b.find("#email-account-credentials").hide();b.find("#email-contacts-container").html(g.contacts)});a.submit()});
$("#import-email-widget .try-another-account a").live("click",function(a){var b=$(this).closest("#import-email-widget");a.preventDefault();b.closest("#facebox").find("div#fbox-notif").hide();b.find("form#get-addresses input").attr("value","");b.find("#email-account-credentials").show();b.find("form#get-addresses input:first").focus();b.find(".address-book-wrapper").remove()});
$("#import-email-widget table.address-book-list td.contact").live("click",function(){var a=$(this).parent().find("input.contact")[0];a.checked=!a.checked});
$("#import-email-widget form.address-book").live("submit",function(a){a.preventDefault();var b=[];$(this).find("input.contact:checked").each(function(){var d=$(this);b.push({name:d.attr("data-name"),email:d.attr("data-email")})});a={contacts:JSON.stringify(b)};var g=$(this).closest("#import-email-widget").find("input[name=deal_id]");g.length>0&&$.extend(a,{deal_id:g.val()});g=$(this).closest("#import-email-widget").find("input[name=purchase_id]");g.length>0&&$.extend(a,{purchase_id:g.val()});$.postJSON($(this).attr("action"),
a)});$("#import-email-widget form.address-book input#address-book-select_all").live("click",function(){$(this).closest("form.address-book").find(".address-book-list-wrapper input[type=checkbox]");$(this).attr("checked")?$("div.address-book-list-wrapper input[type=checkbox]").attr("checked","checked"):$("div.address-book-list-wrapper input[type=checkbox]").removeAttr("checked")});
$(document).ready(function(){$("h1#logo").click(function(){window.location="/"});$("input.has-inner-label").hasInnerLabel();$("abbr.timeago").timeago();var a=$("#city-selector"),b=$("#city-header div.select-city a");$("#selected-city");var g=function(){var d=b.offset(),f=$("#content > .container"),h=f.offset();a.css({left:h.left+f.width()/2-a.width()/2-15+"px",top:d.top+b.outerHeight()-1})};b.click(function(d){d.preventDefault();if($(this).hasClass("active")){a.hide();$(this).removeClass("active");
$("#clippy").show()}else{$("#clippy").hide();$(this).addClass("active");g();a.show()}});a.find("a.close-button").click(function(d){d.preventDefault();a.hide();b.removeClass("active")});$(window).resize(function(){g()});$("#deal-signup").submitJSON();$("a.resend_email_confirmation").click(function(d){d.preventDefault();$.postJSON("/resend_email_confirmation",{},function(f){$.facebox(f.message)})});$("#credit-amount").click(function(){$.facebox("<b>Credit is the equivalent of 'cash'</b> you can use on the site towards any purchase. You get Credit when you invite new users, or get 'cash-back' from some of our fun types of deals. Your Credit amount goes up and down as your earn it and spend it. Get enough and your next purchase can be free!")});
$("#points-amount").click(function(){$.facebox("<b>Your Points make you special.</b> They mark your achievement within the HomeRun community, and increase as you do more, enjoy more, and share more. As your relationship with HomeRun deepens, you'll see that you get Points for inviting, sharing, buying, and checking in to HomeRun. <br/><br/>As you accrue more Points, special offers like <a href='/private-reserve'>The Private Reserve</a> will unlock for you. We restrict access to certain offers and present them to our most loyal members. So your Points are part of your reward for participating, and part of the reason to keep coming back.")});
$("span.explain_confirm").click(function(d){d.preventDefault();$.facebox("We sent you an email asking you to confirm your email address. Please click the link inside or click [resend] if we should send another. If you don't see it, check your spam folder. If you're still having trouble finding it, <a href='/whitelist'>click here</a> for help.")});$("body").ajaxStart(function(){$(this).css("cursor","progress")}).ajaxStop(function(){$(this).css("cursor","auto")});$("#opinion-box a.reason").click(function(d){d.preventDefault();
var f=$(this);$.postJSON("/unlike",{deal_id:f.attr("data-deal_id"),reason:f.attr("data-reason")},function(){f.closest(".body").find(".before-answer").hide().end().find(".after-answer").show()})});$("a.global-recommend-link").click(function(d){d.preventDefault();var f=$(this).attr("href");$.facebox(function(){$.get(f,function(h){$.facebox(h);$("input.has-inner-label").hasInnerLabel();$("#facebox form#get-addresses input:first").focus()})})});$("#inline-sharer form#recommend-deal").submit(function(){var d=
$(this),f=[],h=d.find("input[name=email]").val();h&&f.push({email:h});d.find("input[name=contacts]").val(JSON.stringify(f))}).submitJSON(function(){$("form#recommend-deal input[name=email]").val("")});$(".login-button").click(function(d){d.preventDefault();$.postJSON("/login/facebox",{show_login:$(this).hasClass("show-login")},function(f){$.facebox(f.partial);$("#login-facebox input.has-inner-label, #apply-facebox input.has-inner-label").hasInnerLabel();$("#"+$("#login-facebox").attr("data-init-mode")+
"-facebox input#user_email").focus();$("#login-facebox form").submit(function(){var h=$(this).find("input[type=password]"),i=h.val();h.val("");i=KEY.encrypt(UTF8.encode(i));$(this).find("input[type=hidden][name=hidden_pass]").val(i)}).submitJSON(function(){window.location.reload(true)});$("#apply-facebox form").submitJSON();$("#facebox .account-toggle a").click(function(h){h.preventDefault();$("#facebox .has-tip").qtip("destroy");$("#login-facebox, #apply-facebox").toggle();$("#"+$(this).attr("data-to-mode")+
"-facebox .email").focus()})})});$(document).bind("close.facebox",function(){$("#facebox .has-tip").qtip("destroy")});$("#multi-sharer input").mouseup(function(){$(this).select()});$("body").append("<div id='opaque' style='display: none;'></div>");$(document).bind("loading.facebox",function(){$("#opaque").show()});$(document).bind("close.facebox",function(){$("#opaque").hide()});$(document).bind("afterReveal.facebox",function(){$("#opaque").height($(document).height())});$("#opaque").click(function(){$(document).trigger("close.facebox")})});
var showFacebookLoader=function(a){a&&$.facebox(function(){$("#facebox").find(".loading").css("text-align","center").html('<table style="margin:auto"><tr><td><img src="/images/facebox/loading.gif"/></td><td style="padding-left:15px; font-size: 15pt; color: #666666">Connecting with Facebook..</td></tr></table>');document.location.reload(true)})};$(document).ready(function(){$("form.login").submitJSON()});$("a.forgot-password").live("click",function(){var a=$(this).closest("form");a.showErrors();if(!a.startProcessing())return false;$.postJSON("/forgot_password",a.serialize(),function(b){a.stopProcessing();$.facebox(b.message);a.find('input[type="text"], input[type="password"]').val("")},function(b){a.stopProcessing();a.showErrors(b)});return false});$(document).ready(function(){if($("#account-invite").length>0){var a=null,b=$("#account-invite div.green-box .clippy");if(b.length>0){b.addClass("has-tip");b.qtip({content:{text:"Click to copy link"},style:{name:"cream",tip:"leftMiddle",border:{radius:5}},position:{corner:{target:"rightMiddle",tooltip:"leftMiddle"},adjust:{y:8,scroll:false,resize:false}},show:{ready:true},hide:false});clippyCopiedCallback=function(){b.qtip("api").updateContent("Copied!",false);a&&clearTimeout(a);a=setTimeout(function(){b.qtip("api").updateContent("Click to copy link",
false)},3E3)}}}});$(document).ready(function(){if($("#account-show").length>0){$("#account-show a.fb_unlink").click(function(c){c.preventDefault();$(this).attr("data-fb-logged-in")=="true"?$.postJSON("/fb/unlink",{},function(){FB.Connect.logout(function(){window.location.reload(true)})}):$.postJSON("/fb/unlink",{},function(){window.location.reload(true)})});var a=$("#validity_token").val();$("#delete_image").click(function(c){c.preventDefault();$.ajax({type:"DELETE",url:$(this).attr("href"),data:{},success:function(e){$("#account-show div.wrapper.profile-image img").replaceWith(e.image);
$("span#main-user-image").replaceWith("<span id='main-user-image'>"+e.image+"</span>");$("span#img-delete").hide()},dataType:"json"})});$("#upload_image").uploadify({uploader:"/flash/uploadify.swf",script:"/account/image",cancelImg:"/images/shared/upload-cancel.png",folder:"/images/users",scriptData:{validity_token:a},method:"put",queueID:"fileQueue",buttonText:"upload now",sizeLimit:1048576,auto:true,multi:false,onError:function(c,e,k,j){j.type=="File Size"?$.facebox("That image is over the 1MB limit, try a smaller one."):
$.facebox("Something went wrong. Try reloading the page and giving it another shot.")},onComplete:function(c,e,k,j){c=$.parseJSON(j);$("#account-show div.wrapper.profile-image img").replaceWith(c.image);$("span#main-user-image").replaceWith("<span id='main-user-image'>"+c.image+"</span>");$("span#img-delete").show()}});var b=$("table.about td.second .hide"),g=$("table.about td.second textarea");g.bind("change keyup",function(){b.show()});b.find("a.save").click(function(c){c.preventDefault();$.postJSON($(this).attr("href"),
{"account[about]":g.val()},function(){b.hide()},null,"put")});b.find("a.cancel").click(function(c){c.preventDefault();b.hide()});var d=function(){$("table.name td.second a.change").click(function(c){c.preventDefault();var e=$("table.name td.second div.hide"),k=$("table.name td.second span.name"),j=$(this);e.show();e.find("a.send").click(function(l){l.preventDefault();$.postJSON($(this).attr("href"),{"account[first_name]":e.find("input[name=account_first_name]").val(),"account[last_name]":e.find("input[name=account_last_name]").val()},
function(m){$("table.name td.second").empty();$("table.name td.second").append(m.html);$("#user-nav .full_name a").text(m.full_name);$("input.has-inner-label").hasInnerLabel();d()},null,"put")}).end().find("a.cancel").click(function(l){l.preventDefault();e.hide();j.show();k.show()});k.hide();j.hide()})};d();var f=function(){$("#account-email a.new-email").click(function(c){c.preventDefault();$("#account-email div.new-email").show()});$("#account-email div.new-email a.cancel").click(function(c){c.preventDefault();
$("#account-email div.new-email").hide();$("#account-email div.new-email input.what").val("")});$("#account-email div.new-email a.send").click(function(c){c.preventDefault();$.postJSON($(this).attr("href"),{email:$("#account-email div.new-email input.what").val()},function(){f()})});$("#account-email div.email a.delete").click(function(c){c.preventDefault();$.postJSON($(this).attr("href"),{email:$(this).closest(".email").attr("email")},function(){f()})});$("#account-email div.email a.resend").click(function(c){c.preventDefault();
$.postJSON($(this).attr("href"),{email:$(this).closest(".email").attr("email")})});$("#account-email div.email a.primary").click(function(c){c.preventDefault();$.postJSON($(this).attr("href"),{email:$(this).closest(".email").attr("email")},function(){f()})})};f();var h=function(){$("#account-credit a.delete").click(function(c){c.preventDefault();$.postJSON($(this).attr("href"),null,function(){h()},null,"delete")});$("#account-credit a.primary").click(function(c){c.preventDefault();$.postJSON($(this).attr("href"),
{primary:true},function(){h()},null,"put")});$("#new-credit .has-inner-label").hasInnerLabel();$("#new-credit").submitJSON(function(){h()});$("#account-credit a.new-credit").click(function(c){c.preventDefault();$("#account-credit div.new-credit").show();$("input.has-inner-label").repositionInnerLabels()});$("#account-credit a.cancel").click(function(c){c.preventDefault();$("#account-credit div.new-credit").find(".has-tip").qtip("destroy").end().hide()});$("#account-credit div.new-credit a.cancel").click(function(c){c.preventDefault();
$("#account-credit div.new-credit").hide();$("#account-credit form#new-credit").trigger("reset")});$("#account-credit form#new-credit").bind("reset",function(c){c.preventDefault();$(this).find('input[type="text"],select').val("")})};h();$("#account-show a.pass-change").click(function(){$("#account-show .pass-change-info").show();$(this).hide();$("input.has-inner-label").repositionInnerLabels();return false});$("#account-show div.pass-change-info a.cancel-pass-change").click(function(){$("#account-show div.pass-change-info").hide().find("input").val("");
$("#account-show a.pass-change").show();return false});$("#account-show div.pass-change-info form.pass-change").submitJSON(function(){$("#account-show div.pass-change-info a.cancel-pass-change").click();return false});$("#account-email div.email a.delete").click(function(c){c.preventDefault();$.postJSON($(this).attr("href"),{email:$(this).closest(".email").attr("email")},function(){f()})});var i=function(){$("#account-networks a.remove-sub").click(function(c){c.preventDefault();confirm("Are you sure?")&&
$.postJSON("/subscription/remove",{sub_id:$(this).attr("data-sub-id")},function(){i()})});$("#account-networks select#new-region-id").change(function(c){c.preventDefault();$.postJSON("/subscription/add",{region_id:$(this).find("option:selected").val()},function(){i()})})};i();$("small.cvv-help a").click(function(c){c.preventDefault();$.facebox({div:"#cvv-help"})})}});$(document).ready(function(){if($("#account-intro").length>0){$("form.signup-field, form.user-info").submitJSON();$('form.user-info input[type="text"]:first').focus()}});$(document).ready(function(){if($("#account-intro.apply").length>0){$("#account-intro.apply img").click(function(){$.facebox("Subscribe to get access to these deals.")});setTimeout(function(){$("#facebox").length==0&&$("#email-address").focus()},12E3);var a=-1,b=[2,2,2];setInterval(function(){for(var g=a;g==a;)g=Math.floor(Math.random()*3);for(var d=b[g],f=d;f==d;)f=Math.floor(Math.random()*3);$("table#stacks .stack:eq("+g+")").find(".column:eq("+d+")").fadeOut(2E3).end().find(".column:eq("+f+")").fadeIn(2E3);
a=g;b[g]=f},3E3)}});$(document).ready(function(){$("#business-inquire").length>0&&$("form.biz-info").submitJSON()});$(document).ready(function(){if($("#redeem").length>0){var a=$("form.redeem");a.submitJSON(function(){a.find("input.barcode").val("");$.facebox("Successfully redeemed")})}});$(document).ready(function(){if($("#deal-get").length>0){$("form#order").submitJSON();var a=$("form#order input.price"),b=0,g=$("form#order input.total"),d=parseInt(a.val(),10),f=parseInt(g.val(),10),h=parseInt($("form#order input.credits").val(),10),i=$("td.price-area td.total.value"),c=$("td.reduced-total.value");$("#deal_quantity").blur(function(){var e=$(this);e.val()==""&&e.val("1")});$("#deal_quantity").keyup(function(){var e=$(this);e.val(e.val().replace(/[^0-9]/g,""));e=parseInt(e.val(),10);
if(isNaN(e)||e<1)e=1;b=d*e;f=b-h;g.val(f);if(c.length>0)if(f>0){c.text($.formatCurrency(f/100));$("form#order #still-need-cc").hide()}else{c.text("FREE");$("table.billing-info tbody").is(":visible")?$("form#order #still-need-cc").show():$("form#order #still-need-cc").hide()}i.text($.formatCurrency(b/100));if(b>h)$("form#order span#applied-credit").text($.formatCurrency(h/100));else h>0&&$("form#order span#applied-credit").text($.formatCurrency(b/100))});$("form#order").length>0&&$("#deal_quantity").select();
$("select#card_existing_id").change(function(){if($(this).find("option:selected").val()=="new"){$("table.billing-info tbody").find('input[type="text"]').val("").end().show();f<=0&&$("form#order #still-need-cc").show()}else{$("table.billing-info tbody").hide();$("form#order #still-need-cc").hide();$("table.billing-info tbody .has-tip").qtip("destroy")}})}});$(document).ready(function(){if($("#deal-main").length>0){jQuery.timeago.settings.allowFuture=true;jQuery.timeago.settings.strings.suffixFromNow="";var a=$("#time-left-indicator");if(a.length!=0){var b,g=function(){b=parseInt(a.attr("data-time-left"),10);if(b>=0){var c=b,e={};e.day=Math.floor(c/86400);e.hour=Math.floor((c-=e.day*86400)/3600);e.minute=Math.floor((c-=e.hour*3600)/60);e.second=Math.floor(c-e.minute*60);$.each(e,function(k){var j=e[k];$("big#time-left-"+k).html(j)});a.attr("data-time-left",
b-1)}else{clearInterval(g);window.location.reload(true)}};window.setInterval(g,1E3);g();if($("#deal-main div.buy.blue-box.avalanche").length!=0){var d=function(c,e){var k=c.offset();c.offset({left:e-c.width()/2,top:k.top});c.css({visibility:"visible"})},f=$("#deal-main div.buy.blue-box.avalanche .progress-bar"),h=$("#deal-main div.buy.blue-box.avalanche .sliders .next-drop img");h.length>0&&d(h,f.offset().left+f.outerWidth())}$("table.steps .invite-friends").click(function(){$.facebox({ajax:"/address_book"})})}var i=
function(){$("form.cancel-purchase").submit(function(c){confirm("Are you sure you want to cancel your order?")||c.stopPropogation()}).submitJSON()};i();$("#next-time button").click(function(c){c.preventDefault();$.postJSON("/next_time",{deal_id:$(this).attr("data-deal_id")},function(){$("#next-time").find(".do").hide().end().find(".success").show()})});$("table.purchase-info button.more-purchase-info").click(function(){var c=$(this).attr("data-purchase-id");$.facebox(function(){$.get("/more_purchase_info/"+
c,function(e){$.facebox(e);$("#facebox abbr.timeago").timeago();i()})});return false})}});$(document).ready(function(){$("#discuss").length>0&&$("#discuss form#post").submitJSON()});
