var Activity = Class.create({

    initialize: function(message, options) {
        this._options = Object.extend({
            element: null,
            form: null,
            forms: null,
            minDuration: 0,
            onClear: null,
            block: false
        }, options);

        this._forms = this._options.forms || [this._options.form];

        this.onClear = this._options.onClear;

        jQuery(document.body).addClass("working");

        /*if(!this._options.block && (this._title = jQuery("#section-header h1:first:visible")).length > 0) {
            
        this._oldTitleText = this._title.text();
        this._title.text(message);
        } else {
        // old-style fallback indicator
        this._element = jQuery('<div class="busy-block"><div><span>' + message.escapeHTML() + '</span></div></div>').prependTo($(document.body))[0];
        }*/
        if (this._options.block) {
            // old-style fallback indicator
            this._element = jQuery('<div class="busy-block"><div><span>' + message.escapeHTML() + '</span></div></div>').prependTo(jQuery("body"))[0];
        }

        var f = function(form) {
            /*Form.disable(form);
            jQuery(form).find("button").each(function() {
            Form.Element.disable(this);
            });*/
            jQuery(form).addClass("working");
            jQuery(form).find("input,textarea,select,button").attr("disabled", true);
        };
        if (this._forms && Object.isArray(this._forms)) {
            this._forms.each(f);
        } else if (this._forms) {
            f(this._forms);
        }

        if (this._options.element) {
            this._origElementText = jQuery(this._options.element).text();
            jQuery(this._options.element).text(message).addClass("working");
        }

        if (this._options.minDuration > 0) {
            window.setTimeout(this._timerCallback.bind(this), this._options.minDuration * 1000);
        } else {
            this._timerExpired = true;
        }

        return this;
    },
    onClear: null,
    clear: function() {
        this._clearCalled = true;
        if (this._timerExpired) {
            jQuery(document.body).removeClass("working");
            if (this._title && this._title.length > 0) {
                this._title.text(this._oldTitleText);

            }
            if (this._element) {
                jQuery(this._element).remove();
                this._element = null;
            }
            var f = function(form) {
                /*Form.enable(form);
                jQuery(form).find("button").each(function() {
                Form.Element.enable(this);
                });*/
                jQuery(form).removeClass("working");
                jQuery(form).find("input,textarea,select,button").removeAttr("disabled");
            };
            if (this._forms && Object.isArray(this._forms)) {
                this._forms.each(f);
            } else if (this._forms) {
                f(this._forms);
            }
            if (this._options.element) {
                jQuery(this._options.element).text(this._origElementText).removeClass("working");
            }
            if (this.onClear && this.onClear.call) {
                this.onClear();
            }
        }
    },
    _timerCallback: function() {
        this._timerExpired = true;
        if (this._clearCalled) {
            this.clear();
        }
    }

});
var FormActivity = Class.create(Activity, {
    initialize: function($super, forms, message, options) {
        $super(message, Object.extend(options || {}, Object.isArray(forms) ? { forms: forms} : { form: forms }));
    }
});
jQuery(function($) {
    // preload...
    new Activity("Loading...").clear();
});
// always support document baseURI
if (!document.baseURI) {
    var base = document.getElementsByTagName("base")[0];
    if (base) {
        document.baseURI = base.href;
    }
}

jQuery(function($) {
    var baseUri
    $("#signup,#upgrade,#billing-edit,#upgrade,#downgrade").submit(function(e) {
        e.preventDefault();
        var form = this;
        Form.request(form, {
            onCreate: function() {
                progress = new FormActivity(form, "Submitting...", { minDuration: 2 });
                $("#status").empty();
            },
            onSuccess: function(response) {

		if($(form).is(".consult")) {
			window.location.href = "http://getrocketship.com/thank_you";
			return;
		}

                var f = function() {

                	var url = response.getHeader("Location") || response.getHeader("Content-Location");

                	if (url) window.location.href = url;

                	else if (form.action == window.location.href) window.location.reload();

                	else window.location.href = (function(url) { return url.startsWith("./") ? document.baseURI + url.substr(2) : url; })(form.action);

                };

                if(window.__RSCommission) {

                	window.__RSCommission(f);

                } else {

                	f();

                }

            },
            onFailure: function(response) {
                // error
                if ($("#status").length > 0) Element.scrollTo($("#page-body-content")[0]);
                $('<p />', { className: "error", html: response.status == 500 ? "We couldn't process your info -- please check it and try again." : response.responseText }).appendTo("#status");
            },
            onComplete: function(response) {
                progress.clear();
            }
        });
    });
    $("#design-questionaire").submit(function(e) {
        $(this).addClass("working").find("button").attr("disabled", "disabled");
        $("#status").empty();
        var form = this;
        if ($(this).find("iframe").size() == 0) {
            $('<iframe name="_form-uploader" style="display:none;"></iframe>').appendTo(this).load(function(e) {
                $(form).removeClass("working").find("button").removeAttr("disabled");
                //return;
                if (form.action == window.location.href) window.location.reload();
                else window.location.href = (function(url) { return url.startsWith("./") ? document.baseURI + url.substr(2) : url; })(form.action);
            });
        }
        this.target = "_form-uploader";
    });

});
(function(jQuery, cufon) {

    var c = {
        //"#page-title": { fontFamily : "myriad pro semibold" },
        "#page-title": { fontFamily: "myriad pro", textShadow: "#000000 0 1px" },
        "#page-title strong": { fontFamily: "myriad pro semibold",
            color: "-linear-gradient(#fffcd0,#c6c16f)", textShadow: "#000000 0 1px"
        },
        "#plans h3" : { fontFamily:"myriad pro semibold" },
        "#plans h2, #design-process h3": { fontFamily: "myriad pro light" },
        //"#plans-help p": { fontFamily: "georgia" },
        "#plans-help abbr, #design-process h2, #service h2, #service h3, #plans h4, form h3, #completed h2, #purchase-details h4, #service-details h4, #billing-info .tel": { fontFamily: "verdana" }
        
    };

    jQuery.fn.cufon = function(options, ignoreHistory) {
        return this.each(function() {
            cufon.replace(this, options, ignoreHistory);
        });
    };
    jQuery.fn._text = jQuery.fn.text;
    jQuery.fn.text = function(text) {
        var ret = this._text(text);
        var query = this;
        if (typeof text !== "object" && text != null) {
            query.each(function() {
                var x = jQuery(this).data("cufon");
                var elem = this;
                if (!x) {
                    for (var s in c) {
                        if (jQuery(elem).is(s)) {
                            jQuery(elem).data("cufon", x = c[s]);
                            break;
                        }
                    }
                }
                if (x) {
                    cufon.replace(this, x);
                }
            });
        }
        return ret;
    }

    for (var s in c) {
        cufon.replace(s, c[s]);
    }

})(window.jQuery, window.Cufon);



