/*
 * Copyright (c) 2008 WeGotTickets
 * 
 * @Author Clive Calmeyer
 * @Revision $Id: panels.js 6339 2011-12-21 12:18:12Z clive $
 * @Package www
 * 
 */


domReady( function() {
	
	var panels = {
		regions: {
			panel: $('regions'),
			button: $('regionsbutton')
		},
		advsearch: {
			panel: $('advsearch'),
			button: $('advsearchbutton')
		},
		mailinglist: {
			panel: $('mailinglist'),
			button: $('mailinglistbutton')
		}
	}
	
	
	if( window.location.hash && /^#_(regions|advsearch|mailinglist)$/.test( window.location.hash ) ) {
		var current = window.location.hash.substr( 2 );
	} else {
		var current = 'regions';
	}
	
	
	for( var p in panels ) {
		
		if( p == current ) {
			$addClass( 'active', panels[p]['button'] );
			panels[p]['panel'].parentNode.style.height = ( panels[p]['panel'].offsetHeight + 20 )+"px";
		} else {
			panels[p]['panel'].style.display = 'none';
		}
		
		addEvent( panels[p]['button'], 'click', function( e ) {
			e.stopPropagation();
			e.preventDefault();
			this.blur();
			doit.bind( this )();
		});

		addEvent( panels[p]['button'], 'mouseover', function( e ) {
			e.stopPropagation();
			this.timout = setTimeout( doit.bind( this ), 250 );
		});

		addEvent( panels[p]['button'], 'mouseout', function( e ) {
			e.stopPropagation();
			clearTimeout( this.timout );
		});
		
		function doit() {
			for( var p in panels ) {
				if( panels[p]['button'] == this ) {
					$addClass( 'active', this );
					panels[p]['panel'].style.display = 'block';
					window.location = '#_'+panels[p]['panel'].id;
				} else {
					$removeClass( 'active', panels[p]['button'] );
					panels[p]['panel'].style.display = 'none';
				}
				
			}
		};
		
		panels[p]['panel'].style.position = 'absolute';
		panels[p]['panel'].style.zIndex = 100;
		panels[p]['panel'].style.top = 0;
		
	}

});
