var TFTgo = {

  onReady: function() {
    //init loadings
    TFTgo.initBuild();

  },
  
  initBuild: function() {
  
    var opts = '';

    TFTgo.createSelect({
      elId        : "testisselect",
      label       : "Select a Manufacturer",
      resultsElId : "mfrsdivresults",
      targetElId  : "mfrsdiv",
      dataSource  : mfers
    });

    opts = TFTgo.buildElements(mfers, 'option', '#testisselect');
    $('#testisselect').append($(opts));


    TFTgo.createSelect({
      elId        : "svcsselect",
      label       : "Select a Product",
      resultsElId : "svcsdivresults",
      targetElId  : "svcsdiv",
      dataSource  : svcs
    });
    
    opts = TFTgo.buildElements(svcs, 'option', '#svcsselect');
    $('#svcsselect').append($(opts));

  },

  /**
   *
   * @method buildElements
   * @description a factory method of sorts that takes a data
   *              object and returns a set of DOM-ready option
   *              list of [tag] elements
   *
   * @param data  : the data source used to build the list of [tag]s
   * @param tag   : the type of HTML element list to build
   *
   */
  buildElements: function(data, tag, targetSelector) {
    var elements = '';
    for (var key in data) {
      if (data.hasOwnProperty(key)) {
        elements += '<'+ tag + '>' + key+ '</' + tag + '>';
      }
    }
    return elements;
  },
  
  
  /**
   *
   * @method createSelect
   * @description a factory method of sorts that takes a data
   *              object and returns a DOM-ready select menu void
   *              of options (with one exception)
   *
   * @param data configuration settings
   *  elId        : the id of the select menu being created
   *  label       : the default (first) element in the select menu
   *  resultsElId : target element to append this DOM element
   *  targetElId  : target element to display the result set
   *
   */
  createSelect: function(data) {

    $("<select/>", {
      id: data.elId,
      html: $("<option/>", {html: data.label}),
      change: function () {
        $("#" + data.resultsElId).empty().slideUp("fast");
        var thisvalue = $(this).val();
        var curvals = data.dataSource[thisvalue];
        for (var keyd in curvals) {
          $("#" + data.resultsElId).append($("<p/>", {html: curvals[keyd]}));
        }
        setTimeout(function() {$("#" + data.resultsElId).slideDown("slow");}, 200);
      }
    }).appendTo("#" + data.targetElId);
  }

}

jQuery(document).ready(TFTgo.onReady);

// the following space is intentionally not left unblank ~ shawngo


