dojo.provide("parus.embeddedContent");

dojo.require("dojo.window");

dojo.require("dijit.Dialog");
dojo.require("dijit.form.Button");
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.TabContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.Menu");

dojo.require("parus.parus8");
dojo.require("parus.dialog");
dojo.require("parus.database");
dojo.require("parus.dictEdit");
dojo.require("parus.xml");


if (!parus) parus = {};

if (!parus.embeddedContent) dojo.mixin(parus, {
  embeddedContent: {}
});

dojo.mixin(parus.embeddedContent, {

  startup: function() {

    var params = mill.session.values["params"];
    params = parus.parus8.hexDecodeParams(params);
    var contentID = params[0];
    var title = params[1];
    var result = params[2];
    var url = params[3] || "";
    var content = contentID ? mill.session.values[contentID] : "";

    var contentPane;

    var borderContainer = new dijit.layout.BorderContainer({
      design: "headline",
      gutters: false,
      "class": "balanceTemplateContentPane" + (result == "0" ? " balanceModifiedHeader" : ""),
      style: "height:100%;width:100%;padding:0;opacity:0;filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"
    }, dojo.place("<div></div>", dojo.body(), "last"));

    var headingContentPane = parus.balance._createHeadingPane(title);

    borderContainer.addChild(headingContentPane);

    var templateGridPane = new dijit.layout.ContentPane({
      region: "center",
      content: content,
      href: url,
      "class": "balanceTemplateContentPaneContent",
      onLoad: function() {
        dojo.fadeIn({
          node: templateGridPane.domNode
        }).play();

      },
      onShow: function() {
        loadingDiv.style.display = "none";
        dojo.fadeIn({
          node: borderContainer.domNode,
          duration: 300
        }).play();

        if (result == "0") {
          parus.embeddedMode.changeTabState(true);
        }

        if (!url) {
          dojo.fadeIn({
            node: templateGridPane.domNode
          }).play();
        }


        if (contentID) mill.session.setValue(contentID, "", true);

      }

    });

    borderContainer.addChild(templateGridPane);
    borderContainer.startup();

  }

});