try {
    document.execCommand("BackgroundImageCache", false, true)
} catch(e) {}
var groupon = {};
groupon.style = {
    alternate: function(b, a) {
        this.find("tr:even").css("background-color", b);
        this.find("tr:odd").css("background-color", a)
    },
    markLine: function(a) {
        var b = null;
        this.find("tr").hover(function() {
            b = $(this).css("background-color");
            $(this).css("background-color", a)
        },
        function() {
            $(this).css("background-color", b)
        })
    }
};
groupon.frontEnd = {
    layer: function(j) {
        var f = this,
        c = j.width || "1004px",
        p = j.height || "auto",
        o = j.ajax || false,
        q = j.effect || false,
        h = j.toggleType || "hover",
        d = j.speed || 1004,
        b = j.closeButton,
        n = {},
        i = null,
        l = false,
        m = function() {
            if (o) {
                $.get(o.url, 
                function(r) {
                    f.html(r)
                })
            }
            switch (q) {
            case "fade":
                f.fadeIn(d);
                break;
            case "slide":
                f.slideDown(d);
                break;
            default:
                f.show()
            }
        },
        k = function() {
            switch (q) {
            case "fade":
                f.fadeOut(d);
                break;
            case "slide":
                f.slideUp(d);
                break;
            default:
                f.hide()
            }
        },
        a = null,
        g = {
            bind: function(r) {
                if (r) {
                    i = r;
                    if (h == "hover") {
                        i.parent()[h](function() {
                            g.open()
                        },
                        function() {
                            g.close()
                        })
                    } else {
                        i[h](function(s) {
                            s.preventDefault();
                            g.open()
                        });
                        if (b) {
                            b.click(function(s) {
                                s.preventDefault();
                                g.close();
                                g.fire("LayerClose")
                            })
                        }
                    }
                    return g
                }
            },
            on: function(s, r) {
                n[s] = r
            },
            fire: function(r) {
                if (n[r]) {
                    n[r].call(g)
                }
            },
            close: function() {
                if (l) {
                    if (h == "hover") {
                        if (a) {
                            clearTimeout(a);
                            a = null;
                            return
                        }
                        i.removeClass("active");
                        k()
                    } else {
                        a = null;
                        i.removeClass("active");
                        k()
                    }
                    l = false
                }
            },
            open: function() {
                if (!l) {
                    if (h == "hover") {
                        if (a) {
                            return
                        }
                        a = setTimeout(function() {
                            i.addClass("active");
                            m();
                            a = null
                        },
                        200)
                    } else {
                        if (a) {
                            return
                        }
                        i.addClass("active");
                        m();
                        a = true
                    }
                    l = true;
                    g.fire("LayerOpen")
                }
            },
            toggles: function() {
                if (!l) {
                    g.open()
                } else {
                    g.close()
                }
            }
        };
        return g
    },
    selectSlide: function(f) {
        var a = this,
        g = this.height(),
        b = false,
        d = {},
        c = null,
        i = {
            bind: function(h) {
                c = h;
                c.click(function(j) {
                    j.preventDefault();
                    i.toggles()
                });
                return i
            },
            toggles: function() {
                if (!b) {
                    a.animate({
                        height: f + "px"
                    },
                    1004);
                    c.addClass("active");
                    i.fire("SelectOpen");
                    b = true
                } else {
                    a.animate({
                        height: g + "px"
                    },
                    1004);
                    c.removeClass("active");
                    i.fire("SelectClose");
                    b = false
                }
            },
            on: function(k, j) {
                d[k] = j
            },
            fire: function(h) {
                if (d[h]) {
                    d[h].call(i)
                }
            }
        };
        return i
    },

    inputText: function() {
        this.each(function() {
            var a = $(this),
            b = a[0].defaultValue;
            a.focus(function() {
                if (this.value === b) {
                    this.value = ""
                }
                a.blur(function() {
                    if (/^\s*$/.test(this.value)) {
                        this.value = b
                    }
                    $(this).unbind("blur")
                })
            })
        })
    },
    share: function() {
        /*var a = {
            kaixin: "http://www.kaixin001.com/repaste/share.php?rtitle={title}&rurl={url}",
            renren: "http://share.renren.com/share/buttonshare.do?title={title}&link={url}",
            douban: "http://www.douban.com/recommend/?url={url}&title={title}",
            sina: "http://v.t.sina.com.cn/share/share.php?title={title}&url={url}",
            sohu: "http://bai.sohu.com/share/blank/addbutton.do?from=tuanbao&link={url}",
            email: "mailto:?body=hello{title}{url}"
        };*/
        this.each(function() {
            var d = $(this),
            b = encodeURIComponent(d.children("div.url").text()),
            f = encodeURIComponent(d.children("div.title").text()),
            c = "";
            c = d.html().replace(/ href="?[^" ]+"? +rel="?([^" ]+?)"?\s*>/ig, 
            function(i, h) {
                var g = a[h].replace(/{url}/g, b).replace(/{title}/g, f);
                return ' href="' + g + '">'
            });
            d.html(c)
        })
    },
    slide: function() {
        this.each(function() {
            var h = $(this),
            d = null,
            k = h.find("li"),
            j = k.length - 1,
            i = h.find("div > a"),
            b = 0,
            g = false,
            f = false;
            function c(a) {
                if (g) {
                    return
                }
                k.each(function(m) {
                    var l = $(this),
                    n = typeof a != "undefined" ? a: (b == j ? 0: b + 1);
                    if (n != m && m == b) {
                        l.animate({
                            left: "-1004px"
                        },
                        function() {
                            b = n;
                            l.css("left", "1004px");
                            i.eq(m).removeClass("active")
                        })
                    } else {
                        if (m == n) {
                            l.animate({
                                left: "0"
                            },
                            function() {
                                i.eq(m).addClass("active");
                                g = false
                            })
                        }
                    }
                })
            }
            d = setInterval(c, 4000, undefined);
            i.click(function(a) {
                a.preventDefault();
                clearTimeout(d);
                i.eq(b).removeClass("active");
                c(i.index(this));
                g = true
            });
            h.hover(function() {
                clearTimeout(d);
                f = true
            },
            function() {
                f = false;
                d = setInterval(c, 4000, undefined)
            })
        })
    }
};
$.fn.extend(groupon.frontEnd);
$.fn.extend(groupon.style);
$(function() {
    var b = $("#selectCity").selectSlide(87).bind($("#selectCity .type"));
    $("#manageMenu").layer({
        effect: "fade"
    }).bind($("#myTUANBAO"));
    var c = $("#city").layer({
        effect: "fade",
        toggleType: "click",
        closeButton: $("#closeCity"),
        speed: 250
    }).bind($("#switchCity"));
    var a = $("#province").layer({
        effect: "fade",
        toggleType: "click",
        closeButton: $("#closeProvince"),
        speed: 250
    }).bind($("#switchProvince"));
    c.on("LayerOpen", 
    function() {
        a.close()
    });
    c.on("LayerClose", 
    function() {
        b.toggles()
    });
    a.on("LayerOpen", 
    function() {
        c.close()
    });
    a.on("LayerClose", 
    function() {
        b.toggles()
    });
    b.on("SelectClose", 
    function() {
        a.close();
        c.close()
    });
    $("#province div.province > span").hover(function() {
        $(this).addClass("active")
    },
    function() {
        $(this).removeClass("active")
    });
    $("input[type=text]").inputText();
    $("div.share").share();
    $("div.imgbox").slide();
	$("div.adbox").slide();/*²»Í¬µÄdiv*/
    /*$("p.time").countdown();
    $("div.order").orderModify();
    $("#city").switchByPY(1);
    $("#managecoupons, #managetable").alternate("#f3f3f3", "#ffffff");
    $("#delivAddr").markLine("#e8f4db")*/
});
