//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2009 Aaron Newton <http://clientcide.com/>, Valerio Proietti <http://mad4milk.net> & the MooTools team <http://mootools.net/developers>, MIT Style License.

MooTools.More={version:"1.2.4.4",build:"6f6057dc645fdb7547689183b2311063bd653ddf"};Fx.Scroll=new Class({Extends:Fx,options:{offset:{x:0,y:0},wheelStops:true},initialize:function(b,a){this.element=this.subject=document.id(b);
this.parent(a);var d=this.cancel.bind(this,false);if($type(this.element)!="element"){this.element=document.id(this.element.getDocument().body);}var c=this.element;
if(this.options.wheelStops){this.addEvent("start",function(){c.addEvent("mousewheel",d);},true);this.addEvent("complete",function(){c.removeEvent("mousewheel",d);
},true);}},set:function(){var a=Array.flatten(arguments);if(Browser.Engine.gecko){a=[Math.round(a[0]),Math.round(a[1])];}this.element.scrollTo(a[0],a[1]);
},compute:function(c,b,a){return[0,1].map(function(d){return Fx.compute(c[d],b[d],a);});},start:function(c,g){if(!this.check(c,g)){return this;}var e=this.element.getScrollSize(),b=this.element.getScroll(),d={x:c,y:g};
for(var f in d){var a=e[f];if($chk(d[f])){d[f]=($type(d[f])=="number")?d[f]:a;}else{d[f]=b[f];}d[f]+=this.options.offset[f];}return this.parent([b.x,b.y],[d.x,d.y]);
},toTop:function(){return this.start(false,0);},toLeft:function(){return this.start(0,false);},toRight:function(){return this.start("right",false);},toBottom:function(){return this.start(false,"bottom");
},toElement:function(b){var a=document.id(b).getPosition(this.element);return this.start(a.x,a.y);},scrollIntoView:function(c,e,d){e=e?$splat(e):["x","y"];
var h={};c=document.id(c);var f=c.getPosition(this.element);var i=c.getSize();var g=this.element.getScroll();var a=this.element.getSize();var b={x:f.x+i.x,y:f.y+i.y};
["x","y"].each(function(j){if(e.contains(j)){if(b[j]>g[j]+a[j]){h[j]=b[j]-a[j];}if(f[j]<g[j]){h[j]=f[j];}}if(h[j]==null){h[j]=g[j];}if(d&&d[j]){h[j]=h[j]+d[j];
}},this);if(h.x!=g.x||h.y!=g.y){this.start(h.x,h.y);}return this;},scrollToCenter:function(c,e,d){e=e?$splat(e):["x","y"];c=$(c);var h={},f=c.getPosition(this.element),i=c.getSize(),g=this.element.getScroll(),a=this.element.getSize(),b={x:f.x+i.x,y:f.y+i.y};
["x","y"].each(function(j){if(e.contains(j)){h[j]=f[j]-(a[j]-i[j])/2;}if(h[j]==null){h[j]=g[j];}if(d&&d[j]){h[j]=h[j]+d[j];}},this);if(h.x!=g.x||h.y!=g.y){this.start(h.x,h.y);
}return this;}});

window.addEvent('domready', function (){
    (function(){
        var addNumber = function(el, pref){
            el = el==undefined ? $(document.body) : el;
            pref = pref==undefined ? '' : pref;
            var sp = '.';
            el.getChildren('ol').each(function(li){
               li.getChildren('li').each(function(e,i){
                   var entry = e.get('html').trim().substr(0, 1)=='<' ? e.getChildren('*')[0] : false;
                   new Element('span', {
                       'class': 'li'
                       , 'html': pref+(i+1)+sp
                   }).inject(entry ? entry : e, 'top');
                   addNumber(e, pref+(i+1)+sp);
               });
            });
        }
	addNumber();
    })();
    (function(){
        var m = {};
        m[0]=[];
        var levels = {};
        $$('*').filter(function(el, i){
            return ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].contains(el.get('tag'));
        }).each(function(el, i){
            var id= i+1;
            var level = el.get('tag').substr(1).toInt()-1;
            levels[level] = id;
            m[id]=[];
            m[level>0 ? levels[level-1] : 0].include({
                'id': id
                , 'name': el.get('text')
            });
            el.set('id', 'h-'+id);
            //console.info(level+'-'+id)
        });
        var fx = new Fx.Scroll(window, {
            'link':'cancel'
            , 'duration': 1000
            , 'transition': Fx.Transitions.Expo.easeOut
        });
        var dropMenu = function(parent, el){
            if(m[parent].length<=0)
                return;
            var ul = new Element('ul').inject(el);
            $each(m[parent], function(p){
                 var li = new Element('li').inject(ul);
                 new Element('a', {
                     'html': p.name
                     , 'href': '#h-'+p.id
                     , 'events': {
                         'click': function(e){
                             var a = this.get('href').split('#').getLast();
                             fx.toElement($(a)).chain(function(){
                                //$(a).highlight('#e11');
                                window.location.href = window.location.href.split('#')[0]+'#'+a
                             });
                             return false;
                         }
                     }
                 }).inject(li);
                 dropMenu(p.id, li);
            });
        }
        dropMenu(0, new Element('div', {
            'id': 'nav'
            , 'styles': {
                'height': window.getSize().y-20
            }
        }).inject(document.body, 'top'));
    })();
	(function(){
		new Element('div', {
			'id':'foot'
			, 'html':'<p>Itys dokuments jer oriģinal puorrokstiets nu <a href="http://lakuga.lv/lg/voluda/raksteiba">lakuga.lv</a>. Ka pamaņi klaidu ci drukys klaidu, tod atroksti uz <a href="mailto:termilv@gmail.com">termilv@gmail.com</a></p>'
		}).inject(document.body, 'bottom');
	})();
});

