﻿/// <reference path="~/Scripts/jquery-1.6.4-vsdoc.js" />

//Set up the important webframe namespaces
SetupNamespace("webframe.segments");
SetupNamespace("webframe.segmenttype");

webframe.ui =
{
  BlockUIDisplay: function ()
  {
    $.blockUI(
	  {
	    message: '<h1><img src="/Content/images/busy.gif" /> Just a moment...</h1>'
	  });
  },

  UnblockUIDisplay: function ()
  {
    $.unblockUI();
  },

  WireupTreeList: function (contextSelector)
  {
    function collapseStateImagePath(collapsed)
    {
      var collapsedImgName = 'RightTriSm', uncollapsedImgName = 'DownTriSm';

      return "/content/images/" + (collapsed ? collapsedImgName : uncollapsedImgName) + ".png";
    }

    var listContext = $(contextSelector);
    $('ul li a', listContext).each(function ()
    {
      var this$ = $(this);
      if (this$.hasClass('parent'))
      {
        this$.closest('li').addClass('collapsed');
        this$.before('<a href="#" class="expandCollapse">&nbsp;&nbsp;<img src="' + collapseStateImagePath(true) + '">&nbsp;</a>');
      }
      else
      { this$.before('<span class="noChildren">-</span>'); }
    });

    $('a.expandCollapse', listContext).click(function ()
    {
      var collapseContainer$ = $(this).closest('li');
      var collapsed = collapseContainer$.hasClass('collapsed');
      collapseContainer$.toggleClass('collapsed');
      var stateImagePath = collapseStateImagePath(!collapsed);
      $(this).children('img').attr('src', stateImagePath);

      return false;
    });
  }
};

function SetupNamespace(namespaceString)
{
  var growingNamespace = window;
  var pieces = namespaceString.split(".");
  for (var i = 0; i < pieces.length; i++)
  {
    if (growingNamespace[pieces[i]] == null)
    {
      growingNamespace[pieces[i]] = {};
    }
    growingNamespace = growingNamespace[pieces[i]];
  }
}


