window.addEvent('domready', function(){

//novinky
  
  var el_view = $('news_all');
  var news_id = { counter: 1 };
  var newsky_cykl;
  var el_ids = new Array(6);
  
  el_ids[1] = $('news_1');
  el_ids[2] = $('news_2').set('opacity', 0.6);
  el_ids[3] = $('news_3').set('opacity', 0.6);
  el_ids[4] = $('news_4').set('opacity', 0.6);
  el_ids[5] = $('news_5').set('opacity', 0.6);
  
  var news_zobraz = function()
  { 
    el_view.fade(1);
  };
  
  var req = new Request.HTML({url:'show_news.php', 
		onSuccess: function(html) {
			$('news_all').set('text', '');
			$('news_all').adopt(html);
		},
		onFailure: function() {
			$('news_all').set('text', 'Chyba při načítání dat.');
		}
	});
	
	var write_news = function()
	{
	  req.send({url: this});
  }
  
  var newsky = function()
  {
    this.counter++;
    
    if(this.counter > 5)
    {
      this.counter = 1;
    }
    
    el_ids[1].fade(0.6);
    el_ids[2].fade(0.6);
    el_ids[3].fade(0.6);
    el_ids[4].fade(0.6);
    el_ids[5].fade(0.6);
    
    el_view.fade(0);
    write_news.delay(500, 'show_news.php?id=' + this.counter);
    el_ids[this.counter].fade(1);
    news_zobraz.delay(1400);
  };
  
  newsky_cykl = newsky.periodical(7000, news_id);
  
  function change_news(n_id)
  {
    if(n_id != news_id.counter)
    {
      if(newsky_cykl != 0)
      {
        newsky_cykl = $clear(newsky_cykl);
      }
      
      el_ids[1].fade(0.6);
      el_ids[2].fade(0.6);
      el_ids[3].fade(0.6);
      el_ids[4].fade(0.6);
      el_ids[5].fade(0.6);
      
      newsky_cykl = n_id;
      el_view.fade(0);
      news_id.counter = n_id;
      write_news.delay(500, 'show_news.php?id=' + n_id);
      el_ids[n_id].fade(1);
      news_zobraz.delay(1400);
      newsky_cykl = newsky.periodical(7000, news_id);
    }
  }
  
  $('news_1').addEvent('click', function(e) {
    change_news(1);
	});
	
	$('news_2').addEvent('click', function(e) {
    change_news(2);
	});
	
	$('news_3').addEvent('click', function(e) {
    change_news(3);
	});
	
	$('news_4').addEvent('click', function(e) {
    change_news(4);
	});
	
	$('news_5').addEvent('click', function(e) {
    change_news(5);
	});
  
//hlavní menu

  $('menu_items_1').addEvents({
  		'mouseenter': function(){
  			this.set('tween', {
  				duration: 700,
  				transition: Fx.Transitions.Cubic.easeOut
  			}).tween('height', '235px');
  		},
  		'mouseleave': function(){
  			this.set('tween', {}).tween('height', '40px');
  		}
	});
	
	$('menu_items_2').addEvents({
  		'mouseenter': function(){
  			this.set('tween', {
  				duration: 500,
  				transition: Fx.Transitions.Cubic.easeOut
  			}).tween('height', '160px');
  		},
  		'mouseleave': function(){
  			this.set('tween', {}).tween('height', '40px');
  		}
	});
	
	$('menu_items_3').addEvents({
  		'mouseenter': function(){
  			this.set('tween', {
  				duration: 600,
  				transition: Fx.Transitions.Cubic.easeOut
  			}).tween('height', '160px');
  		},
  		'mouseleave': function(){
  			this.set('tween', {}).tween('height', '40px');
  		}
	});
	
	$('menu_items_4').addEvents({
  		'mouseenter': function(){
  			this.set('tween', {
  				duration: 500,
  				transition: Fx.Transitions.Cubic.easeOut
  			}).tween('height', '135px');
  		},
  		'mouseleave': function(){
  			this.set('tween', {}).tween('height', '40px');
  		}
	});

// sekce

  $('section_menu_1').addEvents({
  		'mouseenter': function(){
  			$('sec_items_1').set('tween', {
  				duration: 500,
  				transition: Fx.Transitions.Cubic.easeOut
  			}).tween('height', '188px');
  		},
  		'mouseleave': function(){
  			$('sec_items_1').set('tween', {}).tween('height', '0px');
  		}
	});
	
	$('section_menu_2').addEvents({
  		'mouseenter': function(){
  			$('sec_items_2').set('tween', {
  				duration: 700,
  				transition: Fx.Transitions.Cubic.easeOut
  			}).tween('height', '128px');
  		},
  		'mouseleave': function(){
  			$('sec_items_2').set('tween', {}).tween('height', '0px');
  		}
	});
	
	$('section_menu_3').addEvents({
  		'mouseenter': function(){
  			$('sec_items_3').set('tween', {
  				duration: 450,
  				transition: Fx.Transitions.Cubic.easeOut
  			}).tween('height', '98px');
  		},
  		'mouseleave': function(){
  			$('sec_items_3').set('tween', {}).tween('height', '0px');
  		}
	});
	
	$('section_menu_4').addEvents({
  		'mouseenter': function(){
  			$('sec_items_4').set('tween', {
  				duration: 500,
  				transition: Fx.Transitions.Cubic.easeOut
  			}).tween('height', '158px');
  		},
  		'mouseleave': function(){
  			$('sec_items_4').set('tween', {}).tween('height', '0px');
  		}
	});
	
	$('section_menu_5').addEvents({
  		'mouseenter': function(){
  			$('sec_items_5').set('tween', {
  				duration: 500,
  				transition: Fx.Transitions.Cubic.easeOut
  			}).tween('height', '128px');
  		},
  		'mouseleave': function(){
  			$('sec_items_5').set('tween', {}).tween('height', '0px');
  		}
	});
	
});

