var lights = {
	
	total: 3,
	height: 14,
	width: 14,
	offsetX: 1,
	offsetY: 1,
	rows: 4,
	cols: 65,
	
	init: function() {
		
		for( var i=0; i<15; i++ ) {
		
			this.create();
		
		}
		
	},
	
	create: function() {
		
		var d = 0.5;
		
		//create a light
		var elm = new Element( 'img', { src: 'images/lights/' + this.pick_light() + '.png' } );
		$('header_center').insert( elm );
		elm.setStyle( 'position: absolute; top: ' + this.get_top() + 'px; left: ' + this.get_left() + 'px; opacity: 0;' );
		
		//fade in and out
		new Effect.Opacity( elm, { from: 0, to: 1, duration: d } );
		new Effect.Opacity( elm, { from: 1, to: 0, duration: d, delay: d } );
		
		//destroy and respawn
		( function() {
			if( elm != null ) elm.remove();
			lights.create();
		} ).delay( ( d * 2 ) );
		
	},
	
	get_top: function() {
	
		//return 57;
		return ( Math.floor( Math.random() * this.rows ) * this.height ) + this.offsetY;
	
	},
	
	get_left: function() {
	
		//return 247;
		return ( Math.floor( Math.random() * this.cols ) * this.width ) + this.offsetX;
	
	},
	
	pick_light: function() {
	
		//return 1;
		return Math.floor( Math.random() * this.total );
	
	},
	
	animate: function() {
		
	}
	
}


//align mixology menu id needed
if( $('mixology_submenu') ) {

	function alignsubmenu() {
			
		var l1 = $$('#menu a')[1].cumulativeOffset().left;
		var l2 = $('page').cumulativeOffset().left;
		$('mixology_submenu').setStyle( 'left: ' + (  ( l1 - l2 ) ) + 'px' );
	
	}

	Event.observe( window, 'load', alignsubmenu );
	Event.observe( window, 'resize', alignsubmenu );

}

Event.observe( window, 'load', lights.init.bind(lights) );

