var cPREFIX, cCLS_ACCORDION, cACCORDION_TRANSITION_DELAY= 3,
  cACCORDION_TRANSITION_DELTA= 0.05, cACCORDION_TRANSITION_RADIX= 10, 
  cNUMERIC_PRECISION= 6, timerAccordion;

function lin2log( p ) { return (Math.pow(cACCORDION_TRANSITION_RADIX, p)-1)/(cACCORDION_TRANSITION_RADIX-1); }

function accordionTransition( pRatio, pOld, pOldW, pNew, pNewW ) {
  pOld.style.width= (((1-lin2log(pRatio))*pOldW).toFixed(cNUMERIC_PRECISION))+'px';
  pNew.style.width= ((lin2log(pRatio)*pNewW).toFixed(cNUMERIC_PRECISION))+'px';
  timerAccordion= ( pRatio>= 1?false:setTimeout(function() { 
      accordionTransition(pRatio+cACCORDION_TRANSITION_DELTA, pOld, pOldW, pNew, pNewW);
    }, cACCORDION_TRANSITION_DELAY) );
}

function accordion( pID ) { 
  var a= [], aBody= [], bodyID, e= cCLS_ACCORDION+'_'+'home', i, 
    isActive= false, j= -1, n= 0, selectedBodyID;  
  with ( document ) { 
    if ( !timerAccordion && getElementById(e) && pID
      && (pID.length> 0) ) {
      a= getElementById(e).getElementsByTagName('*'); 
      for ( i= 0; i< a.length; i++ ) {
        if ( (' '+a[i].className+' ').indexOf(' '+cCLS_ACCORDION+'_tab ')> -1 ) {
          bodyID= a[i].id.replace('_tab', '_body');
          if ( getElementById(bodyID) ) { aBody[n]= getElementById(bodyID);
            isActive= a[i].id== pID;
            if ( isActive ) $('#'+a[i].id).unbind('click');
            else $('#'+a[i].id).bind('click', function( e ) { 
              accordion($(e.target).closest('.'+cCLS_ACCORDION+'_tab').attr('id')); });
            a[i].className= cCLS_ACCORDION+'_tab '+( isActive?cPREFIX+'_active':'');
            j= ( !(aBody[n].style.width in {'0px':1, '':1})?n:j ); n++;
          }
        }
      }
      j= ( j== -1?n-1:j ); selectedBodyID= pID.replace('_tab', '_body');
      newWidth= getElementById(selectedBodyID).scrollWidth;
      if ( newWidth== 1 ) newWidth= 560;
      accordionTransition(0, aBody[j], aBody[j].scrollWidth, 
        getElementById(selectedBodyID), newWidth);
    }
  }  
}

/******************************************************************************
* 20100622 psbrogna create DOM TARGET attributes based on document REL        *
*                   attributes                                                *
* ref: http://articles.sitepoint.com/article/standards-compliant-world        *
******************************************************************************/
function postProcessLinks() { var a, i;
  if ( document.getElementsByTagName ) {
    a= document.getElementsByTagName('a');
    for ( i= 0; i< a.length; i++ )
      with ( a[i] )
        if ( getAttribute('href') && getAttribute('rel') 
          && (getAttribute('rel')== 'external') ) 
          setAttribute('target', '_blank'); 
  }
}

function dom_transformations() { postProcessLinks(); 
  accordion(cCLS_ACCORDION+'_home_6_tab'); }

function myOnload() { 
  cPREFIX= document.forms[0].PREFIX.value; 
  cCLS_ACCORDION= cPREFIX+'_accordion';
  dom_transformations();
}

$(document).ready(function(){ myOnload(); });

