// Calling page must have paramsDiv & libraryDiv objects for these functions
// show and manipulate

function plugin_main()
{
   // Hide the library div
   HideAllLibraryDivs();
   write_params(paramsDiv);
   //main_tools.style.display="none";
   globalStore.OnCreateGem = OnCreateGem;
   globalStore.ActiveGem = new Gem();
   globalStore.ActiveGem.TargetDiv = gemsDiv;
   globalStore.ActiveGem.CallingDiv = paramsDiv;
   globalStore.ActiveGem.CallbackFunction = GemCallback;
   //globalStore.ActiveGem.ParentDiv = main_tools;
   globalStore.ActiveGem.WriteShapeSelectionHTML();

}

function write_params(targetDiv)
{
   targetDiv.innerHTML = "";
   var hArr = new Array();
   hArr.push("<table width='100%' border=0 cellspacing=0 style='margin-left:3px'>");
   hArr.push("<col width=40px><col width=30%><col width=70%>");
   hArr.push("<tr><td align=left><img src='ProjectAssistant/NewGem/NewGem.png'></td><td colspan=2><b>" + gPluginName + "</b></td></tr>");
   hArr.push("<tr><td></td><td>"+ gNameEdit + ":</td><td align=right><input type=edit id=GemNameEdit></td></tr>");
   hArr.push("</table>");

   // Add the back button HTML to the array
   hArr.push("<div class='mouseOut' button_name='forward_button' id=ForwardButton targetFunction='globalStore.OnCreateGem' style='width=30px;float:right;'>");
   hArr.push("<img id=back_img src ='" + artcam.HtmlRootDir + "../SharedImages/forward.gif' align=absmiddle border=0 width=30 height=30>");
   hArr.push("</div>");
   // Bung all our HTML into the div and display it
   targetDiv.innerHTML += hArr.join("\n");

   globalStore.GemNameEdit = eval(GemNameEdit);
   globalStore.GemNameEdit.value = artcam.SelectedAssembly.Name + gGem;
   InitialiseButtonDivs();
   SubclassNumberEditControls();
}

function OnCreateGem()
{
   globalStore.ActiveGem.Name = globalStore.GemNameEdit.value;
   globalStore.ActiveGem.CreateModel();
   artcam.SelectedAssembly.AppendGemSet(globalStore.ActiveGem.GemModel);
   globalStore.ActiveGem.GemModel.InDisplayList=false;
   artcam.ProjectAssembly.UpdateAssemblyMonitor();
   OnClose();
}

function GemCallback(completed)
{
   if(!completed)
   {
      OnBackButton();
      return;
   }
   globalStore.GemNameEdit.value = artcam.SelectedAssembly.Name + globalStore.ActiveGem.Shape + gGem;
}