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() {
    
    var topmenu = $('container').getElement(".topmenu"),
        submenus = $('container').getElements(".submenu"),
        toplevel_onclass = "open",
        toplevel_offclass = "closed",
        toplevel_currentclass = "current",
        timer_active = false,
        timer_timeout = 5000,
        timer = new Date(),
        previous = false,
        timerobj = false;
        
        /*
,
        
        //functions
        hideSubmenu = function(m) {
            m.removeClass(toplevel_onclass).addClass(toplevel_currentclass).addClass(toplevel_offclass);
        },
        
        resetMenu = function(tli, previous) {
            tli.removeClass(toplevel_onclass).addClass(toplevel_offclass);
            previous.removeClass(toplevel_offclass).addClass(toplevel_onclass);
        };
*/
    
    
    if($('container').getElement('.menu-icons')) {

        var mask=$('container').getElement('.menu-icons-mask'),
            menu=$('container').getElement('.menu-icons'),
    		scroller = new Fx.Scroll(mask),
            lis=menu.getElements('li'),
            next=0,
            visible_quantity=7,
            timeout= 2000,
            direction = 1, //"forwards"; -1="backwards"
            pause = false; 
                                                            
        if(lis.length>visible_quantity) {
                    
            scrolling = (function(){
                
                //scroll to the chosen element
                scroller.toElement(lis[next]);
             	             
                // if count < length of elements list, thats ok
                // otherwise reset count to 0
                if((next >= lis.length-visible_quantity) && (direction==1) || (next == 0) && (direction==0)) {
                   direction = (direction==1) ? 0 :1;
                   //next stays the same to 'pause'
                } else {
                   if(direction==1) next++; else next--;
                }
                
            }).periodical(timeout);
        } else {
            // nothing
        }
    }
    
    
    	// background image
	if ($('bgimage')){
	
		// stop image clicking
		$('bgimage').addEvents({
			'mousedown': function (ev){ ev.stop(); },
			'mouseup': function (ev){ ev.stop(); },
			'click': function (ev){ ev.stop(); }
		});
		
		// resize image to window
		resizeImageToWindow = function (){
				
			// get x and y size
			var imgsize = $('bgimage').getSize();
		
			// get window width and height
			var windowsize = window.getSize();
			
			/* swipe
			var ch = $('swipe').getElement('div.content').getSize().y + 120;
			if (window.getSize().y > ch){
				$('swipe').setStyle('height', window.getSize().y);
			} else {
				$('swipe').setStyle('height', ch);
			}
			*/
			
			// how much to multiply width/height
			var ratio = 1;
						
			// landscape
			if (windowsize.x > windowsize.y){
			
				ratio = windowsize.x / imgsize.x;	
				
				// if y is going to give us whitespace
				if (ratio * imgsize.y < windowsize.y){
					ratio = windowsize.y / imgsize.y;
				}	
			
			} else { // portrait
			
				ratio = windowsize.y / imgsize.y;
				
				// if x is going to give us whitespace
				if (ratio * imgsize.x < windowsize.x){
					ratio = windowsize.x / imgsize.x;
				}
			
			}
			
			// we have a minimum width/height
			if (ratio * imgsize.x < 800){
				ratio = 800 / imgsize.x;
			} else if (ratio * imgsize.y < 600){
				ratio = 600 / imgsize.y;
			}
			
			// set height
			$('bgimage').setStyles({
				width: ratio * imgsize.x,
				height: ratio * imgsize.y
			});
			

		
		};
        
		// add window resize event
		window.addEvent('resize', resizeImageToWindow);
		window.fireEvent('resize', {}, 500);
	
  }


    
});
