/**
 * function: for second sliding teaser on homepage
 * usage: var twitterTeaserRun = setTimeout(twitterTeaserRun,5000);
 */
	function twitterTeaserRun(dir){
		var dir = (dir=="previous")? -1 : 1;
		
		try{clearTimeout(twitterTeaserTime)}catch(e){}
		var container = $("twitterTeaser").down('ul');
		var slides = container.childElements();
		for(i=0;i<slides.length;i++){
			if(slides[i].visible()){
				var current = i;
				i=999; //break loop
			}
		}
		
		var next = (current+slides.length+dir)%slides.length;
		var nextWidth = slides[next].getWidth();
		slides[next].show();
		slides[next].style.left = dir*nextWidth+'px';
		slides[next].style.position = 'absolute';
		slides[current].style.position = 'absolute';
		
		
		new Effect.Parallel([
			new Effect.Move(slides[next], { 
				x: 0, 
				y: 0, 
				mode: 'absolute',
				sync: true 
				}),
			new Effect.Move(slides[current], { 
				x: -dir*nextWidth, 
				y: 0,
				mode: 'absolute', 
				sync: true, 
				afterFinish: function(effect){
					effect.element.hide();
					}
				})
				],{
				duration: .8
			}
		);
		twitterTeaserTime = setTimeout(twitterTeaserRun,5000);
	}
	
/**
 * function: for second sliding teaser on homepage
 * usage: var highlightTeaserTime = setTimeout(highlightTeaserRun,5000);
 */
	function highlightTeaserRun(dir){
		var dir = (dir=="previous")? -1 : 1;
		
		try{clearTimeout(highlightTeaserTime)}catch(e){}
		var container = $("highlightTeaser").down('ul');
		var slides = container.childElements();
		for(i=0;i<slides.length;i++){
			if(slides[i].visible()){
				var current = i;
				i=999; //break loop
			}
		}
		
		var next = (current+slides.length+dir)%slides.length;
		var nextWidth = slides[next].getWidth();
		slides[next].show();
		slides[next].style.left = dir*nextWidth+'px';
		slides[next].style.position = 'absolute';
		slides[current].style.position = 'absolute';
		
		
		new Effect.Parallel([
			new Effect.Move(slides[next], { 
				x: 0, 
				y: 0, 
				mode: 'absolute',
				sync: true 
				}),
			new Effect.Move(slides[current], { 
				x: -dir*nextWidth, 
				y: 0,
				mode: 'absolute', 
				sync: true, 
				afterFinish: function(effect){
					effect.element.hide();
					}
				})
				],{
				duration: .8
			}
		);
		highlightTeaserTime = setTimeout(highlightTeaserRun,5000);
	}

var sponsorTeaser  = Class.create({
// constructor
	initialize: function(container,options) {
		this.elements = $(container).down('ul').childElements();
		this.current = 0;
		this.options = options;
		this.timeout = null;
		
		this._initStart();
	},
// Private functions
	_initStart: function(){
		var o = this.options;
	// start element
		if (typeof o.start == 'string'){
			if(o.start.toLowerCase() == 'random'){
				o.start = Math.floor(Math.random()*this.elements.length);
			}
		}else if (typeof o.start == 'number'){
			o.start = o.start%this.elements.length;
		}
		this.show(o.start);
	},
// Public functions
	show: function(nr){
		var nr = nr%this.elements.length;
		this.elements[this.current].hide();
		this.elements[nr].show();
		this.current = nr;
		var oThis = this;
		this.timeout = setTimeout(function(){oThis.next()},this.options.speed);
	},
	next: function(){
		this.show((this.current+1)%this.elements.length);
	},
	previous: function(){
		this.show((this.current+this.elements.length - 1)% this.elements.length);
	}
});

var quotesTeaser  = Class.create({
// constructor
	initialize: function(container,options) {
		this.elements = [];
		this.quote = $(container).down('blockquote');
		this.cite = $(container).down('cite');
		this.current = 0;
		this.options = options;
		this.timeout = null;
		
		if(typeof this.options.url == 'undefined'){
			throw('Please add the url property.');
		}
		if(typeof this.options.speed != 'number'){
			this.options.speed = 5000;
		}
		this._loadXML();
	},
// Private functions
	_loadXML: function(){
		var oThis = this;
		new Ajax.Request(this.options.url, {
			method: 'get',   
			onSuccess: function(transport) {       // yada yada yada 
					oThis._loadData(transport.responseXML);
					
				}
		}); 
	},
	_loadData: function(xml){
		var data = xml.getElementsByTagName("quota");
		for(i=0;i<data.length;i++){
			this.elements.push(data[i].childNodes[0].nodeValue)
			
		}
		this._shuffle();
		this.show(0);
	},
	_shuffle: function(){
	  var i = this.elements.length;
	  if ( i == 0 ) return false;
	  while ( --i ) {
	     var j = Math.floor( Math.random() * ( i + 1 ) );
	     var tempi = this.elements[i];
	     var tempj = this.elements[j];
	     this.elements[i] = tempj;
	     this.elements[j] = tempi;
	   }
	},
// Public functions
	show: function(nr){
		var nr = nr%this.elements.length;
		this.quote.innerHTML = this.elements[nr];
		this.current = nr;
		
		var oThis = this;
		this.timeout = setTimeout(function(){oThis.next()},this.options.speed);
	},
	next: function(){
		this.show((this.current+1)%this.elements.length);
	},
	previous: function(){
		this.show((this.current+this.elements.length - 1)% this.elements.length);
	}
});
/**
 * function: for second sliding teaser on homepage
 * usage: var quotesTeaserTime = setTimeout(quotesTeaserRun,5000);
 */
/*	function quotesTeaserRun(dir){
		var dir = (dir=="previous")? -1 : 1;
		
		try{clearTimeout(quotesTeaserTime)}catch(e){}
		var container = $("quotesTeaser").down('ul');
		var slides = container.childElements();
		for(i=0;i<slides.length;i++){
			if(slides[i].visible()){
				var current = i;
				i=999; //break loop
			}
		}
		
		var next = (current+slides.length+dir)%slides.length;
		var nextWidth = slides[next].getWidth();
		slides[next].show();
		slides[next].style.left = dir*nextWidth+'px';
		slides[next].style.position = 'absolute';
		slides[current].style.position = 'absolute';
		
		
		new Effect.Parallel([
			new Effect.Move(slides[next], { 
				x: 0, 
				y: 0, 
				mode: 'absolute',
				sync: true 
				}),
			new Effect.Move(slides[current], { 
				x: -dir*nextWidth, 
				y: 0,
				mode: 'absolute', 
				sync: true, 
				afterFinish: function(effect){
					effect.element.hide();
					}
				})
				],{
				duration: .8
			}
		);
		quotesTeaserTime = setTimeout(quotesTeaserRun,5000);
	}	

*/





	function checkListOpen(el){
		if(!$(el).next('.accordeonContent').visible()){
			$(el).up().select('.accordeonContent').invoke('hide');
			$(el).up().select('.checklistBoxOpen').invoke('removeClassName','checklistBoxOpen');
		
			$(el).addClassName('checklistBoxOpen');
			$(el).next('.accordeonContent').show();
		}else {
			$(el).removeClassName('checklistBoxOpen');
			$(el).next('.accordeonContent').hide();
		}
		
	}
	
	
	
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
