var ghei_pbmenutimeout = null

function prepareMenu() {
	if($$('ul.header-nav')[0]!= null){
		 $$('ul.header-nav')[0].childElements().each(
		 	function (s){
				s.observe('mouseover',function (){
					this.addClassName("selected");
			 		this.childElements().each(function(s){
						if(s.nodeName == 'DIV')
							s.appear({duration:.2});
					})
				}).observe('mouseout',function(){
					this.removeClassName('selected')
					clearTimeout(ghei_pbmenutimeout)
					ghei_pbmenutimeout = setTimeout(
						function temp(ele){
							ele.childElements().each(function(s){
								if(s.nodeName == 'DIV'){
									if(!s.hasClassName('test')){
										s.removeClassName("test")
										s.fade({duration:.2});
									}
									else
										ele.addClassName("selected");
								}
								return;
							})
						},300,this)
				})
		 })
		$$('ul.header-nav div.second-level').each(function (x){
			x.observe('mouseover', function(){
				this.addClassName("test")
			}).observe('mouseout', function(){
				this.removeClassName("test")
			})
		});
		 $$('ul.header-nav ul.level-2').each(function (x){
			x.childElements().each(
			function (s){
				s.observe('mouseover',function (){
					this.childElements()[0].style.color = 'red'
					
				}).observe('mouseout',function(){
					this.childElements()[0].style.color = 'white'
				})
		 	}
		)})
	}
}


function runNewsEffect(num) {
 next = num >= $$('.news > div > div').length ? 1 : (num + 1);
 new Effect.Fade($$('.news > div > div:nth-child(' + num + ')')[0], {duration:1});
 setTimeout("new Effect.Appear($$('.news > div > div:nth-child(' + next + ')')[0], {duration:1});", 1000); 
 setTimeout('runNewsEffect(' + next + ')', 4000);
 } 
 

/*function runWallsEffect(numWall) {
 clearTimeout(wallsTimeout)
 
 nextWall = numWall >= $$('.wall > li').length-1 ? 0 : (numWall + 1);
 
 new Effect.Appear($$('.wall > li')[nextWall], {duration:1});
 new Effect.Fade($$('.wall > li')[numWall], {duration:1});
 
 $$('li.thumb')[numWall].removeClassName('current');
 $$('li.thumb')[nextWall].addClassName('current');
 
 wallsTimeout = setTimeout('runWallsEffect(' + nextWall + ')', 4000);
 } 
*/

function runWallsEffect(numWall) {
 clearTimeout(wallsTimeout)
 
 nextWall = numWall >= $$('.wall > li').length-1 ? 0 : (numWall + 1);
 
 new Effect.Appear($$('.wall > li')[nextWall], {duration:1});
 new Effect.Fade($$('.wall > li')[numWall], {duration:1});
 
 $$('li.thumb')[numWall].removeClassName('current');
 $$('li.thumb')[nextWall].addClassName('current');
 
 wallsTimeout = setTimeout('runWallsEffect(' + nextWall + ')', 4000);
 } 


Event.observe(window,"load",function() {
  prepareMenu();
  if ($$('.gallery')[0]!=null){
    clickMenu($$('.gallery')[0])
  }
  if($$('.news')[0] != null && $$('.news').size() > 1){
   $$('.news > div > div').each(function(s){s.style.display = 'none';});
   $$('.news > div > div:first-child').each(function(s){s.style.display = 'block';});
   runNewsEffect(1); 
  }
  if($$('.wall')[0] != null){
   $$('.wall > li').each(function(s){s.style.display = 'none';});
   wallsTimeout = 0;
   i=0;
   $$('.wall > li').each(function(){i++});
   //alert(i);
   runWallsEffect(i-1); 
   //runWallsEffect(0);
  }
});


