/*
 
 jQuery Tools 1.2.3 Overlay - Overlay base. Extend it.
 NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 http://flowplayer.org/tools/overlay/
 Since: March 2008
 Date:    Mon Jun 7 13:43:53 2010 +0000
 */
(function(a){
    function t(d, b){
        var c = this, i = d.add(c), o = a(window), k, f, m, g = a.tools.expose && (b.mask || b.expose), n = Math.random().toString().slice(10);
        if (g) {
            if (typeof g == "string") 
                g = {
                    color: g
                };
            g.closeOnClick = g.closeOnEsc = false
        }
        var p = b.target || d.attr("rel");
        f = p ? a(p) : d;
        if (!f.length) 
            throw "Could not find Overlay: " + p;
        d && d.index(f) == -1 && d.click(function(e){
            c.load(e);
            return e.preventDefault()
        });
        a.extend(c, {
            load: function(e){
                if (c.isOpened()) 
                    return c;
                var h = q[b.effect];
                if (!h) 
                    throw 'Overlay: cannot find effect : "' + b.effect +
                    '"';
                b.oneInstance && a.each(s, function(){
                    this.close(e)
                });
                e = e || a.Event();
                e.type = "onBeforeLoad";
                i.trigger(e);
                if (e.isDefaultPrevented()) 
                    return c;
                m = true;
                g && a(f).expose(g);
                var j = b.top, r = b.left, u = f.outerWidth({
                    margin: true
                }), v = f.outerHeight({
                    margin: true
                });
                if (typeof j == "string") 
                    j = j == "center" ? Math.max((o.height() - v) / 2, 0) : parseInt(j, 10) / 100 * o.height();
                if (r == "center") 
                    r = Math.max((o.width() - u) / 2, 0);
                h[0].call(c, {
                    top: j,
                    left: r
                }, function(){
                    if (m) {
                        e.type = "onLoad";
                        i.trigger(e)
                    }
                });
                g && b.closeOnClick &&
                a.mask.getMask().one("click", c.close);
                b.closeOnClick && a(document).bind("click." + n, function(l){
                    a(l.target).parents(f).length || c.close(l)
                });
                b.closeOnEsc && a(document).bind("keydown." + n, function(l){
                    l.keyCode == 27 && c.close(l)
                });
                return c
            },
            close: function(e){
                if (!c.isOpened()) 
                    return c;
                e = e || a.Event();
                e.type = "onBeforeClose";
                i.trigger(e);
                if (!e.isDefaultPrevented()) {
                    m = false;
                    q[b.effect][1].call(c, function(){
                        e.type = "onClose";
                        i.trigger(e)
                    });
                    a(document).unbind("click." + n).unbind("keydown." + n);
                    g && a.mask.close();
                    return c
                }
            },
            getOverlay: function(){
                return f
            },
            getTrigger: function(){
                return d
            },
            getClosers: function(){
                return k
            },
            isOpened: function(){
                return m
            },
            getConf: function(){
                return b
            }
        });
        a.each("onBeforeLoad,onStart,onLoad,onBeforeClose,onClose".split(","), function(e, h){
            a.isFunction(b[h]) && a(c).bind(h, b[h]);
            c[h] = function(j){
                a(c).bind(h, j);
                return c
            }
        });
        k = f.find(b.close || ".close");
        if (!k.length && !b.close) {
            k = a('<a class="close"></a>');
            f.prepend(k)
        }
        k.click(function(e){
            c.close(e)
        });
        b.load && c.load()
    }
    a.tools = a.tools ||
    {
        version: "1.2.3"
    };
    a.tools.overlay = {
        addEffect: function(d, b, c){
            q[d] = [b, c]
        },
        conf: {
            close: null,
            closeOnClick: true,
            closeOnEsc: true,
            closeSpeed: "fast",
            effect: "default",
            fixed: !a.browser.msie || a.browser.version > 6,
            left: "center",
            load: false,
            mask: null,
            oneInstance: true,
            speed: "normal",
            target: null,
            top: "10%"
        }
    };
    var s = [], q = {};
    a.tools.overlay.addEffect("default", function(d, b){
        var c = this.getConf(), i = a(window);
        if (!c.fixed) {
            d.top += i.scrollTop();
            d.left += i.scrollLeft()
        }
        d.position = c.fixed ? "fixed" : "absolute";
        this.getOverlay().css(d).fadeIn(c.speed, b)
    }, function(d){
        this.getOverlay().fadeOut(this.getConf().closeSpeed, d)
    });
    a.fn.overlay = function(d){
        var b = this.data("overlay");
        if (b) 
            return b;
        if (a.isFunction(d)) 
            d = {
                onBeforeLoad: d
            };
        d = a.extend(true, {}, a.tools.overlay.conf, d);
        this.each(function(){
            b = new t(a(this), d);
            s.push(b);
            a(this).data("overlay", b)
        });
        return d.api ? b : this
    }
})(jQuery);

var triggers;
$(document).ready(function(){
    triggers = $("#overlay").overlay({
        // some mask tweaks suitable for modal dialogs
        target: $('#yesno'),
        mask: {
            color: '#000',
            loadSpeed: 100,
            opacity: 0,
            speed: 1000
        },
        closeOnClick: true,
		onBeforeLoad: function(){
		},
        onLoad: function(){
        id = setTimeout("close()", 2000);
        }
    });
    $('.add2basket').click(function(){
        var gform;
        gform = $(this).parent();
        $.post("catalog/cart-add/", gform.serialize(), function(data){
            $('#basket').html(data);
            $('#yesno').html(data);
		    $("#overlay").overlay().load();
        });
        return false;
    });
});
function close(){
    $("#overlay").overlay().close();
}

