function Timer(){this.obj=(arguments.length)?arguments[0]:window;return this;}
Timer.prototype.setInterval=function(func,msec){var i=Timer.getNew();var t=Timer.buildCall(this.obj,i,arguments);Timer.set[i].timer=window.setInterval(t,msec);return i;}
Timer.prototype.setTimeout=function(func,msec){var i=Timer.getNew();Timer.buildCall(this.obj,i,arguments);Timer.set[i].timer=window.setTimeout("Timer.callOnce("+i+");",msec);return i;}
Timer.prototype.clearInterval=function(i){if(!Timer.set[i])return;window.clearInterval(Timer.set[i].timer);Timer.set[i]=null;}
Timer.prototype.clearTimeout=function(i){if(!Timer.set[i])return;window.clearTimeout(Timer.set[i].timer);Timer.set[i]=null;}
Timer.set=new Array();Timer.buildCall=function(obj,i,args){var t="";Timer.set[i]=new Array();if(obj!=window){Timer.set[i].obj=obj;t="Timer.set["+i+"].obj.";}
t+=args[0]+"(";if(args.length>2){Timer.set[i][0]=args[2];t+="Timer.set["+i+"][0]";for(var j=1;(j+2)<args.length;j++){Timer.set[i][j]=args[j+2];t+=", Timer.set["+i+"]["+j+"]";}}
t+=");";Timer.set[i].call=t;return t;}
Timer.callOnce=function(i){if(!Timer.set[i])return;eval(Timer.set[i].call);Timer.set[i]=null;}
Timer.getNew=function(){var i=0;while(Timer.set[i])i++;return i;}
function noSpam(){if(document.getElementById){var at='@';var EmailLinks=$$('a');for(var i=0;i<EmailLinks.length;i++){var EmailLinkElement=EmailLinks[i];if(EmailLinkElement.className=='escape'){var LocalPart=EmailLinkElement.firstChild;var DomainPart=EmailLinkElement.lastChild;LocalPart.nextSibling.innerHTML=at;LocalPart.data=LocalPart.data.replace(/\s/g,"");DomainPart.data=DomainPart.data.replace(/\s/g,"");if(EmailLinkElement.rel!=''){EmailLinkElement.href="mailto:"+LocalPart.data+at+EmailLinkElement.rel;}
else{EmailLinkElement.href="mailto:"+LocalPart.data+at+DomainPart.data;}}}}}
sfHover=function(){var sfEls=$$("#mainnavi li");for(var i=0;i<sfEls.length;i++){sfEls[i].onmouseover=function(){this.className+=" sfhover";}
sfEls[i].onmouseout=function(){this.timer=new Timer(this);this.timer.setTimeout("out",100);}
sfEls[i].out=function(){this.className=this.className.replace(new RegExp("\\bsfhover\\b"),"");}}}
function basename(){var pts=location.href.split('\\');if(pts.length<2)pts=location.href.split('/');return pts[pts.length-1];}

/************************************************/

function showSlideshow(){
	$('slideshow').fade('in');
}
function fadeSlideshow(){
	$('slideshow').fade(0.7);
}

window.addEvent('domready', function(){
//	email protection
	noSpam();
	
// 	smooth anchor scrolling
	new SmoothScroll({duration: 600});

//	automatically distribute widths for navigation
//	naviAutoWidth(600,'navi-main');

//	simple dropdown:
//	sfHover();
	
//	animated dropdown (with mootools)
//	new MenuMatic({id: 'navi-main',hideDelay: 800,opacity: 100});
	
//	image-slideshow
//	show = new SlideShow('slideshow',{height:'300px'});

	slideshowImageArray = [0,1,2,3,4,5,6,7,8,9,10,11,12];
	slideshowImageArray.sort(function() {return 0.5 - Math.random()});
	
	var mysort = new Fx.Sort($$('#slideshow span'), {duration: 1});
	mysort.rearrangeDOM(slideshowImageArray);
	

	var slideShow = new noobSlide({
		box: $('slideshow'),
		items: slideshowImageArray,
		interval: 5000,
		size: 460,
		autoPlay: true,
		fxOptions: {
			duration: 1600,
			transition: Fx.Transitions.Sine.easeInOut,
			wait: false
		},
		onWalk: function(currentItem, currentHandle){
			fadeSlideshow();
			setTimeout("showSlideshow()",800);
		},
		addButtons: {
			previous: $('slideshow-prev'),
			next: $('slideshow-next'),
			stop: $('slideshow-stop'),
			play: $('slideshow-play')
		}
	});
	$('slideshow-container').addEvent('mouseenter',function(){
		if(slideShowPlays && slideShowPlays === true){
			$('slideshow-stop').fade('in');
			$('slideshow-play').setStyles({
				'visibility':'hidden',
				'opacity': 0
			});
		} else {
			$('slideshow-play').fade('in');
			$('slideshow-stop').setStyles({
				'visibility':'hidden',
				'opacity': 0
			});
		}
	});
	$('slideshow-container').addEvent('mouseleave',function(){
		if($('slideshow-play').getStyle('visibility') == 'visible'){
			$('slideshow-play').fade('out');
		}
		if($('slideshow-stop').getStyle('visibility') == 'visible'){
			$('slideshow-stop').fade('out');
		}
	});


//	mooscroll - js-scrollbars besides the content (for fixed content-container height)
//	var scrollBox1 = new MooScroll({selector:'#content-main'});	
	
//	only show top-link, if content is high enough
/*	$$('.top-link').each(function(el,i){if(i==$$('.top-link').length-1){
		if($('content-main').clientHeight < 350){el.setStyle('display','none')}}
	});*/

//	accordion
	var myAccordion = new Accordion($('accordion'), '.toggler', '.element', {
		opacity: false,
		display: -1,
		alwaysHide: true,
		onActive: function(toggler, element){
			//toggler.setStyle('color', '#41464D');
		},
		onBackground: function(toggler, element){
			//toggler.setStyle('color', '#528CE0');
		}
	});

});
