window.addEvent( 'domready', function(){
	
	
	$$('#menu > li > a').each( function( item, index){
		var elem = new Element('img',{ 'src' : '/img/nav_' + item.get('rel') + '.png', 'alt' : item.get('rel')  });
		item.empty();
		item.adopt( elem );
		elem.getParent().addEvent('mouseover', function(){ 			
			elem.src = elem.src.replace( '.png', '_active.png' );
			
		});
		
		elem.getParent().addEvent('mouseout', function(){ 
			elem.src = elem.src.replace( '_active', '' );
		});
		
		elem.getParent('li').getChildren('ul').addEvent('mouseover', function(){ 			
			elem.src = elem.src.replace( '.png', '_active.png' );
		});
		elem.getParent('li').getChildren('ul').addEvent('mouseout', function(){ 			
			elem.src = elem.src.replace( '_active', '' );
		});
	});
	
	var gigPeriodId = 0;
	var gigMargin = 0;
	var gigScrollAmount = 44;//52;
	var maxGigScroll = 0;
	var publicGigs = $$('.gig');
	var activeGigIndex = 0;
	maxGigScroll = -1 * ( publicGigs.length -1 )*gigScrollAmount;
	
	/*
	var scrollGigs = function(){
		gigMargin -= gigScrollAmount;
		if( gigMargin < maxGigScroll )
		{
			gigMargin = 0;
			activeGigIndex = 0;
		}
		else
			activeGigIndex++;
		$('gigs').tween( 'margin-top', gigMargin + 'px' );
		console.log( activeGigIndex );
		
	}*/
	
	var scrollToGig = function()
	{
		//console.log('->scrollToGig()');
		if( ++activeGigIndex > publicGigs.length-1 )
			activeGigIndex = 0;
		//console.log( activeGigIndex );
		var toScroll = gigScrollAmount * (activeGigIndex) * -1;
		$('gigs').tween( 'margin-top', toScroll + 'px' );
	}
		

	gigPeriodId = scrollToGig.periodical(2000);
	
	publicGigs.each( function( item, index ){
		item.addEvent( 'mouseover', function(){
		  
			if( activeGigIndex == index )
			{
				//console.log( 'mouseenter::activeGigIndex: ' + activeGigIndex  + ' - index: ' + index);
				showGig( item );
				
			}
			else
			{
				//scrollGigs(  );
				//showGig(item);
			}
		});
		item.addEvent( 'mouseout', function(){
		//alert( index );	
		 
			if( activeGigIndex == index )
			{
				//console.log( 'mouseout::activeGigIndex: ' + activeGigIndex  + ' - index: ' + index);
				var myChain = new Chain;
				myChain.chain(
					$('gigWrapper').tween('height', '44px'),
					item.tween('height', '32px'),
					item.setStyle('background', 'black'),
					item.setStyle('border-left', '1px solid black'),
					item.setStyle('border-right', '1px solid black'),
					resetScrolling(),
					gigPeriodId = scrollToGig.periodical(2000)
				);
			}
			
		});
		
	});
	
	function resetScrolling()
	{
		$$('.gig').each( function( item, index){ item.setStyle('height', '32px'); });
		//activeGigIndex = 99999;
		//scrollToGig();
	}
	
	function stopScroll()
	{
		//console.log('->stopScroll()');
		/*gigPeriodId = */$clear(gigPeriodId);
		gigPeriodId = 0;
		var toScroll = gigScrollAmount * (activeGigIndex) * -1;
		$('gigs').tween( 'margin-top', toScroll + 'px' );

	}
	function showGig( item )
	{
		//console.log('->showGig()');
		/*gigPeriodId = */$clear(gigPeriodId);
		gigPeriodId = 0;
		$('gigs').get('tween').cancel();
		$$('.gig').each( function( item, index){ item.get('tween').cancel(); });
		stopScroll();
		item.setStyle('background', 'black');
		$('gigWrapper').tween('height', '145px');
		item.tween('height', '130px');
		item.setStyle('border-left', '1px solid #363636');
		item.setStyle('border-right', '1px solid #363636');
		item.setStyle('border-bottom', '1px solid #363636');
	}
/*
	$('publicGigs').addEvent('mouseenter', function(){
		stopScroll();
	});
	
	$('publicGigs').addEvent('mouseout', function(){
		periodId = scrollGigs.periodical(2000);
	});*/

	
	function startGallery() {
		var myGallery = new gallery($('img_box_big'), {
		timed: true,
		showArrows: false,
		showInfopane: false,
		showCarousel: false,
		embedLinks: false,
		delay: 5000,
		fadeDuration: 2000
		});									
	} 
	try{
		startGallery();
	}
	catch( e ) {}
	try{
		$('gigsTransparent').fade(0.7);
		$('gigsTransparent').addEvent( 'mouseover', function(){
			$('gigsTransparent').fade(1);
		});
		$('gigsTransparent').addEvent( 'mouseout', function(){
			$('gigsTransparent').fade(0.7);
		});
		
		$('gigOverview').addEvent( 'mouseover', function(){
			$('gigsTransparent').fade(1);
		});
		$('gigOverview').addEvent( 'mouseout', function(){
			$('gigsTransparent').fade(0.7);
		});
	}
	catch( e ){}	
	try{
		$('fadingIngredients').fade(0.7);
		$('mask3').addEvent( 'mouseover', function(){
			$('fadingIngredients').fade(0.9);
		});
		$('mask3').addEvent( 'mouseout', function(){
			$('fadingIngredients').fade(0.7);
		});
	}
	catch( e ){}	


			
});