/*  Copyright (c) 2001-2010. Matteo Bicocchi (Pupunzi); Open lab srl, Firenze - Italy */
(function(d) {
  var k = d(window).width(), l = d(window).height();
  d.doOnWindowResize = function(c) {
    clearTimeout(this.doRes);
    this.doRes = setTimeout(function() {
      d(c).adjastPos();
      k = d(window).width();
      l = d(window).height()
    }, 800)
  };
  d.fn.adjastPos = function(c) {
    clearTimeout(this.doRes);
    if(d(this).attr("options").mantainOnWindow) {
      c || (c = 20);
      var b = d(window).width() + d(window).scrollLeft(), a = d(window).height() + d(window).scrollTop();
      this.each(function() {
        if(d(this).offset().left + d(this).outerWidth() > b || d(this).offset().top + d(this).outerHeight() > a) {
          var e = d(this).offset().left + d(this).outerWidth() > b ? b - d(this).outerWidth() - c : d(this).offset().left, f = d(this).offset().top + d(this).outerHeight() > a ? a - d(this).outerHeight() - c : d(this).offset().top;
          f = f > 0 ? f : 0;
          d(this).animate({left:e, top:f}, 600)
        }
      })
    }
  };
  jQuery.fn.buildContainers = function(c) {
    var b = this;
    return this.each(function() {
      if(!d(this).is("[inited=true]")) {
        this.options = {containment:"document", elementsPath:"elements/", dockedIconDim:35, onCollapse:function() {
        }, onBeforeIconize:function() {
        }, onIconize:function() {
        }, onClose:function() {
        }, onBeforeClose:function() {
        }, onResize:function() {
        }, onDrag:function() {
        }, onRestore:function() {
        }, onLoad:function() {
        }, mantainOnWindow:true, collapseEffect:"slide", effectDuration:600};
        d.extend(this.options, c);
        this.options.mantainOnWindow && d(window).resize(function() {
          d.doOnWindowResize(b)
        });
        var a = d(this);
        a.attr("inited", "true");
        a.attr("iconized", "false");
        a.attr("collapsed", "false");
        a.attr("closed", "false");
        a.attr("fullscreen", "false");
        a.attr("options", this.options);
        !a.css("position") == "absolute" && a.css({position:"relative"});
        if(d.metadata) {
          d.metadata.setType("class");
          a.metadata().skin && a.attr("skin", a.metadata().skin);
          a.metadata().collapsed && a.attr("collapsed", a.metadata().collapsed);
          a.metadata().iconized && a.attr("iconized", a.metadata().iconized);
          a.metadata().icon && a.attr("icon", a.metadata().icon);
          a.metadata().buttons && a.attr("buttons", a.metadata().buttons);
          a.metadata().content && a.attr("content", a.metadata().content);
          a.metadata().data && a.attr("data", a.metadata().data);
          a.metadata().aspectRatio && a.attr("aspectRatio", a.metadata().aspectRatio);
          a.metadata().grid && a.attr("grid", a.metadata().grid);
          a.metadata().gridx && a.attr("gridx", a.metadata().gridx);
          a.metadata().gridy && a.attr("gridy", a.metadata().gridy);
          a.metadata().handles && a.attr("handles", a.metadata().handles);
          a.metadata().dock && a.attr("dock", a.metadata().dock);
          a.metadata().closed && a.attr("closed", a.metadata().closed);
          a.metadata().rememberMe && a.attr("rememberMe", a.metadata().rememberMe);
          a.metadata().isModal && a.attr("isModal", a.metadata().isModal);
          a.metadata().width && a.attr("width", a.metadata().width);
          a.metadata().height && a.attr("height", a.metadata().height);
          a.metadata().alwaysOnTop && a.css("z-index", 1E5).addClass("alwaysOnTop");
          a.metadata().containment && a.attr("containment", a.metadata().containment);
          a.metadata().minWidth && a.attr("minWidth", a.metadata().minWidth);
          a.metadata().minHeight && a.attr("minHeight", a.metadata().minHeight)
        }
        if(a.attr("rememberMe") == "true") {
          a.attr("width", a.mb_getCookie("width") != null ? a.mb_getCookie("width") : a.attr("width"));
          a.attr("height", a.mb_getCookie("height") != null ? a.mb_getCookie("height") : a.attr("height"));
          a.attr("closed", a.mb_getCookie("closed") != null ? a.mb_getCookie("closed") : a.attr("closed"));
          a.attr("collapsed", a.mb_getCookie("collapsed") != null ? a.mb_getCookie("collapsed") : a.attr("collapsed"));
          a.attr("iconized", a.mb_getCookie("iconized") != null ? a.mb_getCookie("iconized") : a.attr("iconized"));
          a.attr("fullscreen", a.mb_getCookie("fullscreen") != null ? a.mb_getCookie("fullscreen") : a.attr("fullscreen"));
          a.css("left", a.mb_getCookie("x") != null ? a.mb_getCookie("x") : a.css("left"));
          a.css("top", a.mb_getCookie("y") != null ? a.mb_getCookie("y") : a.css("top"))
        }
        if(a.attr("content")) {
          var e = a.attr("data") ? a.attr("data") : "";
          a.mb_changeContainerContent(a.attr("content"), e)
        }
        a.addClass(a.attr("skin"));
        a.find(".n:first").attr("unselectable", "on");
        a.find(".n:first").html() || a.find(".n:first").html("&nbsp;");
        a.containerSetIcon(a.attr("icon"), this.options.elementsPath);
        a.attr("buttons") && a.containerSetButtons(a.attr("buttons"), this.options);
        a.css({width:"99.9%"});
        if(a.attr("width")) {
          e = d.browser.msie ? a.attr("width") : a.attr("width") + "px";
          a.css({width:e})
        }
        if(a.attr("height")) {
          a.find(".c:first , .mbcontainercontent:first").css("height", a.attr("height") - a.find(".n:first").outerHeight() - a.find(".s:first").outerHeight());
          a.attr("height", "");
          a.css({height:""})
        }else {
          d.browser.safari && a.find(".mbcontainercontent:first").css("padding-bottom", 5)
        }
        e = d(window).height();
        a.outerHeight() > e && a.find(".c:first , .mbcontainercontent:first").css("height", e - 20 - a.find(".n:first").outerHeight() - a.find(".s:first").outerHeight());
        if(a.hasClass("draggable")) {
          e = a.css("position") == "static" ? "absolute" : a.css("position");
          a.css({position:e, margin:0});
          a.find(".n:first").css({cursor:"move"});
          a.mb_bringToFront();
          a.draggable({handle:".n:first", delay:0, containment:this.options.containment, stop:function() {
            var f = d(this).attr("options");
            f.onDrag && f.onDrag(d(this));
            if(a.attr("rememberMe")) {
              a.mb_setCookie("x", a.css("left"));
              a.mb_setCookie("y", a.css("top"))
            }
          }});
          if(a.attr("grid") || a.attr("gridx") && a.attr("gridy")) {
            e = a.attr("grid") ? [a.attr("grid"), a.attr("grid")] : [a.attr("gridx"), a.attr("gridy")];
            a.draggable("option", "grid", e)
          }
          a.bind("mousedown", function() {
            d(this).mb_bringToFront()
          })
        }
        a.hasClass("resizable") && a.containerResize();
        if(a.attr("collapsed") == "true") {
          a.attr("collapsed", "false");
          a.containerCollapse(this.options)
        }
        if(a.attr("iconized") == "true") {
          a.attr("iconized", "false");
          a.containerIconize(this.options)
        }
        if(a.attr("fullscreen") == "true") {
          a.attr("fullscreen", "false");
          a.containerFullscreen(this.options)
        }
        if(a.mb_getState("closed")) {
          a.attr("closed", "false");
          a.mb_close()
        }
        setTimeout(function() {
          var f = a.attr("options");
          f.onLoad && f.onLoad(a);
          a.css("visibility", "visible");
          a.adjastPos()
        }, 1E3)
      }
    })
  };
  jQuery.fn.containerResize = function() {
    var c = d(this);
    c.attr("options");
    var b = c.hasClass("draggable"), a = c.attr("handles") ? c.attr("handles") : "s", e = c.attr("aspectRatio") ? c.attr("aspectRatio") : false, f = c.attr("minWidth") ? c.attr("minWidth") : 350, g = c.attr("minHeight") ? c.attr("minHeight") : 150;
    c.resizable({handles:b ? "" : a, aspectRatio:e, minWidth:f, minHeight:g, iframeFix:true, helper:"mbproxy", start:function(h, m) {
      var i = c.attr("containment") ? c.parents() : d(window), j = c.attr("containment") ? c.position() : c.offset();
      d(c).resizable("option", "maxHeight", i.height() - (j.top - 5));
      d(c).resizable("option", "maxWidth", i.width() - (j.left - 5));
      m.helper.mb_bringToFront()
    }, stop:function() {
      var h = d(this).outerHeight() - c.find(".n:first").outerHeight() - c.find(".s:first").outerHeight();
      c.find(".c:first , .mbcontainercontent:first").css({height:h});
      if(!b && !c.attr("handles")) {
        h = c.attr("width") && c.attr("width") > 0 ? c.attr("width") : "99.9%";
        c.css({width:h})
      }
      h = c.attr("options");
      h.onResize && h.onResize(c);
      if(c.attr("rememberMe")) {
        c.mb_setCookie("width", c.outerWidth());
        c.mb_setCookie("height", c.outerHeight())
      }
    }});
    c.resizable("option", "maxHeight", d("document").outerHeight() - (c.offset().top + c.outerHeight()) - 10);
    c.find(".ui-resizable-n").addClass("mb-resize").addClass("mb-resize-resizable-n");
    c.find(".ui-resizable-e").addClass("mb-resize").addClass("mb-resize-resizable-e");
    c.find(".ui-resizable-w").addClass("mb-resize").addClass("mb-resize-resizable-w");
    c.find(".ui-resizable-s").addClass("mb-resize").addClass("mb-resize-resizable-s");
    c.find(".ui-resizable-se").addClass("mb-resize").addClass("mb-resize-resizable-se")
  };
  jQuery.fn.containerSetIcon = function(c, b) {
    var a = d(this);
    if(c && c != "") {
      a.find(".ne:first").prepend("<img class='icon' src='" + b + "icons/" + c + "' style='position:absolute'/>");
      a.find(".n:first").css({paddingLeft:25})
    }else {
      a.find(".n:first").css({paddingLeft:0})
    }
  };
  jQuery.fn.containerSetButtons = function(c, b) {
    var a = d(this);
    b || (b = a.attr("options"));
    var e = b.elementsPath;
    if(c != "") {
      var f = c.split(",");
      a.find(".ne:first").append("<div class='buttonBar'></div>");
      for(var g in f) {
        if(f[g] == "c") {
          a.find(".buttonBar:first").append("<img src='" + e + a.attr("skin") + "/close.png' class='close'  title='close container' />");
          a.find(".close:first").bind("click", function() {
            a.mb_close()
          })
        }
        if(f[g] == "m") {
          a.find(".buttonBar:first").append("<img src='" + e + a.attr("skin") + "/min.png' class='collapsedContainer'  title='minimize container' />");
          a.find(".collapsedContainer:first").bind("click", function() {
            a.containerCollapse(b)
          });
          a.find(".n:first").bind("dblclick", function() {
            a.containerCollapse(b)
          })
        }
        if(f[g] == "p") {
          a.find(".buttonBar:first").append("<img src='" + e + a.attr("skin") + "/print.png' class='printContainer'  title='print container' />");
          a.find(".printContainer:first").bind("click", function() {
          })
        }
        if(f[g] == "i") {
          a.find(".buttonBar:first").append("<img src='" + e + a.attr("skin") + "/iconize.png' class='iconizeContainer'  title='iconize container' />");
          a.find(".iconizeContainer:first").bind("click", function() {
            a.containerIconize(b)
          })
        }
        if(f[g] == "f") {
          d(this).find(".buttonBar:first").append("<img src='" + e + d(this).attr("skin") + "/fullscreen.png' class='fullscreenContainer' title='toggle container size'/>");
          d(this).find(".fullscreenContainer:first").bind("click", function() {
            a.containerFullscreen(b)
          })
        }
      }
      var h = d.browser.mozilla || d.browser.safari;
      h && a.find(".buttonBar:first img").css({opacity:0.5, cursor:"pointer", mozUserSelect:"none", khtmlUserSelect:"none"}).mouseover(function() {
        d(this).fadeTo(200, 1)
      }).mouseout(function() {
        h && d(this).fadeTo(200, 0.5)
      });
      a.find(".buttonBar:first img").attr("unselectable", "on")
    }
  };
  jQuery.fn.containerCollapse = function(c) {
    this.each(function() {
      var b = d(this);
      c || (c = b.attr("options"));
      if(b.mb_getState("collapsed")) {
        if(c.collapseEffect == "fade") {
          b.find(".o:first").fadeIn(c.effectDuration, function() {
          })
        }else {
          b.find(".o:first").slideDown(c.effectDuration, function() {
          });
          b.find(".icon:first").hide();
          b.animate({height:b.attr("h")}, c.effectDuration, function() {
            b.find(".icon:first").show();
            b.css({height:""})
          })
        }
        b.hasClass("resizable") && b.resizable("enable");
        b.attr("collapsed", "false");
        b.find(".collapsedContainer:first").attr("src", c.elementsPath + b.attr("skin") + "/min.png");
        b.find(".mbcontainercontent:first").css("overflow", "auto")
      }else {
        b.attr("w", b.outerWidth());
        b.attr("h", b.outerHeight());
        if(c.collapseEffect == "fade") {
          b.find(".o:first").fadeOut(c.effectDuration, function() {
          })
        }else {
          b.find(".icon:first").hide();
          b.find(".o:first").slideUp(c.effectDuration, function() {
          });
          b.animate({height:b.find(".n:first").outerHeight() + b.find(".s:first").outerHeight()}, c.effectDuration, function() {
            b.find(".icon:first").show()
          })
        }
        b.attr("collapsed", "true");
        b.find(".collapsedContainer:first").attr("src", c.elementsPath + b.attr("skin") + "/max.png");
        b.resizable("disable");
        c.onCollapse && c.onCollapse(b)
      }
      b.attr("rememberMe") && b.mb_setCookie("collapsed", b.mb_getState("collapsed"))
    })
  };
  jQuery.fn.containerIconize = function(c) {
    var b = d(this);
    c || (c = b.attr("options"));
    return this.each(function() {
      c.onBeforeIconize && c.onBeforeIconize();
      b.attr("iconized", "true");
      if(b.attr("collapsed") == "false") {
        b.attr("h", b.outerHeight());
        b.attr("h", !b.attr("height") && !b.css("height") ? "" : b.outerHeight())
      }
      b.attr("w", b.attr("width") && b.attr("width") > 0 ? !b.hasClass("resizable") ? b.attr("width") : b.width() : !b.attr("handles") ? "99.9%" : b.width());
      b.attr("t", b.css("top"));
      b.attr("l", b.css("left"));
      b.resizable("disable");
      var a = 0, e = b.css("top"), f = b;
      if(b.attr("dock")) {
        f = d("#" + b.attr("dock"));
        a = f.find("img").size();
        a = d("#" + b.attr("dock")).offset().left + c.dockedIconDim * a;
        e = d("#" + b.attr("dock")).offset().top
      }
      this.dockIcon = d("<img src='" + c.elementsPath + "icons/" + (b.attr("icon") ? b.attr("icon") : "restore.png") + "' class='restoreContainer' width='" + c.dockedIconDim + "'/>").appendTo(f).css("cursor", "pointer").hide().attr("contTitle", b.find(".n:first").text()).bind("click", function() {
        b.attr("iconized", "false");
        b.is(".draggable") ? b.css({top:d(this).offset().top, left:d(this).offset().left}) : b.css({left:"auto", top:"auto"});
        b.show();
        if(d.browser.msie) {
          b.find(".no:first").show();
          if(b.attr("collapsed") == "false") {
            b.css({height:b.attr("h"), width:b.attr("w"), left:b.attr("l"), top:b.attr("t")}, c.effectDuration);
            b.find(".c:first , .mbcontainercontent:first").css("height", b.attr("h") - b.find(".n:first").outerHeight() - b.find(".s:first").outerHeight())
          }else {
            b.css({height:"60px", width:b.attr("w"), left:b.attr("l"), top:b.attr("t")}, c.effectDuration)
          }
        }else {
          b.find(".no:first").fadeIn("fast");
          b.attr("collapsed") == "false" ? b.animate({height:b.attr("h"), width:b.attr("w"), left:b.attr("l"), top:b.attr("t")}, c.effectDuration, function() {
            b.find(".mbcontainercontent:first").css("overflow", "auto");
            b.hasClass("draggable") && b.mb_bringToFront();
            b.css({height:""})
          }) : b.animate({height:"60px", width:b.attr("w"), left:b.attr("l"), top:b.attr("t")}, c.effectDuration)
        }
        b.hasClass("resizable") && b.attr("collapsed") == "false" && b.resizable("enable");
        d(this).remove();
        b.hasClass("draggable") && b.mb_bringToFront();
        d(".iconLabel").remove();
        b.attr("restored", true);
        c.onRestore && c.onRestore(b);
        if(b.attr("rememberMe")) {
          b.mb_setCookie("restored", b.mb_getState("restored"));
          b.mb_setCookie("closed", false);
          b.mb_setCookie("iconized", false);
          b.mb_setCookie("collapsed", false);
          b.mb_setCookie("fullscreen", false)
        }
        c.mantainOnWindow && d.doOnWindowResize(b)
      }).bind("mouseenter", function() {
        var g = "<div class='iconLabel'>" + d(this).attr("contTitle") + "</div>";
        d("body").append(g);
        d(".iconLabel").hide().css({position:"absolute", top:d(this).offset().top - 20, left:d(this).offset().left + 15, opacity:0.9}).fadeIn("slow").mb_bringToFront()
      }).bind("mouseleave", function() {
        d(".iconLabel").fadeOut("fast", function() {
          d(this).remove()
        })
      });
      if(d.browser.msie) {
        b.find(".no:first").hide();
        b.css({height:c.dockedIconDim, width:c.dockedIconDim, left:a, top:e});
        d(this.dockIcon).show();
        b.attr("dock") && b.hide()
      }else {
        b.find(".mbcontainercontent:first").css("overflow", "hidden");
        b.find(".no:first").slideUp("fast");
        b.animate({height:c.dockedIconDim, width:c.dockedIconDim, left:a, top:e}, c.effectDuration, function() {
          d(this.dockIcon).show();
          b.attr("dock") && b.hide()
        })
      }
      c.onIconize && c.onIconize(b);
      b.attr("rememberMe") && b.mb_setCookie("iconized", b.mb_getState("iconized"))
    })
  };
  jQuery.fn.mb_resizeTo = function(c, b, a) {
    a = a || a == undefined ? 200 : 0;
    var e = d(this);
    if(e.mb_getState("closed") || e.mb_getState("iconized")) {
      b && e.attr("w", b);
      c && e.attr("h", c);
      if(e.attr("rememberMe")) {
        e.mb_setCookie("width", e.attr("w"));
        e.mb_setCookie("height", e.attr("h"))
      }
    }else {
      b || (b = e.outerWidth());
      c || (c = e.outerHeight());
      var f = c - e.find(".n:first").outerHeight() - e.find(".s:first").outerHeight();
      e.find(".c:first , .mbcontainercontent:first").animate({height:f}, a);
      e.animate({height:c, width:b}, a, function() {
        e.adjastPos();
        var g = e.attr("options");
        g.onResize && g.onResize(e);
        if(e.attr("rememberMe")) {
          e.mb_setCookie("width", e.outerWidth());
          e.mb_setCookie("height", e.outerHeight())
        }
      })
    }
  };
  jQuery.fn.mb_iconize = function() {
    return this.each(function() {
      var c = d(this), b = c.get(0);
      if(!c.mb_getState("closed")) {
        if(c.mb_getState("iconized")) {
          d(b.dockIcon).click();
          c.mb_bringToFront()
        }else {
          c.containerIconize();
          b.options.onIconize && b.options.onIconize(d(b))
        }
      }
    })
  };
  jQuery.fn.mb_open = function(c, b) {
    var a = d(this), e = Math.floor(a.attr("t")), f = Math.floor(a.attr("l"));
    a.css("top", e).css("left", f);
    e = a.get(0);
    if(a.mb_getState("closed")) {
      if(c) {
        b || (b = "");
        a.mb_changeContainerContent(c, b)
      }
      d.browser.msie ? a.show() : a.fadeIn(300);
      a.attr("closed", "false");
      if(a.attr("rememberMe")) {
        a.mb_setCookie("closed", false);
        a.mb_setCookie("restored", true)
      }
      a.mb_bringToFront();
      a.attr("restored", true);
      a.mb_getState("collapsed") || a.mb_resizeTo(a.attr("h"), a.attr("w"), false);
      e.options.onRestore && e.options.onRestore(d(e))
    }
    return a
  };
  jQuery.fn.mb_close = function() {
    var c = d(this).get(0), b = d(this);
    if(!b.mb_getState("closed") && !b.mb_getState("iconized")) {
      c.options.onBeforeClose && c.options.onBeforeClose(d(c));
      if(!b.mb_getState("collapsed")) {
        b.attr("w", b.outerWidth());
        b.attr("h", b.outerHeight());
        b.attr("t", b.offset().top);
        b.attr("l", b.offset().left)
      }
      if(d.browser.msie) {
        b.hide();
        c.options.onClose && c.options.onClose(d(c))
      }else {
        b.fadeOut(300, function() {
          c.options.onClose && c.options.onClose(d(c))
        })
      }
    }
    b.attr("closed", "true");
    b.attr("rememberMe") && b.mb_setCookie("closed", true);
    return d(this)
  };
  jQuery.fn.mb_toggle = function() {
    !d(this).mb_getState("closed") && !d(this).mb_getState("iconized") && d(this).containerCollapse();
    return d(this)
  };
  jQuery.fn.mb_bringToFront = function() {
    var c = 10;
    d("*").not(".alwaysOnTop").each(function() {
      if(d(this).css("position") == "absolute" || d(this).css("position") == "fixed") {
        c = parseInt(d(this).css("zIndex")) > c ? parseInt(d(this).css("zIndex")) : c
      }
    });
    d(this).not(".alwaysOnTop").css("zIndex", c += 1);
    return c
  };
  jQuery.fn.mb_changeContent = function(c, b) {
    var a = d(this);
    b || (b = "");
    d.ajax({type:"POST", url:c, data:b, success:function(e) {
      a.html(e)
    }})
  };
  jQuery.fn.mb_changeContainerContent = function(c, b) {
    d(this).find(".mbcontainercontent:first").mb_changeContent(c, b)
  };
  jQuery.fn.mb_getState = function(c) {
    c = d(this).attr(c);
    return c = c == "true"
  };
  jQuery.fn.mb_fullscreen = function(c) {
    var b = d(this);
    if(b.mb_getState("iconized") || b.mb_getState("collapsed") || b.mb_getState("closed")) {
      b.attr("w", d(window).width() - 40);
      b.attr("h", d(window).height() - 40);
      b.attr("t", 20);
      b.attr("l", 20);
      b.css("height", "")
    }else {
      b.animate({top:20, left:20, position:"relative"}, 600, "swing", function() {
        if(b.attr("rememberMe")) {
          b.mb_setCookie("x", d(this).css("left"));
          b.mb_setCookie("y", d(this).css("top"))
        }
      });
      b.mb_resizeTo(d(window).height() - 40, d(window).width() - 40, c);
      b.attr("w", d(this).outerWidth());
      b.attr("h", d(this).outerHeight());
      b.attr("t", d(this).offset().top);
      b.attr("l", d(this).offset().left);
      b.css("height", "");
      b.mb_bringToFront();
      return b
    }
  };
  jQuery.fn.mb_centerOnWindow = function(c) {
    var b = d(this), a = d(window).width(), e = d(window).height(), f = b.outerWidth(), g = b.outerHeight();
    a = (a - f) / 2;
    e = (e - g) / 2 > 0 ? (e - g) / 2 : 10;
    if(b.css("position") != "fixed") {
      a += d(window).scrollLeft();
      e += d(window).scrollTop()
    }
    if(c) {
      b.animate({top:e, left:a}, 600, function() {
        if(b.attr("rememberMe")) {
          b.mb_setCookie("x", d(this).css("left"));
          b.mb_setCookie("y", d(this).css("top"))
        }
      })
    }else {
      b.css({top:e, left:a});
      if(b.attr("rememberMe")) {
        b.mb_setCookie("x", d(this).css("left"));
        b.mb_setCookie("y", d(this).css("top"))
      }
    }
    return b
  };
  jQuery.fn.mb_switchFixedPosition = function() {
    return this.each(function() {
      var c = d(this);
      typeof c.attr("pos") == "undefined" && c.attr("pos", c.css("position"));
      if(c.css("position") == c.attr("pos")) {
        c.css("top", parseFloat(c.css("top")) - d(window).scrollTop());
        c.css("position", "fixed")
      }else {
        c.css("position", c.attr("pos"));
        c.css("top", parseFloat(c.css("top")) + d(window).scrollTop())
      }
    })
  };
  jQuery.fn.mb_switchAlwaisOnTop = function() {
    return this.each(function() {
      var c = d(this);
      if(c.hasClass("alwaysOnTop")) {
        c.removeClass("alwaysOnTop").css("z-index", c.get(0).zi)
      }else {
        c.get(0).zi = c.css("z-index");
        c.css("z-index", 1E5).addClass("alwaysOnTop")
      }
    })
  };
  jQuery.fn.mb_setPosition = function(c, b) {
    return this.each(function() {
      d(this).animate({top:c, left:b}, 600)
    })
  };
  jQuery.fn.mb_setCookie = function(c, b, a) {
    var e = d(this).attr("id");
    e || (e = "");
    a || (a = 7);
    var f = new Date;
    f.setTime(f.getTime() + a * 24 * 60 * 60 * 1E3);
    a = "; expires=" + f.toGMTString();
    document.cookie = c + "_" + e + "=" + b + a + "; path=/"
  };
  jQuery.fn.mb_getCookie = function(c) {
    var b = d(this).attr("id");
    b || (b = "");
    c = c + "_" + b + "=";
    b = document.cookie.split(";");
    for(var a = 0;a < b.length;a++) {
      for(var e = b[a];e.charAt(0) == " ";) {
        e = e.substring(1, e.length)
      }
      if(e.indexOf(c) == 0) {
        return e.substring(c.length, e.length)
      }
    }
    return null
  };
  jQuery.fn.mb_removeCookie = function(c) {
    d(this).mb_setCookie(c, "", -1)
  };
  jQuery.fn.containerFullscreen = function() {
    var c = d(this);
    if(!(!c.is(".draggable") || c.is("[iconized='true']") || c.is("[collapsed='true']"))) {
      if(c.is("[fullscreen='true']")) {
        c.attr("fullscreen", "false");
        c.mb_resizeTo(c.attr("h2"), c.attr("w2"));
        c.animate({top:c.attr("t2"), left:c.attr("l2"), position:"relative"}, 600)
      }else {
        c.attr("fullscreen", "true");
        c.attr("w2", c.outerWidth());
        c.attr("h2", c.outerHeight());
        c.attr("t2", c.css("top"));
        c.attr("l2", c.css("left"));
        c.mb_fullscreen()
      }
    }
  }
})(jQuery);
