/***********************************************************************************
************************************************************************************
***                                                                              ***
***   XTC LavaLamp                                                               ***
***                                                                              ***
***   Copyright (c) 2010,2011 Monev Software LLC,  All Rights Reserved           ***
***                                                                              ***
***   This program is free software; you can redistribute it and/or modify       ***
***   it under the terms of the GNU General Public License as published by       ***
***   the Free Software Foundation; either version 2 of the License, or          ***
***   (at your option) any later version.                                        ***
***                                                                              ***
***   This program is distributed in the hope that it will be useful,            ***
***   but WITHOUT ANY WARRANTY; without even the implied warranty of             ***
***   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              ***
***   GNU General Public License for more details.                               ***
***                                                                              ***
***   You should have received a copy of the GNU General Public License          ***
***   along with this program; if not, write to the Free Software                ***
***   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   ***
***                                                                              ***
***   See COPYRIGHT.php for more information.                                    ***
***   See LICENSE.php for more information.                                      ***
***                                                                              ***
***   www.joomlaxtc.com                                                          ***
***                                                                              ***
************************************************************************************
***********************************************************************************/

function xtcLava(o){
    if(o.container){
    
      if(document.body.hasClass('lava'))
        this.container = $('menu').getElement('ul.menu');
        
      if(this.container){
        
        o.duration = (o.duration && (o.duration > 0) ) ? o.duration : 200;
        
        this.menuLeft = this.container.getPosition(this.container).x;
        
        this.lis = this.container.getChildren('li');
        this.current = 0;        
        this.lis.each(function(l,i){
          this.current = ( l.hasClass('active') ) ? i : this.current;
        }, this);
        
        var sizer = this.lis[this.current].getFirst('a');
        //this.tick = new Element('div', {'class':'left'});
        this.lamp = new Element('li', {'class':'lavalamp', styles:{
           height: sizer.getSize().y, 
           width: sizer.getSize().x,
           left: sizer.getPosition(this.container).x - this.menuLeft
        }});
        //this.lamp.adopt(this.tick);
        this.container.adopt(this.lamp);
        
        this.lavafx = new Fx.Morph(this.lamp, {duration: o.duration, link:'cancel', transition: Fx.Transitions.Quad.easeInOut, fps:73});
        this.lis.each(function(l,i){
          var sizeron = l.getFirst('a');
          var sizeroff = this.lis[this.current].getFirst('a');
          l.addEvent('mouseenter', function(){
            this.lavafx.start({ width: sizeron.getSize().x, left: sizeron.getPosition(this.container).x - this.menuLeft });
          }.bind(this));
          l.addEvent('mouseleave', function(){
            this.lavafx.start({ width: sizeroff.getSize().x, left: sizeroff.getPosition(this.container).x - this.menuLeft });
          }.bind(this));
        });
        
      }
    }
}
