// support code for tabbed product descriptions V2.10
var pids = new Array();
var panes = new Array();
var panewidths = new Array();				// Sorted Products Compatibility 
var paneheights = new Array();				// Sorted Products Compatibility 
var bTabberSet = false;

function swaptabs(ulid, seq){
  // make tab active class
  var litems = document.getElementById('ul_' + ulid).getElementsByTagName('li');
  for (var i=0; i<litems.length; i++)
    {
    litems[i].id = (i == seq) ? 'tab-current' : '';
    }
  // hide other panes (siblings)
  // make pane visible
  paneId = 'pane_' + ulid + '_' + seq;
  for (var con in panes) {
  if (panes[con][paneId] != null) { // tab and pane are members of this container
      var pane = document.getElementById(paneId);
      pane.style.display = "block";
      var container = document.getElementById(con);
      for (var i in panes[con]) {
        var pane = panes[con][i];
        if (pane == undefined) continue;
        if (pane.id == paneId) continue;
        if ( pane.style && pane.style.display ) pane.style.display = "none";
      }
    }
  }
  return false;
}

function setupPanes(Id, usePrevious) {
  // go through the DOM, find each tab-container
  // set up the panes array with named panes
  // find the max height, set tab-panes to that height
  // save height and width - use old values if called with usePrevious set
  var containerId = 'cont_' + Id;
  panes[containerId] = new Array();
  var maxHeight = 0; var maxWidth = 0;
  var container = document.getElementById(containerId);
  var paneContainer = container.getElementsByTagName("div")[0];
  var paneList = paneContainer.childNodes;
  for (var i=0; i < paneList.length; i++ ) {
    var pane = paneList[i];
    if (pane.nodeType != 1) continue;
    if (pane.offsetHeight > maxHeight) maxHeight = pane.offsetHeight;
    if (pane.offsetWidth  > maxWidth ) maxWidth  = pane.offsetWidth;
    panes[containerId][pane.id] = pane;
    pane.style.display = "none";
  }
  
  if ( usePrevious )					// Sorted Products - use prior computed values
    {
    maxWidth = panewidths[Id];
    maxHeight = paneheights[Id];
    } 
     
//  paneContainer.style.height = maxHeight + "px";
  paneContainer.style.width  = maxWidth + "px";

  panewidths[Id] = maxWidth;				// Sorted Products Compatibility
  paneheights[Id] = maxHeight;				// Sorted Products Compatibility
  
  // activate first tab
  swaptabs(Id, 0);
}

function setallpanes(){
// called on page load - set up all tab containers
  if ( bTabberSet ) return;		// only do once
  bTabberSet = true;
  for ( var i=0; i<pids.length; i++ )
    {
    setupPanes(pids[i]); 
    }
}

function resetallpanes(){
// called by other add-ons (e.g. Sorter) if page modified 
  for ( var i=0; i<pids.length; i++ )
    {
    setupPanes(pids[i], true); 
    }
}

// in case we cannot activate on DOM loaded
if (window.attachEvent) 						// IE 
	{ 
	window.attachEvent("onload", setallpanes); 
	} 
else 									// DOM
	{  
	window.addEventListener("load", setallpanes, false); 
	}

// DOM Ready detect based on www.kryogenix.org/days/2007/09/26/shortloaded
(function(i) {var u =navigator.userAgent;var e=/*@cc_on!@*/false; var st =
setTimeout;if(/webkit/i.test(u)){st(function(){var dr=document.readyState;
if(dr=="loaded"||dr=="complete"){i()}else{st(arguments.callee,10);}},10);}
else if((/mozilla/i.test(u)&&!/(compati)/.test(u)) || (/opera/i.test(u))){
document.addEventListener("DOMContentLoaded",i,false); } else if(e){     (
function(){var t=document.createElement('doc:rdy');try{t.doScroll('left');
i();t=null;}catch(e){st(arguments.callee,0);}})();}})(setallpanes);
