﻿// Footer assoluto - v. 04/12/2009 #1





/*** Configurazione */

// Gli id delle colonne sopra il footer
var _cols = new Array( "colonna1", "colonna2" );
//var _cols = new Array( "colonna1", "colonna2", "corpo-colonna3" );





/*** Main */

// Attiva la procedura
_addEventListener_( window, "load", _initAbsFooter_ );





/*** Funzioni */

// document.getElementById( id ) cross-browser
function _getElementById_( _id ) {
 if( document.getElementById ) {
  if( document.getElementById( _id ) )
   return document.getElementById( _id );
 }
 else if( document.all ) {
  if( document.all[_id] )
   return document.all[_id];
 }
 else
  return null;
}

// elem.setAttribute( type, val ) cross-browser
function _setAttribute_( _elemid, _attr ) {
 if( document.all && ( ! window.opera ) )
  _getElementById_( _elemid ).style.setAttribute( "cssText", _attr );
 else
  _getElementById_( _elemid ).setAttribute( "style", _attr );

 return;
}

// elem.getAttribute( attr ) cross-browser
function _getAttribute_( _elemid, _attr ) {
 try {
  return eval( "document.all[_elemid]." + _attr );
 }
 catch( _e ) {
  return eval( "_getElementById_( _elemid )." + _attr );
 }
}

// elem.addEventListener( event, listener, false ) cross-browser
function _addEventListener_( _elem, _event, _listener ) {
 if( _elem.addEventListener )
  _elem.addEventListener( _event, _listener, false ); 
 else if( _elem.attachEvent )
  _elem.attachEvent( "on" + _event, _listener );
 else
  eval( "_elem.on" + _event + " = _listener;" );

 return;
}

// Riposiziona il footer
function _absFooter_() {

 // Trova il valore dell'altezza maggiore tra tutte le colonne
 for( _max = 0, _count = 0; _count < _cols.length; _count++ ) {
  _setAttribute_( _cols[_count], "min-height: 0px; height: auto !important; height: 0px;" );
  _max = Math.max( _max, _getAttribute_( _cols[_count], "offsetHeight" ) );
 }

 // Imposta l'altezza maggiore su tutte le colonne
 for( _count = 0; _count < _cols.length; _count++ )
  _setAttribute_( _cols[_count], "min-height: " + _max + "px; height: auto !important; height: " + _max + "px;" );

 return;
}

// Inizializzazione dello script
function _initAbsFooter_() {

 // Gestisce il ridimensionamento della finestra
 _addEventListener_( window, "resize", _absFooter_ );

 // Prima esecuzione
 _absFooter_();

 return;
}

