/*
	Hide / Show Script
	with animation
	by: John Henry Pacay
	September 30, 2008
	
	bug: putting borders wont animate when height is = 0
*/

var hideshowContent = function(){
	var timer, _h;

	return {
				hideshow: function( p ){
					var pcont = document.getElementById( p );
					var pcontd = pcont.style.display;
					
					if( !pcont._h ){
						pcont._h = pcont.offsetHeight;
					}
	
					clearInterval( pcont.timer );
	
					if( pcontd == 'block' ){
						pcont.timer = setInterval( function() { hideshowContent.hideshowAnimate( pcont, false ) }, 30 );
					} else if( pcontd == 'none' ){
						pcont.timer = setInterval( function() { hideshowContent.hideshowAnimate( pcont, true ) }, 30 );
					}
				},
				setHeight: function( id ){
					document.getElementById( id )._h = document.getElementById( id ).offsetHeight;
				},
				hideshowAnimate: function( p, flag ){
					var ph = p.offsetHeight;
					if( flag && p._h > ph ){
						p.style.display = 'block';
						var nh = ph + 20;
						nh = ( nh >= p._h ) ? p._h : nh;
					} else if( !flag && ph > 0 ){
						var nh = ph - 20;
						nh = ( nh <= 0 ) ? 0 : nh;
					} else{
						clearInterval( p.timer );
					}
					if( !flag && ph <= 0 ){
						p.style.display = 'none';
					}
					p.style.height = nh + 'px';
				}
			}
}();
