(function() {
  function la(a) {
    function b() {
      var s;
      if(g) {
        s = (j.contentDocument || j.contentWindow.document).location.hash;
        if(i != s) {
          i = s;
          a(s.substr(1));
          location.hash = s
        }
      }else {
        s = location.hash;
        if(i != s) {
          i = s;
          a(s.substr(1))
        }
      }
      k = z(b, 100);
      A = false
    }
    function d() {
      u || b()
    }
    function c(s) {
      function ma() {
        if(t > 0) {
          t -= q
        }
        if(g) {
          var U = j.contentWindow.document;
          U.open();
          U.close();
          U.location.hash = s
        }
        A = true;
        location.hash = i = "#" + s
      }
      z(ma, t);
      t += q
    }
    function f() {
      u = false;
      clearTimeout(k)
    }
    var e = Object.prototype.toString.call(window.opera) == "[object Opera]", g = !!window.attachEvent && !e, u = false, k, i = location.hash, j, q = e || g ? 400 : 200, t = 0, z = window.setTimeout, A = false;
    if("onhashchange" in window) {
      w(window, "hashchange", function() {
        A || a(location.hash.substr(1))
      })
    }else {
      if(g) {
        e = '<iframe id="PAI_history" style="display: none;" src="javascript:false;"></iframe>';
        if(F == "prototypejs") {
          $$("body")[0].insert({top:e})
        }else {
          F == "jquery" && n("body").prepend(e)
        }
        j = o("PAI_history");
        e = j.contentWindow.document;
        e.open();
        e.close();
        e.location.hash = i
      }else {
        if(e) {
          if(F == "prototypejs") {
            $$("body")[0].insert({top:'<img src="javascript:location.href=\'javascript:PAI.checkLocation();\';" style="left:-1000px;top:-1000px;width:1px;height:1px;border:0;position:absolute;" />'})
          }else {
            F == "jquery" && n("body").prepend('<img src="javascript:location.href=\'javascript:PAI.checkLocation();\';" style="left:-1000px;top:-1000px;width:1px;height:1px;border:0;position:absolute;" />')
          }
          window.PAI.checkLocation = b
        }
      }
      d()
    }
    this.start = d;
    this.stop = f;
    this.add = c
  }
  function na() {
  }
  var F, o, V, m, B, L, G, W, X, C, P, Y, Z, D, w, M, aa, ba, Q;
  if(typeof Prototype !== "undefined") {
    var N = Element, R = Object;
    F = "prototypejs";
    o = $;
    V = function(a) {
      return a.evalJSON()
    };
    m = Object.toJSON;
    B = N.readAttribute;
    L = N.identify;
    G = N.update;
    W = N.scrollTo;
    X = N.up;
    C = R.isElement;
    P = R.isArray;
    Y = R.toQueryString;
    Z = R.extend;
    D = Prototype.emptyFunction;
    w = Event.observe;
    M = $A;
    aa = function(a) {
      return Form.serialize(a, {hash:true})
    };
    ba = String.prototype.toQueryParams;
    Q = function(a) {
      return new Ajax.Request(a.url, {parameters:a.data, onSuccess:function(b) {
        return(a.success || D)(b["response" + (a.dataType = "JSON")], b.statusText, b)
      }, onException:a.error, onComplete:a.complete})
    }
  }else {
    if(typeof jQuery !== "undefined") {
      var n = jQuery;
      F = "jquery";
      o = function(a) {
        if(typeof a === "string") {
          a = document.getElementById(a)
        }
        return a
      };
      V = n.parseJSON;
      m = n.toJSON;
      B = n.attr;
      var oa = 0;
      L = function(a) {
        a = o(a);
        var b = B(a, "id");
        if(b) {
          return b
        }
        do {
          b = "pai_anonymous_element_" + oa++
        }while(o(b));
        a.setAttribute("id", b);
        return b
      };
      D = n.noop;
      w = n.event.add;
      M = n.makeArray;
      X = n.closest;
      C = function(a) {
        return!!(a && a.nodeType == 1)
      };
      P = n.isArray;
      aa = function(a) {
        a = n(a).serializeArray();
        for(var b = a.length, d = {}, c = 0;c < b;c++) {
          d[a[c].name] = a[c].value
        }
        return d
      };
      Y = n.param;
      ba = function(a) {
        a = a.split("&");
        for(var b = a.length, d = {}, c, f = 0;f < b;f++) {
          c = a[f].split("=", 2);
          d[c[0]] = c[1]
        }
        return 0
      };
      Z = n.extend;
      G = function(a, b) {
        n(a).html(b)
      };
      W = function(a) {
        a = n(a);
        var b = a.w();
        window.scrollTo(b.left, b.top);
        return a
      };
      Q = n.ajax
    }else {
      throw"PAI requires either the Prototype or the jQuery JavaScript framework";
    }
  }
  var l = {e:true}, p, y = "", E = "", r, x, ea, fa, S, v, T;
  function H(a) {
    a = o(a);
    return B(a, "data-pai-skip") == "true" ? true : false
  }
  var ca = {};
  function I(a) {
    a = a ? o(a) : document;
    function b(j) {
      H(this) || j.preventDefault()
    }
    function d(j) {
      if(!H(this)) {
        l.g == "click" && j.preventDefault();
        j = unescape(this.href).substr(r.length);
        if(E != j) {
          h.a("click", this, [j]);
          T.add(j);
          J(j)
        }
      }
    }
    for(var c = M(a.getElementsByTagName("a")), f = c.length, e, g = 0;g < f;g++) {
      e = c[g];
      if(B(e, "data-pai-ajaxified") != "true" && !H(e) && r == unescape(e.href).substr(0, r.length)) {
        e.setAttribute("data-pai-ajaxified", "true");
        if(l.g != "click") {
          w(e, l.g, d);
          w(e, "click", b)
        }else {
          w(e, "click", d)
        }
      }
    }
    function u(j) {
      var q = (ca[L(this)][1] || D)();
      if(typeof q === "undefined") {
        q = true
      }
      if(q) {
        if(!H(this)) {
          j.preventDefault();
          ga(this)
        }
      }else {
        j.preventDefault()
      }
    }
    c = M(a.getElementsByTagName("form"));
    f = c.length;
    var k, i;
    for(g = 0;g < f;g++) {
      e = c[g];
      if(B(e, "data-pai-ajaxified") != "true") {
        k = unescape(B(e, "action"));
        i = "";
        if(k) {
          if(k.substr(0, r.length) == r) {
            i = k.substr(r.length)
          }else {
            if(k.substr(0, x.length) == x) {
              i = k.substr(x.length)
            }
          }
        }else {
          i = E
        }
        if(i) {
          k = L(e);
          w(e, "submit", u);
          e.setAttribute("data-pai-ajaxified", "true");
          ca[k] = [i, e.onsubmit];
          e.onsubmit = D
        }
      }
    }
    return a
  }
  function O(a, b) {
    function d(i) {
      if(C(i) && !H(i)) {
        w(i, "load", function() {
          f += 1;
          (b.k || D).apply(i, [c, f]);
          if(c == f) {
            (b.h || D).apply(i, [c])
          }
        });
        c += 1
      }
    }
    a = a ? o(a) : document;
    var c = 0, f = 0;
    b = b || {};
    var e;
    if(document.evaluate) {
      e = document.evaluate("//frame|//frameset|//iframe|//img|//link", a, null, XPathResult.ANY_TYPE, null);
      for(var g;g = e.iterateNext();) {
        d(g)
      }
    }else {
      g = ["FRAME", "FRAMESET", "IFRAME", "IMG", "LINK"];
      for(var u = 0, k;u < g.length;u++) {
        e = M(document.getElementsByTagName(g[u]));
        for(k = 0;k < e.length;k++) {
          d(e[k])
        }
      }
    }
    c || (b.h || D).apply(a, [c]);
    return a
  }
  function ga(a) {
    a = o(a);
    if(!H(a)) {
      if(a.tagName != "FORM") {
        a = X(a, "form");
        if(!C(a)) {
          return
        }
      }
      var b = ca[L(a)][0];
      if(b) {
        var d = aa(a);
        h.a("form:submit", a, [b, d]);
        if(B(a, "method") == "get") {
          if(b.match("\\?") ? true : false) {
            a = b.split("?", 2);
            b = a[0];
            a = ba(a[1]);
            d = Z(a, d)
          }
          b += "?" + Y(d);
          d = {}
        }
        if(b.substr(0, 19) == "PAI_ContentBoxForm/") {
          b = b.substr(19).split("/");
          var c = b[0];
          h.a("contentbox:beforeunload", o(v[c].ID), [c, v[c], "form"]);
          Q({url:x + l.t + "js/getContentBox.php?PAI_content=" + l.s + "&name=" + c + "&box=" + b[1], data:d, z:function(f) {
            var e = v[c], g = o(e.ID);
            G(g, f.responseText);
            if(e.HideIfEmpty && !f.responseText) {
              g.style.display = "none";
              h.a("contentbox:hide", g, [c, e])
            }else {
              I(g);
              O(g);
              g.style.display = ""
            }
            h.a("contentbox:domloaded", g, [c, e, "form"])
          }})
        }else {
          T.add(b);
          J(b, d)
        }
      }
    }
  }
  function ha(a, b) {
    if(a.substr(0, r.length) == r) {
      a = a.substr(r.length)
    }else {
      if(a.substr(0, x.length) == x) {
        a = a.substr(x.length)
      }
    }
    if(!(E == a && !b)) {
      h.a("go", this, [a, b]);
      T.add(a);
      J(a, b)
    }
  }
  var K = {}, ia;
  function J(a, b) {
    h.a("page:beforeunload", this, [y, E]);
    var d = a.match("\\?") ? true : false, c;
    if(a.match("\\#") ? true : false) {
      c = a.split("#");
      a = c[0];
      c = c[1]
    }
    var f = a;
    if(d) {
      f = a.split("?", 2);
      f = f[0]
    }
    if(f.substr(f.length - 1) == "/") {
      f = f.substr(0, f.length - 1)
    }
    f = f ? f : l.i;
    var e = {HASH:c, PAGE:f, PAGELINK:a};
    h.a("page:requestinfo", p, [e]);
    c = false;
    d = ea + a + (d ? "&" : "?") + "PAI_content=true";
    var g, u, k;
    for(g in v) {
      f = v[g];
      u = f.BindToPages ? e.d : f.pages[e.d] ? f.pages[e.d] : f.Default;
      if(C(k = o(f.ID))) {
        h.a("contentbox:beforeunload", k, [g, f, "page"]);
        f.PeriodicalUpdate && f.AjaxUpdater && f.AjaxUpdater.stop();
        if(!f.Static || typeof f.html[u] === "undefined") {
          d += "&PAI_ContentBoxes[]=" + g;
          c = true
        }
      }
    }
    if(g = S[e.d]) {
      if(g.JSPage) {
        y = e.d;
        E = a;
        h.a("JSPageBefore:" + e.d, p, [e]);
        I(p);
        O(p)
      }else {
        if(l.b && g.l || !l.b && !g.n || !K[a]) {
          c = true
        }
      }
    }else {
      if(!l.b || !K[a]) {
        c = true
      }
    }
    if(b) {
      c = true
    }
    ia = a;
    h.a("page:beforerequest", p, [e, c]);
    if(c) {
      Q({url:d, dataType:"text", data:b, error:function(i, j) {
        var q;
        q += "<p>";
        for(var t in j) {
          q += "<b>" + t + "</b> <pre>" + j[t] + "</pre><br>"
        }
      }, complete:function(i) {
        var j = V(i.responseText);
        if(j) {
          h.a("page:beforeload", p, [j, e, true]);
          if(i = i.getResponseHeader("refresh")) {
            i = i.split(";");
            var q = i[0].q() * 1E3, t = i[1].q();
            t = t.substr(0, 4) == "url=" ? t.substr(4) : this.u;
            window.setTimeout(function() {
              ha(t)
            }, q)
          }
          if(P(j.ContentBoxes)) {
            i = 0;
            q = j.ContentBoxes.length;
            for(var z, A;i < q;i++) {
              z = j.ContentBoxes[i];
              A = v[z.name];
              A.html[z.box] = z.html;
              A.PeriodicalUpdate && A.AjaxUpdater.complete(z.html)
            }
          }
          delete j.ContentBoxes;
          j.content = j.content ? j.content : " ";
          K[e.PAGELINK] = j;
          ja(e)
        }
      }})
    }else {
      h.a("page:noRequest");
      h.a("page:beforeload", p, [K[a], e, false]);
      ja(e)
    }
  }
  function ja(a) {
    if(a.PAGELINK == ia) {
      var b = a.PAGE, d = K[a.PAGELINK], c = S[b];
      y = b;
      E = a.PAGELINK;
      document.title = l.o.replace("%s", c ? c.Title : "Undefined title");
      c && c.JSPage ? h.a("JSPage:" + b, p, [a]) : G(p, d.content);
      I(p);
      O(p, {k:function() {
        h.a("page:loadprocess", this, arguments)
      }, h:function() {
        h.a("page:load", this, arguments)
      }});
      if(c && (l.b && c.l || !l.b && !c.n) || !c && l.b) {
        K[a.PAGELINK] = null
      }
      c = o(a.HASH);
      C(c) && W(c);
      var f, e, g;
      for(f in v) {
        c = v[f];
        e = c.BindToPages ? b : c.pages[b] ? c.pages[b] : c.Default;
        g = o(c.ID);
        if(C(g)) {
          if(c.HideIfEmpty && !c.html[e]) {
            g.style.display = "none";
            h.a("contentbox:hide", g, [f, c])
          }else {
            G(g, c.html[e]);
            I(g);
            O(g, {k:function() {
              h.a("contentbox:loadprocess", this, arguments)
            }, h:function() {
              h.a("contentbox:load", this, arguments)
            }});
            g.style.display = ""
          }
          h.a("contentbox:domloaded", g, [f, c, "page"])
        }
      }
      h.a("page:domloaded", p, [a, d]);
      if(typeof pageTracker == "object" && l.p) {
        pageTracker.v(a.PAGELINK ? r + a.PAGELINK : r)
      }
    }
  }
  var h = {c:{}, f:function(a, b) {
    if(l.e) {
      h.c[a] || (h.c[a] = []);
      h.c[a][h.c[a].length] = b
    }
  }, a:function(a, b, d) {
    if(l.e) {
      var c = h.c[a];
      if(c) {
        a != "action:run" && h.a("action:run", b, [a, d]);
        a = [];
        for(var f = 0, e = c.length;f < e;f++) {
          a[f] = c[f].apply(b, d || [])
        }
        return a
      }
    }
  }, m:function(a, b) {
    if(l.e) {
      var d = h.c[a];
      d && b && d.A(b)
    }
  }}, ka = false;
  function da() {
    if(!(ka || !window.PAIServerVars)) {
      ka = true;
      var a = window.PAIServerVars, b = {}, d = a.LANGUAGE;
      b.i = a.PageIndex;
      b.b = a.StaticPages;
      b.p = a.TrackGoogleAnalytics;
      b.j = a.RequireJS;
      b.g = a.ClickEventName;
      b.o = a.TitleTemplate;
      b.e = a.ACTIONS;
      fa = a.Custom;
      PAI.PATH = x = a.PATH;
      ea = a.AJAXPATH;
      S = a.PageInfo;
      v = a.ContentBoxes;
      r = location.protocol + "//" + location.hostname + x + (d ? d + "/" : "");
      l = b;
      d = x + (d ? d + "/" : "");
      if(location.pathname.length > d.length && location.pathname.substr(0, d.length) == d) {
        if(a.RedirectIfNotIndex) {
          location.href = r + "#" + location.pathname.substr(d.length) + location.search;
          return
        }else {
          E = y = location.pathname.substr(d.length)
        }
      }else {
        y = b.i
      }
      T = new la(J);
      p = o("PAI_content");
      d = location.hash.substr(1);
      if(d.substr(d.length - 1) == "/") {
        d = d.substr(0, d.length - 1)
      }
      d || (d = y);
      if(b.j) {
        J(d)
      }else {
        if(d && y != d) {
          a = a.LoadingText;
          b = h.a("LoadingText", this, [d]);
          if(P(b)) {
            a = b.join("\n")
          }
          G(p, a);
          J(d)
        }else {
          h.a("page:domloaded", this, [[]])
        }
      }
      var c;
      for(c in v) {
        a = v[c];
        b = o(a.ID);
        if(C(b)) {
          h.a("contentbox:domloaded", b, [c, a, "domloaded"]);
          if(a.PeriodicalUpdate) {
            a.r = new na(c)
          }
        }
      }
      I()
    }
  }
  h.f("page:domloaded", function() {
    h.a("update_complete", this, arguments)
  });
  h.f("page:load", function() {
    h.a("update_load", this, arguments)
  });
  if(!window.PAI_notInitialize) {
    w(window, "load", function() {
      da();
      l.j || h.a("page:load", this)
    });
    w(document, F == "prototypejs" ? "dom:loaded" : "ready", function() {
      da()
    })
  }
  m = {};
  m.page = function() {
    return y
  };
  m.pagelink = function() {
    return E
  };
  m.pageInfo = function(a) {
    return S[a ? a : y]
  };
  m.go = ha;
  m.submit = ga;
  m.initialize = da;
  m.checkLinks = I;
  m.checkObjects = O;
  m.AddAction = h.f;
  m.RemoveAction = h.m;
  m.Action = {};
  m.Action.Add = h.f;
  m.CustomVar = function(a) {
    return fa[a]
  };
  window.PAI = m
})();