

// ====================================================== tab_collection()

function tab_collection()
{
  this.tabs = [];
  this.add_tab = function(tabObject){this.tabs[this.tabs.length] = tabObject;};
};


// ====================================================== tab()

function tab(tab_name, tab_HTML, tab_width)
{
  this.tab_name  = tab_name.toLowerCase();
  this.tab_HTML  = tab_HTML;
  this.tab_width = tab_width;
  this.URL       = "http://www.intel.com";
  this.gen_HTML  = gen_HTML;
};

// --------------------------------------------- gen_HTML

function gen_HTML(state)
{
  var imageState = "";
  
  if (state.toLowerCase() == "on") {
  	imageState = "_on"
  } else {
    imageState = "_off";
  }

  var return_HTML = this.tab_HTML;

  // replace out variables
  return_HTML = return_HTML.replace( "%__URL__%"   ,this.URL   );
  return_HTML = return_HTML.replace( "%__STATE__%" ,imageState );
  
  return return_HTML;
};


// ====================================================== tab_line()

function tab_line(graphic_width)
{
  var return_HTML = tab_line_HTML;

  return_HTML = return_HTML.replace("%__WIDTH__%", graphic_width);

  return return_HTML;
};


// ====================================================== product_matrix()

function product_matrix()
{
  window.mtrx = this;
  this.hub = [];
  this.add_product_hub = add_product_hub;

  this.tab_collection = null;
  this.use_tab_collection = function(collection)
    {
      this.tab_collection = collection

      for(i=0; i < collection.tabs.length; i++)
	{
	  // add prototype properties to product_hub objects
	  product_hub.prototype[collection.tabs[i].tab_name] = null;
	};
    }; 
  
  this.create_tabs = create_tabs;
};

// --------------------------------------------- add_product_hub

function add_product_hub(hubID, description)
{
  this.hub[hubID] = new product_hub(hubID, description);
};


// ====================================================== product_hub()
// prototype properties added to product_hub by
// product_matrix.tab_collection()

function product_hub(hubID, description)
{
  this.ID = hubID;
  this.description = description;
  
  // always On - hack to force tab(s) to overstate
  this.alwaysOnArray = [];
  this.alwaysOn = function(tabName)
  	{
		this.alwaysOnArray[this.alwaysOnArray.length] = tabName;
	};
  this.checkAlwaysOn = function(tabName)
  	{
		for(var i=0; i < this.alwaysOnArray.length; i++)
		{
			if(this.alwaysOnArray[i] == tabName){return true;}
		};
		return false;
	};	
  
};



// ====================================================== create_tabs()

function create_tabs(hubID)
{
  if(hubID == "generic"){hubID = findInQueryString("prod")};
  if(this.hub[hubID] == null){hubID = "0000";};

  var final_line_length = tab_table_width;
  var locationPath      = location.href.toLowerCase(); 
  var nav_HTML          = new String();
  
  nav_HTML += tab_table_start;

  // write first line
  nav_HTML += tab_line( first_tab_line_length );
  final_line_length -= first_tab_line_length;
  
  for(i=0; i < this.tab_collection.tabs.length; i++)
    {
      if(this.hub[hubID][this.tab_collection.tabs[i].tab_name] != null)
	{
	  var loopingTab = this.tab_collection.tabs[i];
	  var tabState = "off";
	  
	  // update tab URL property
	  loopingTab.URL = this.hub[hubID][loopingTab.tab_name];
	  
	   // create over states
	  if(locationPath.indexOf(loopingTab.URL.toLowerCase()) != -1){ tabState = "on"; };
	  
	  if(this.hub[hubID].checkAlwaysOn(loopingTab.tab_name)){ tabState = "on"; };
	  
	  // get tab HTML
	  nav_HTML += loopingTab.gen_HTML( tabState );
	  final_line_length -= loopingTab.tab_width;
	  
	  // add lines between tabs
	  nav_HTML += tab_line( tab_line_length_between_buttons );
	  final_line_length -= tab_line_length_between_buttons;
	};
    };
  
  // write last line
  nav_HTML += tab_line( final_line_length );
  
  nav_HTML += tab_table_end;
  
  return nav_HTML;
};


// ====================================================== findInQueryString()

function findInQueryString(propName)
{
  var queryStr = location.search;
  
  var prop_start = queryStr.indexOf(propName);  
  if(prop_start == -1){ return false; };
  prop_start += propName.length + 1; // 1 for "="
  
  var prop_end = queryStr.indexOf("&", prop_start);
  if(prop_end == -1){prop_end = queryStr.length;};
  
  var propValue = queryStr.slice(prop_start, prop_end);
  return propValue; 
};


// ====================================================== multiMatrix()

function multiMatrix()
{
  var matrices = new Object();
  
  this.addMatrix = function(matrixName, matrixURL)
    {
      matrices[matrixName] = matrixURL; 
    };

  this.findMatrixURL = function(matrixName){
    for(matrix in matrices)
      {
	if(matrix == matrixName){return matrices[matrixName];};
      };
    return matrices["default"];
  };
  
  this.getMatrix = function()
    {
      matrixName = findInQueryString("matrix");
      matrixURL = this.findMatrixURL( matrixName );
      document.write("<script type=\"text/javascript\" src=\"" + matrixURL + "\"><\/script>");
    };
};
