/**
 * 	Little Toggler... useful for accordion blocks..
 */	
	
var iToggle = Class.create();

iToggle.prototype = {
	
	initialize : function ( oCurrent, sCookieID, bNoCloseAll, bAutoCollapse ) {
		
		this.init_cookies();
		this.sCookieID		= sCookieID		|| '';
		this.oCurrent		= oCurrent  	|| '';
		this.bNoCloseAll	= bNoCloseAll 	|| 0;
		this.bAutoCollapse	= bAutoCollapse	|| 0;
		
		if ( this.bAutoCollapse ){
			this.collapse_all();
		}
		
		
		if ( oCurrent ) {
			//alert('startup flick : ' + this.oCurrent + ' -> ' + oCurrent );
			//this.flick(oCurrent);
			this.cookie_store(oCurrent);
		} else if ( this.cookie && this.sCookieID ) {
			if ( sCookie = this.cookie.read( 'tog_' + this.sCookieID ) ){
				//alert('cookie flick : ' + this.oCurrent + ' -> ' + sCookie );
				this.flick( sCookie );
			}
		}
	},
	
	flick : function ( sNewId ){
		//alert('flick ' + this.oCurrent + ' -> ' + sNewId );
		if ( $( 'tog_content_' + sNewId ) ) {
			if ( this.oCurrent == sNewId ) {
				if ( this.bNoCloseAll ) {
					if ( this.sPrevious ) {
						sNewId = this.sPrevious;
					} else {
						sNewId = this.oCurrent;
					}
				} else {
					sNewId = '';
				}
			}
			// Store for posterity.. 
			this.sPrevious = this.oCurrent;
			// .. openeing
			( this.oNewContent 	= $( 'tog_content_' + sNewId ) ) && ( this.oNewContent.toggle() );
			( this.oNewIcon		= $( 'tog_icon_' 	+ sNewId ) ) && ( this.oNewIcon.innerHTML = '&#9660;' );
			( this.oNewBlock	= $( 'tog_block_' 	+ sNewId ) ) && ( this.oNewBlock.className = 'toggle-open' );
			( this.oNewTab		= $( 'tog_tab_' 	+ sNewId ) ) && ( this.oNewTab.addClassName('toggle-tab-hi') );
			// .. closing
			( this.oOldContent 	= $( 'tog_content_' + this.oCurrent ) ) && ( this.oOldContent.toggle() );
			//( this.oOldContent 	= $( 'tog_content_' + this.oCurrent ) ) && ( this.oOldContent.toggle() );
			( this.oOldIcon		= $( 'tog_icon_' 	+ this.oCurrent ) ) && ( this.oOldIcon.innerHTML = '&#9658;' );
			( this.oOldBlock	= $( 'tog_block_' 	+ this.oCurrent ) ) && ( this.oOldBlock.className = 'toggle-closed' );
			( this.oOldTab		= $( 'tog_tab_' 	+ this.oCurrent ) ) && ( this.oOldTab.removeClassName('toggle-tab-hi') );
			// till next time.. 
			this.oCurrent 	= sNewId;
			//
			this.cookie_store( sNewId );
		}
	},
	
	cookie_store : function( sId ){
		if ( this.cookie && this.sCookieID ) {
			this.cookie.write( 'tog_' + this.sCookieID, sId, '+1M', '/' );
			//alert('Cookie :: ' + sId );
		}
	},
	
	init_cookies : function (){
		if ( HTTP && HTTP.Cookies ){
			this.cookie = new HTTP.Cookies;
		}
	},
	
	collapse_all : function (){
		if ( closedBlocks = $$('.toggle-closed') ) {
			closedBlocks.each(function (name,index){
				name.down('.toggle-content').hide();
			});
		}
	}
	
}