function rand (min, max) {  
    return Math.floor(Math.random() * (max - min + 1)) + min;  
}  

window.addEvent("domready", function() {
	
	$('content').setStyle('min-height', '546px');

 if($$('.switcher').length > 0) {
        $$('.switcher').each(function(switcher) {           
            var bilder = switcher.getChildren('p');
            var bildbuttons = switcher.getElement('.switcherbuttons');
            
            var width = switcher.getSize().x;
            var height = 0;
            var i=0;
            bilder.each(function(bild) {
                if(height < bild.getSize().y) height = bild.getSize().y;
		
		if(bildbuttons) {
                	var btnhtml = bildbuttons.get('html');
                	btnhtml += "<img alt='" + i + "' style='cursor:pointer;z-index: 10000;margin-left: 0px;' src='frontend/style/default/images/graydot.png' />";
                	bildbuttons.set('html', btnhtml);
                	i++;
		}

            });
            //alert(height);
            //switcher.set('html', '');
            switcher.setStyles({
                overflow: 'hidden',
                position:'relative'
            });
            
            bilder.setStyles({
                position: 'absolute',
                top: '0px',
                display: 'block',
                margin: 0
            });

		bilder.fade('hide');
			

            switcher.adopt(bilder);
	if(bildbuttons) {	
            	switcher.adopt(bildbuttons);

            	var buttons = bildbuttons.getElements('img');
            	buttons[0].set('src', 'frontend/style/default/images/reddot.png');
            
          	  buttons.addEvent('click', function(){
                	next = this.get('alt').toInt();
             	   if(next >= bilder.length) next = 0;

            	    buttons[next].set('src', 'frontend/style/default/images/reddot.png');
            	    buttons[current].set('src', 'frontend/style/default/images/graydot.png');   
                
            	    bilder[next].setStyle('left', (width*-1)+'px');
            	    bilder[current].tween('left', (width)+'px');
            	    bilder[next].tween('left', '0px');
           	     current = next;

           	     clearInterval(switchtimer);
           	     switchtimer = doswitch.periodical(1500+4000);

           	 });
            }
            bilder[0].setStyles({
                left: '0px',
                top: '0px'
            });

            switcher.setStyles({
                height: '550px'
            });

		var current = rand(0, bilder.length-1);
		bilder[current].fade('show');	
            
            
            var doswitch = function() {
                next = current+1;
                if(next >= bilder.length) next = 0;

if(bildbuttons) {
                buttons[next].set('src', 'frontend/style/default/images/reddot.png');
                buttons[current].set('src', 'frontend/style/default/images/graydot.png');
               } 
                //bilder[next].setStyle('left', (width*-1)+'px');
                //bilder[current].tween('left', (width)+'px');
                //bilder[next].tween('left', '0px');
bilder[next].fade('in');
bilder[current].fade('out');
                current = next;
            };

            switchtimer = doswitch.periodical(1500+4000);
        });
    }
    

	
    if($('imagegallery')) {
        var gallery = $('imagegallery');
        gallery.setStyle('display', 'block');
        if(gallery.getElements('.gallery_item').length > 0) {
            
            var height = 0;
            var overlayHeight = 0;
            var width = gallery.getSize().x;
            gallery.getElements('.gallery_item').each(function(el) {
                //var calcHeight = el.getStyle('height').toInt() + el.getStyle('border-top-width').toInt() + el.getStyle('border-bottom-width').toInt() + el.getStyle('margin-top').toInt() + el.getStyle('margin-bottom').toInt();
                var calcHeight = el.getSize().y + el.getStyle('border-top-width').toInt() + el.getStyle('border-bottom-width').toInt() + el.getStyle('margin-top').toInt() + el.getStyle('margin-bottom').toInt();
            //alert(calcHeight);
                if(calcHeight > height) height = calcHeight;
                
                calcHeight = el.getElement('img').getSize().y + el.getElement('img').getStyle('border-top-width').toInt() + el.getElement('img').getStyle('border-bottom-width').toInt() + el.getElement('img').getStyle('margin-top').toInt() + el.getElement('img').getStyle('margin-bottom').toInt();
                if(calcHeight > overlayHeight) overlayHeight = calcHeight;
                
            });
            //alert(overlayHeight);
                        
            var overlay = new Element('div');
            overlay.addClass('overlay');
            overlay.setStyles({
                width: width,
                height: overlayHeight,
                margin: '0px',
                padding: '0px',
                position: 'absolute',
                top: '6px',
                left: '0px',
                'z-index': 200
            }).inject(gallery);
            
            gallery.setStyles({
                position: 'relative',
                overflow: 'hidden',
                height: (height+10)+'px'             
            });
            
            gallery.getElements('.gallery_item').setStyles({
                position: 'absolute',
                top: '10px',
                left: width+'px',
                width: width+'px',
                display: 'block',
                background: 'transparent'
            });
            
            var current = gallery.getElement('.gallery_item').setStyle('left', '0px');
            
            
            gallery.getElements('.gallery_item').each(function(el, key) {
	          	  var tempimg = new Element('img', {'class': 'imagegallery_dot', 'src': 'frontend/style/default/images/gallerydots_gray.png'});
	          	  if(key==0){
	          	  	tempimg.set('src', 'frontend/style/default/images/gallerydots_orange.png');
	          	  	
	          	  }
	          	  tempimg.inject($('imagegallery_navi'));
	          	  tempimg.addEvent('click', function(){
	          	  	
	          	  		$$('#imagegallery_navi .imagegallery_dot').set('src', 'frontend/style/default/images/gallerydots_gray.png');
	          	  		this.set('src', 'frontend/style/default/images/gallerydots_orange.png');

		          	  	var next = el;
		                if(next == null) next = gallery.getFirst('.gallery_item');
		                next.setStyles({
		                    'left': (width*1)+'px',
		                    'z-index': 100
		                });
		                current.tween('left', (width*-1)+'px');
		                next.tween('left', '0px');
		            
		                current.setStyle('z-index', '0');
		                current = next;
		                
	          	  });
            });
            
            
            
            
            gallery.getElements('.gallery_item').set('tween', { transition: 'expo:Out' });
            if(gallery.getElements('.gallery_item').length > 1) {
                gallery.setStyles({cursor: 'pointer'});
                overlay.addClass('controlls');
                //gallery.addEvents({
                overlay.addEvents({
                    'click': function(e) {
                        var pos = e.client.x-gallery.getPosition().x;
                        var posy = e.client.y-gallery.getPosition().x;
                        //if(posy < 400) {
                            if(pos > (width/2)) {
                            	$$('#imagegallery_navi .imagegallery_dot').set('src', 'frontend/style/default/images/gallerydots_gray.png');
	          	  				
                            	
                                var next = current.getNext('.gallery_item');
                                if(next == null) next = gallery.getFirst('.gallery_item');
  
                                var nextIndex = gallery.getElements('.gallery_item').indexOf(next);
                                $$('#imagegallery_navi .imagegallery_dot')[nextIndex].set('src', 'frontend/style/default/images/gallerydots_orange.png');
                                
                                next.setStyles({
                                    'left': (width*1)+'px',
                                    'z-index': 100
                                });
                                current.tween('left', (width*-1)+'px');
                                next.tween('left', '0px');
                            
                                current.setStyle('z-index', '0');
                                current = next;
                            } else {
                            	$$('#imagegallery_navi .imagegallery_dot').set('src', 'frontend/style/default/images/gallerydots_gray.png');
	          	  				this.set('src', 'frontend/style/default/images/gallerydots_orange.png');

                            	
                                var next = current.getPrevious('.gallery_item');
                                if(next == null) next = gallery.getLast('.gallery_item');
                                
                                var nextIndex = gallery.getElements('.gallery_item').indexOf(next);
                                $$('#imagegallery_navi .imagegallery_dot')[nextIndex].set('src', 'frontend/style/default/images/gallerydots_orange.png');
                          
                                next.setStyles({
                                    'left': (width*-1)+'px',
                                    'z-index': 100
                                });
                                current.tween('left', (width)+'px');
                                next.tween('left', '0px');
                                
                                current.setStyle('z-index', '0');
                                current = next;
                            } 
                        //}
                        return false;
                    }
                });
            }
        }
        
    }
    

});



/*
---

script: Loop.js

description: Runs a class method on a periodical

license: MIT-style license.

authors: Ryan Florence <http://ryanflorence.com>

docs: http://moodocs.net/rpflo/mootools-rpflo/Loop

requires:
- core:1.2.4/'*'

provides: [Loop]

...
*/

var Loop = new Class({

	loopCount: 0,
	isStopped: true,
	isLooping: false,
	loopMethod: function(){},

	setLoop: function(fn,delay){
		if(this.isLooping) {
			this.stopLoop();
			var wasLooping = true;
		} else {
			var wasLooping = false;
		}
		this.loopMethod = fn;
		this.loopDelay = delay || 3000;
		if(wasLooping) this.startLoop();
		return this;
	},

	stopLoop: function() {
		this.isStopped = true;
		this.isLooping = false;
		$clear(this.periodical);
		return this;
	},

	startLoop: function(delay) {
		if(this.isStopped){
			var delay = (delay) ? delay : this.loopDelay;
			this.isStopped = false;
			this.isLooping = true;
			this.periodical = this.looper.periodical(delay,this);
		};
		return this;
	},

	resetLoop: function(){
		this.loopCount = 0;
		return this;
	},

	looper: function(){
		this.loopCount++;
		this.loopMethod(this.loopCount);
		return this;
	}

});


/************************************************
*   mooquee v.1.1                               *
*   Http: WwW.developer.ps/moo/mooquee          *
*   Dirar Abu Kteish dirar@zanstudio.com        *
*   2009-01-30                                  *
*************************************************
*   Extend By www.Sod.hu                        *
*   new directions: top, bottom                 *
*   2008-04-30                                  *
/***********************************************/
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details. */ 

var mooquee = new Class({
    initialize: function(element, options) {
		this.setOptions({
			marHeight: 40,
			marWidth: 550,
			steps: 1,
			speed: 40,
			direction: 'bottom',
			pauseOnOver: true,
			pauseOnContainerOver: true
	    }, options);
	    this.timer = null;
	    this.textElement = null;
	    this.fx = null;
	    this.mooqueeElement = element;
	    this.constructMooquee();
	},
	constructMooquee: function() {
		var el = this.mooqueeElement;
		el.setStyles({
		    'width' : this.options.marWidth
		    ,'height' : this.options.marHeight		    
		});
        this.textElement = new Element('div',{
		    'class' : 'mooquee-text'
		    ,'id' : 'mooquee-text'
		}).set('html', el.innerHTML).setStyle('position', 'absolute');
		el.set('html', '');//clear mooqueeElement inner html
		el.setStyles({
			position: 'absolute',
			overflow: 'hidden',
			'white-space': 'nowrap'
		});
		this.textElement.inject(el);
		//this.textElement = $('mooquee-text');
		
		if((this.textElement.getCoordinates().width.toInt()+20) <= this.textElement.getParent().getCoordinates().width.toInt()) {
			this.textElement.setStyle("padding-left", "20px");
			return;
		}
        if(!this.setStartPos()){return;}
        if(this.options.pauseOnOver){this.addMouseEvents();}
		//start marquee
        
		//this.timer = this.startMooquee.delay(this.options.speed, this);
        var mq = this;
        this.fx = new Fx.Tween(this.textElement, {
        	"onComplete": function() {
        		this.start("left", mq.textElement.getParent().getCoordinates().width.toInt(), -1 * mq.textElement.getCoordinates().width.toInt());
        	},
        	"duration": this.options.speed,
        	transition: "linear"
        });
        
        this.fx.start("left", this.textElement.getParent().getCoordinates().width.toInt(), this.textElement.getCoordinates().width.toInt() * -1);
	},
	setStartPos: function(){
	    /* sod.hu Ext */
		if( this.options.direction == 'bottom' )
            this.textElement.setStyle('bottom', ( -1 * this.textElement.getCoordinates().height.toInt()));
        else if( this.options.direction == 'top' )
            this.textElement.setStyle( 'bottom', this.options.marHeight );
        else if( this.options.direction == 'left' )
            this.textElement.setStyle('left', ( -1 * this.textElement.getCoordinates().width.toInt()));
        else if( this.options.direction == 'right' )
            this.textElement.setStyle( 'left', this.options.marWidth );
        else{
            alert( 'direction config error: ' + this.options.direction );
            return false;
        }
        return true;
	},
	addMouseEvents : function(){
	    if(!this.options.pauseOnContainerOver){
	        this.textElement.addEvents({
	            'mouseenter' : function(me){
	                //this.clearTimer();
	        		this.fx.pause();
	            }.bind(this),
	            'mouseleave' : function(me){
	               // this.timer = this.startMooquee.delay(this.options.speed, this);
	            	this.fx.resume();
	            }.bind(this)
	        });
	    }else{
	        this.mooqueeElement.addEvents({
	            'mouseenter' : function(me){
	                //this.clearTimer();
	        		this.fx.pause();
	            }.bind(this),
	            'mouseleave' : function(me){
	                //this.timer = this.startMooquee.delay(this.options.speed, this);
	            	this.fx.resume();
	            }.bind(this)
	        });
	    }
	},
    startMooquee: function(){
        /* sod.hu Ext */
        if(this.options.direction == 'bottom' || this.options.direction == 'top')
            var pos = this.textElement.getStyle('bottom').toInt();
        else if(this.options.direction == 'left' || this.options.direction == 'right')
            var pos = this.textElement.getStyle('left').toInt();
        if(this.options.direction == 'bottom')
            this.textElement.setStyle( 'bottom', ( pos + -1 ) + 'px' );
        else if(this.options.direction == 'top')
            this.textElement.setStyle( 'bottom', ( pos + 1 ) + 'px' );
        else if(this.options.direction == 'left'){
            this.textElement.setStyle( 'left', ( pos + -1 ) + 'px' );
        }
        else if(this.options.direction == 'right')
            this.textElement.setStyle( 'left', ( pos + 1 ) + 'px' );
        /* sod.hu Ext end */
        this.checkEnd(pos);
        //this.timer = this.startMooquee.delay(this.options.speed, this);
    },
    resumeMooquee: function(){
        this.stopMooquee();
        if(this.options.pauseOnOver){this.addMouseEvents();}
        this.timer = this.startMooquee.delay(this.options.speed, this);
    },
    stopMooquee: function(){
        this.clearTimer();
        this.textElement.removeEvents();
    },
    clearTimer: function(){
        $clear(this.timer);
    },
    checkEnd: function(pos){
        /* sod.hu Ext */
        if(this.options.direction == 'bottom'){
            if(pos < -1 * (this.textElement.getCoordinates().height.toInt()))
                this.textElement.setStyle('bottom', this.options.marHeight);
        } else if(this.options.direction == 'top'){
            if(pos > this.options.marHeight.toInt())
                this.textElement.setStyle('bottom', -1 * (this.textElement.getCoordinates().height.toInt()) );
        } else if(this.options.direction == 'left'){
            if(pos < -1 * (this.textElement.getCoordinates().width.toInt()))
                this.textElement.setStyle('left', this.options.marWidth);
        } else if(this.options.direction == 'right'){
            if(pos > this.options.marWidth.toInt())
                this.textElement.setStyle('left', -1 * (this.textElement.getCoordinates().width.toInt()) );
        }
        /* sod.hu Ext end */
    },
    setDirection: function(dir){
        this.options.direction = dir;
        this.setStartPos();
    }
});
mooquee.implement(new Options);

/*
$(document).addEvent("domready", function() {
	if($('start_news')) {
		var newsContainer = $('start_news').getElement("div");
		var speed = newsContainer.getElements("span").length * 10000;
		var speed = newsContainer.get("html").stripTags().length*50 + 5000;
		obj = new mooquee(newsContainer, {marWidth: "745px", direction:"left", "speed":speed});
	}
	
	if($('glossaryContainer')) {
		$$('body')[0].adopt($('glossaryContainer')); // Hier wird sichergegangen, dass die Boxen richtig ausgerichtet werden
		$$('span.glossaryLink').each(function(link) {
			link.removeClass('glossaryLink');
			var ID = link.get('class');
			link.addClass('glossaryLink');
			var descDiv = $('glossaryContainer').getFirst('.entry'+ID);
			descDiv.setStyles({
				'position': 'absolute',
				display:'block',
				opacity:0
			});
			
			link.store('descDiv', descDiv);
			
			link.addEvents({
				'mouseenter': function(e) {
					this.retrieve('descDiv').setStyles({
						top: link.getPosition().y+'px',
						left: (link.getPosition().x+link.getWidth()+5)+'px'
					});
					this.retrieve('descDiv').fade('in');
					
				},
				
				'mouseleave': function(e) {
					this.retrieve('descDiv').fade('out');			
				}
			});
		});
	}
	
	/*$('glossaryContainer').getChildren('div').each(function(el) {
		
	});
});
*/

