(function ($) { $(function () {
    $.get(EASYESTIMATES.URL + "/ajax-easyestimate.php", {"passgroup": EASYESTIMATES.ID}, function (data, textStatus) {
        var script = "";
        data = data.replace(/<script[^>]*>[\s\S]*?<\/script>/ig, function (m) {
            script += m;
            return "";
        });
        //console.log(data);
        var $pricing = $("#box-pricing .pricing-body")/*.css({"visibility": "hidden"})*/.html(data);
        var $from = $pricing.find("form");
        var $to = $('<div><div id="textareax" class="msgareaclass"></div></div>').appendTo($pricing);

        $from.find(">table>tbody>tr").each(function () {
            var $opt = $('<dl class="pricing-option overflow"><dt class="opt-title"></dt><dd class="opt-data"></dd></dl>').appendTo($to);
            var $tab = $(">td:eq(1) table td", this);

            if ($tab.eq(0).html()) {
                $opt.find("dt.opt-title").append($tab.eq(0).html()).attr({"id": $tab.eq(0).attr("id")});

                if ($tab.length == 2) {
                    $opt.find("dd.opt-data").append($tab.eq(1).find(">*"));
                    if ($(">td:eq(2)>*", this).length) {
                        $(">td:eq(2)>*", this).appendTo($('<div class="data-addson"></div>').appendTo($opt.find("dd.opt-data")));
                    }
                }
                else if ($tab.length == 1) {
                    $opt.find("dd.opt-data").append($(">td:eq(2)>*", this));

                    if ($opt.find("dd.opt-data>*").is("a") && $opt.find("dd.opt-data>*").length == 1) {
                        $opt.addClass("pricing-option-header");
                    }
                }
            }
            else {
                $opt.remove();
            }

            if ($tab.eq(0).attr("id") == "itx" + EASYESTIMATES.ID_TOTAL) {
                $opt.appendTo('.pricing-foot');
            }

            $opt = $tab = null;
        }).end().find("input").appendTo($to);

        $to.find(".pricing-option-header").not(":first").each(function () {
            $(this).before('<div class="pricing-option-line" />');
        });

        $from.remove();
        $("<div/>").appendTo($pricing).html(script);

        $("#box-pricing .bg-loading").hide();
        $("#box-pricing .box-pricing-inner").show();
        $pricing = $from = $to = null;


//        $("[name=inline" + EASYESTIMATES.ID_SIZE + "],[name=inline" + EASYESTIMATES.ID_HEIGHT + "],[name=inline" + EASYESTIMATES.ID_WIDTH + "]").change(function () {
//            swfobjectEmbedSWF(EMBEDFLASH.sizing);
//            (function () {
//                if ($('#flashObject')[0].viewMode) {
//                    $('#flashObject')[0].viewMode(20, 4, 1, 2, 3);
//                }
//                else {
//                    setTimeout(arguments.callee, 500);
//                }
//            })();
//        });
    }, "html");



    $("#submit-free-proof,#submit-order-pay").click(function () {
        if (this.id == "submit-free-proof") {
            $("#order-free-proof").val("1");
        }
        var order_info = [];
        $("#box-pricing .pricing-option").each(function () {
            var id = $(".opt-title", this).attr("id").replace(/[^\d]/g, "");
            order_info[order_info.length] = {
                "id": id,
                "name": $("#itx" + id, this).text(),
                "header": $(this).is(".pricing-option-header") & 1,
                "inline": $("input[name=savetext" + id + "]", this).val(),
                "outline": ($("input[name=outline" + id + "]", this).is(":hidden") ? "" : $("input[name=outline" + id + "]", this).val())
            }
            if (id == EASYESTIMATES.ID_TOTAL) {
                var total = order_info[order_info.length-1]["outline"];
                total = parseFloat(total.replace(/,/g, ""));
                $("#order-total").val(total);
            }
        });
        var specialchar = function (s) {
            s = s || "";
            s = s.toString();
            s = s.replace(/&/, "&amp;");
            s = s.replace(/:/, "&58;");
            s = s.replace(/,/, "&44;");
            s = s.replace(/#/, "&35;");
            return s;
        };
        for (var i = 0, l = order_info.length; i < l; i ++) {
            var t = [];
            for (var j in order_info[i]) {
                t[t.length] = j + ":" + specialchar(order_info[i][j]);
            }
            order_info[i] = t.join(",")
            t = null;
        }
        order_info = order_info.join("#");
        $("#order-info").val(order_info);
        specialchar = order_info = null;

        $(this).parents("form").submit();
        return false;
    });

    return true;
});})(jQuery);

function swfobjectEmbedSWF(o) {
    swfobject.embedSWF(o.src, "flashObject", "416", "320", "8.0.0", "./expressInstall.swf", o.vars, {"wmode": "transparent"});
}

swfobjectEmbedSWF(EMBEDFLASH.gallery);
