function animateMenuLeft(index) {
  var currentidx = index;
  $$('.menubar').each(function(item,idx) {
    var currentleft = item.getPosition(item.getParent()).x;
    if (idx == currentidx) {
      item.setStyle('left',(currentleft+(3-idx)*35)+'px');
    }
    if (idx > currentidx) {
      item.setStyle('left',(currentleft-35)+'px');    
    }
  });  
  $$('.menubar').each(function(item,idx) {
    if (idx == currentidx) {
      var colorbarMorph = new Fx.Morph(item);
      var textMorph = new Fx.Morph(item.getElement('.textbar img'));
      var submenu = $('leftcol').getElement('.submenu');
      var submenuReveal = new Fx.Reveal(submenu,{'duration':'long'});
      
      colorbarMorph.start({'height':'380px'}).chain(function() {
        textMorph.start({'height':'220px','width':'21px'});
        submenuReveal.reveal();
      });
        
    } else {
      item.addEvents({
        'mouseover': function(e) {
          this.set('morph', {duration: 'short', transition: 'sine:out'});
          this.morph({'height':'200px'});
        },
        'mouseout': function(e) {
          this.morph({'height':'180px'});
        }            
      });
    }
  });
}

function _animateMenuLeft(index) {
  var currentidx = index;
  var delta = 30;  
  $$('.menubar').each(function(item,idx) {
    var currentleft = item.getPosition(item.getParent()).x;
    if (idx == currentidx) {
      item.setStyle('left',(currentleft+(4-idx)*delta)+'px');
    }
    if (idx > currentidx) {
      item.setStyle('left',(currentleft-delta)+'px');    
    }
  });  
  $$('.menubar').each(function(item,idx) {
    if (idx == currentidx) {
      var colorbarMorph = new Fx.Morph(item);
      var textMorph = new Fx.Morph(item.getElement('.textbar img'));
      var submenu = $('leftcol').getElement('.submenu');
      var submenuReveal = new Fx.Reveal(submenu,{'duration':'long'});
      
      colorbarMorph.start({'height':'380px'}).chain(function() {
        textMorph.start({'height':'220px','width':'21px'});
        submenuReveal.reveal();
      });
        
    } else {
      item.addEvents({
        'mouseover': function(e) {
          this.set('morph', {duration: 'short', transition: 'sine:out'});
          this.morph({'height':'200px'});
        },
        'mouseout': function(e) {
          this.morph({'height':'180px'});
        }            
      });
    }
  });
}

function animateIndexServices() {
  $$('.bar').each(function(item) {        
  
    var shade = item.getElement('.barsh');
    shade.setStyles({'opacity':1,'visibility':'hidden'});
   
    var shadewarp = new Fx.Morph(shade,{
      duration: 600,
      transition: Fx.Transitions.Sine.easeIn,
      onComplete: function() {
        shade.setStyles({'height':'','width':'','opacity':1,'visibility':'hidden'});
      }
    });
    item.addEvents({
      'mouseenter': function(e) {
        shade.setStyle('visibility','');
        shadewarp.start({'height':'500px','width':'140px','opacity':0});
      },
      'click': function(e) {
      }
    });
  });
             
}
function scrollNews() {
  var newsli = $('news').getElements('li');
  var n = newsli.length;
  var howlong = n * 20000;
  var containery = $('newscontainer').getDimensions().y;
  var newsy = $('news').getDimensions().y;
  $('news').setStyle('margin-top',containery);
  var myFx = new Fx.Morph('news', {          
    duration: howlong,
    transition: Fx.Transitions.linear,
    chain: 'ignore',
    onComplete: function() {
      this.start({
        'margin-top': [containery,-1*newsy]
      });
    }
  }).start({
    'margin-top': [containery,-1*newsy]
  });     
  $('news').getElement('ul').addEvents({
      'mouseenter': function() {
        myFx.pause();
      },
      'mouseleave': function() {
        myFx.resume();
      }
    });
}      

function slideCenter() {
  $('center').setStyles({'margin-right':'9px','width':'496px'}); 
  var limity = $('center').getDimensions().y;
  var addtoy = $('center').getStyle('margin-top').toInt()+$('center').getStyle('margin-bottom').toInt();
  var sizey = $('centerscroll').getDimensions().y+addtoy;
  var stepy = limity-sizey; 
  var slider = new Element('div',{'id':'slider'});
  var knob = new Element('div',{'id':'knob'});
  slider.grab(knob);
  $('center').grab(slider);
  var mySlider = new Slider(slider,knob, {
    range: [0,stepy*-1],
    mode: 'vertical',
    wheel: true,
    snap: true,
    onChange: function(pos){
      var currentmargin = $('centerscroll').getStyle('margin-top').toInt();
      $('centerscroll').setStyle('margin-top',pos * -1);            
    }
  });
  $('centerscroll').addEvent('mousewheel',function(e) {
    e.stop();
    var currentmargin = $('centerscroll').getStyle('margin-top').toInt();
    if (currentmargin >= stepy && currentmargin <= 0) {
      var wheelstep = currentmargin + e.wheel * 15;
      if (wheelstep > 0) wheelstep=0;
      if (wheelstep < stepy) wheelstep=stepy;
      $('centerscroll').setStyle('margin-top',wheelstep);            
      mySlider.set(Math.abs(wheelstep));
    }          
  });
}

function colorBox() {
  var domains = ["127.0.0.1",
                ".moovie.it"];
  var ac = Cookie.read('color');
  if (ac) {
    $$('.lat').each(function(x) {
      x.getElements('b').each(function(b) {
        b.setStyle('color','#'+ac);
      });
    });
    if ($('cc')) {
      $('cc').getElements('b').each(function(b) {
        b.setStyle('color','#'+ac);
      });
      $('cc').getElements('.bb').each(function(b) {
        b.setStyle('color','#'+ac);
      });        
    }
  }

  $$('.clrbox').each(function(a) {
    a.addEvent('click',function(e) {
      var c = this.get('id').substring(2);
      $$('.lat').each(function(x) {
        x.getElements('b').each(function(b) {
          b.setStyle('color','#'+c);
        });
      });
      if ($('cc')) {
        $('cc').getElements('b').each(function(b) {
          b.setStyle('color','#'+c);
        });
        $('cc').getElements('.bb').each(function(b) {
          b.setStyle('color','#'+c);
        });        
      }
      domains.each(function(d) {
        Cookie.write('color', c, {domain: d, path: "/", duration: 3600*24*60});
      });      
    });
  });
}

function hilightMenu(title,style) {
if ($('leftcol').getElement('.submenu')) {
  $('leftcol').getElement('.submenu').getElements('a').each(function(h) {
    if (h.get('title') == null)
       h.setStyle('color','#666');
    if (h.get('title') == title)
       h.addClass(style);
  });
}
}
