/*
# MTS Studios ltd 2010 - copyrights
# No unauthorized use of this code. Please contact office@mtsstudios.com to acquire permission.
# www.mtsstudios.com
# LumLight Menu v.1 / 2010
#
# 
#
*/

function initMainMenu()
{

if(document.getElementById('menu'))
{
var menu = document.getElementById('menu');
}
else
{
return;
}
var light;
function _Light ( l, w )
{
var n_light = document.getElementById('n_light');
var n_light_c = document.getElementById('n_light_c');
var fix2 = 0; // left pos fix
var fix1 = 38 - fix2; // padding fix - fix2

var o_l = l-fix2;
var o_w = w-fix1;
var t_l;
var t_w;

this.curPos = function ( l, w )
{
    w -= fix1;
    l -= fix2;
    n_light.style.left = l+'px';
    n_light_c.style.width = w+'px';
}

this.position = function ( l, w )
{
w -= fix1;
l -= fix2;
if(!t_l)
{
    curL = n_light.offsetLeft;
    curW = n_light_c.offsetWidth;
    //alert(curL+':'+curW+'=>'+l+':'+w);
    t_l = new Tween(n_light.style,'left',Tween.regularEaseOut,curL,l,0.8,'px');
    t_w = new Tween(n_light_c.style,'width',Tween.regularEaseOut,curW,w,0.8,'px');
    t_l.start();
    t_w.start();
    t_l.onMotionFinished = function(){t_l=null;}
    t_w.onMotionFinished = function(){t_w=null;}
}
else
{
    t_l.stop();
    t_w.stop();
    curL = n_light.offsetLeft;
    curW = n_light_c.offsetWidth;

    t_l = new Tween(n_light.style,'left',Tween.regularEaseOut,curL,l,0.8,'px');
    t_w = new Tween(n_light_c.style,'width',Tween.regularEaseOut,curW,w,0.8,'px');
    t_l.start();
    t_w.start();
    t_l.onMotionFinished = function(){t_l=null;}
    t_w.onMotionFinished = function(){t_w=null;}
}
}
this.origPos = function ()
{
if(!t_l)
{
    curL = n_light.offsetLeft;
    curW = n_light_c.offsetWidth;
    //alert(curL+':'+curW+'=>'+l+':'+w);
    t_l = new Tween(n_light.style,'left',Tween.regularEaseOut,curL,o_l,0.8,'px');
    t_w = new Tween(n_light_c.style,'width',Tween.regularEaseOut,curW,o_w,0.8,'px');
    t_l.start();
    t_w.start();
    t_l.onMotionFinished = function(){t_l=null;}
    t_w.onMotionFinished = function(){t_w=null;}
}
else
{
    t_l.stop();
    t_w.stop();
    curL = n_light.offsetLeft;
    curW = n_light_c.offsetWidth;

    t_l = new Tween(n_light.style,'left',Tween.regularEaseOut,curL,o_l,0.8,'px');
    t_w = new Tween(n_light_c.style,'width',Tween.regularEaseOut,curW,o_w,0.8,'px');
    t_l.start();
    t_w.start();
    t_l.onMotionFinished = function(){t_l=null;}
    t_w.onMotionFinished = function(){t_w=null;}
}	
}
}


function _But ( li, x, w, a, l )
{
var but = li;
var x = x;
var width = w;
var active = a;
var link = l;

but.onmouseover = lightOn;
but.onmouseout = lightOff;

if(active)
curPos();


function lightOn ()
{
light.position(x,width);
}
function lightOff ()
{
light.origPos();
}

function curPos ()
{
    light.curPos(x,width);
}

}


function getButs()
{
var n_lis = menu.getElementsByTagName('li');
var x = 0;
var b_fix = 0;
for(i = 0; i < n_lis.length; i++)
{
x = n_lis[i].offsetLeft;
w = n_lis[i].offsetWidth;
l = n_lis[i].getElementsByTagName('a');
//alert(x+' '+w);
//alert(l[0]);
if(n_lis[i].id == 'active_page')
{
    a = true;
    light = new _Light(x,w);
}
else
    a = false;

but = new _But( n_lis[i], x, w, a, l[0] );

}
}
getButs();
////


}
