﻿/*-- Web1by1 (C) Marketing1by1 v1.4.2, October 2010 --*/
var w1x1 = new _w1x1("m1x1.signals.com", "si");
var w1x1_locs = new _w1x1_locs();

jQuery(function () {
    jQuery.ajax({ type: "GET", url: w1x1.u("i", ""),
        contentType: "application/json; charset=utf-8", dataType: "json",
        success: function (r1) {
            if (typeof r1.st != "undefined") {
                w1x1.ceSet(r1.st);
                if (w1x1.ceGet() == -1) { jQuery.getJSON(w1x1.u("i", w1x1.p("ce", 1)), function (r2) { w1x1.ceSet(r2.st); w1x1_ff() }); } else { w1x1_ff() };
            } else { w1x1_ff() };
        },
        error: function () { w1x1_ff(); }
    });
    function w1x1_pr(l, ps) {
        var h = '';
        switch (l) {
            case "P1":
            case "C1":
                jQuery.each(ps, function (j, p) {
                    h += '<td align="center" valign="middle"><table width="140" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="top"><br><a href="' + p.U + '"><img src="' + p.I + '" border="0" alt="' + p.N + '"></a><br><font face="arial, verdana, helvetica, sans-serif" size="2"><a href="' + p.U + '">' + p.N + '</font></a><br><font face=arial,verdana,sans-serif size=2><b>$' + p.P + '</b></font></td></tr></table></td>';
                    if (j == 2) return false;
                });
                jQuery('#w1x1_' + l).append('<table cellspacing="0" cellpadding="0" width="530" border="0"><tr>' + h + '</tr></table>');
                break;
        }
    }
    function w1x1_ff() {
        for (i = 0; i < w1x1_locs.count(); i++) {
            if (w1x1.ceGet() > 0) {
                jQuery.ajax({ type: "GET", url: w1x1.u("pr", w1x1.p("l", w1x1_locs.lGet(i))),
                    contentType: "application/json; charset=utf-8", dataType: "json",
                    w1x1_l: w1x1_locs.lGet(i), w1x1_d: w1x1_locs.dGet(i).Get(), w1x1_s: 0,
                    success: function (data) {
                        if (typeof data.Prods != "undefined") {
                            if (data.Prods.length > 0) { this.w1x1_s = data.Prods.length; w1x1_pr(data.Loc, data.Prods); }
                        }
                    },
                    complete: function () { if (this.w1x1_s == 0) { w1x1_pr(this.w1x1_l, this.w1x1_d); this.w1x1_s = -1; } }
                });
            }
            else { w1x1_pr(w1x1_locs.lGet(i), w1x1_locs.dGet(i).Get()); }
        };

        w1x1.iSend();
    }
});
