/******************************************************************
	Basic JS by Mike Serth									
******************************************************************/

 //var preloadIcons = new Asset.images(['typo3conf/ext/ms_setup/base/gfx/sprite-smallcorners-icons.png']);
 //var preloadCorners = new Asset.images(['typo3conf/ext/ms_setup/base/gfx/sprite-corners.png']);
 //var preloadNavigation = new Asset.images(['typo3conf/ext/ms_setup/base/gfx/sprite-navigation.png']);
 
// IE6 PNGFix
(function($) {
	window.addEvent('domready', function(){
		if (!Browser.ie6) {return};
		
		DD_belatedPNG.fix('div.corner-left');
		DD_belatedPNG.fix('div.corner-right');
	});
})(document.id);
 
(function(){
	window.addEvent('domready', function(){
		$$('.navigation-main-zone a').each(function(link) {
			link.addEvents({
				'mouseenter': function(e){
					this.store('tmpTitle',this.get('title'));
					this.set('title','');
				},
				'mouseleave': function(e){
					this.set('title',this.retrieve('tmpTitle'));
				}
			});
		});
	});
})(document.id);
		
 
// Fullscreen Background Call
(function($) {
	window.addEvent('domready', function(){
		var moosizer = new mooSizer({ bgElement:'fullsize' });
	});
})(document.id);


(function($){
	
	window.addEvent('domready', function(){
			
				var currentIndex	 = 0,
			        images           = [],
			        container        = null,
			        effect           = 'fade',
			        timer            = 10000,
			        clickLock        = false,
			        slideInterval    = null;
				
				var effects = {
						
		            fade: function(image) {
						image.fade('hide');
		                image.fade('in');
		            },
		            
		            slide: function(image, mode) {
		                var startX;
		                switch (mode) {
		                    case 'forward':
		                        startX = container.getSize().x;
		                        break;
		                    case 'backward':
		                        startX = container.getSize().x*-1;
		                        break;
		                }
		                
		                var slideComplete = function() {
		                    clickLock = false;
		                    this.removeEvent('complete', slideComplete);
		                }
		                
		                image.get('tween').addEvent('complete', slideComplete);
		                
		                image.setStyle('left', startX);
		                image.tween('left', 0);
		                
		                var imageTween = function() {
		                    
		                }
		                
		            }
		            
		        };
				
				// Keyvisual Image Fading
				if($('background-wrapper')){
					
					images = $$("#fullsize > img");
		        	container = $('fullsize');
		        	
		        	var imagesLoaded = [];
		            images.each(function(image) {
		                  var asset = document.id(new Image());
		                  asset.onload = function() {
		                        imagesLoaded.push(image);
		                        if (images.length === imagesLoaded.length) {
		                             images.fade('in');
		                        }
		                  }
		                  asset.src = image.get('src');
		            });
			        
			        if (images.length <= 1) return;
			        
			        var slide = function(mode) {
			            var previousImage        = images[currentIndex];
			            
			            switch (mode) {
			                case 'forward':
			                    currentIndex++;
			                    if (currentIndex > images.length-1) currentIndex = 0;
			                    break;
			                case 'backward':
			                    currentIndex--;
			                    if (currentIndex < 0) currentIndex = images.length-1;
			                    break;
			                default:
			                    return;
			            }
			            
			            var currentImage    = images[currentIndex],
			                highestZIndex    = 0;
			                
			            clickLock = true;
			            
			            if (effect in effects) effects[effect](currentImage, mode);
			            else effects.fade(currentImage);
			            
			            images.each(function(image) {
			                var zIndex = parseInt(image.getStyle('z-index'));
			                if (zIndex > highestZIndex) highestZIndex = zIndex;
			            });
			            
			            currentImage.setStyle('z-index', highestZIndex+1);
			            
			        };
			        
			        // Set InitStyles
			        container.setStyles({
			        	
			            overflow: 'hidden',
			            position: 'relative'
			            	
			        });
			        
			        images.each(function(image, i) {
			        	
			            image.setStyles({
			            	
			                position: 'absolute',
			                left: 0,
			                top: 0,
			                'z-index': images.length - i
			                
			            });
			            
			            image.set('tween', {duration: 2000, transition: Fx.Transitions.Quart.easeInOut});
			            
			        });
			        
			        var setupSlideInterval = function() {
			        	
			            if (slideInterval !== null) return;
			            slideInterval = slide.periodical(timer, this, ['forward']);
			            
			        };
			        
			        var clearSlideInterval = function() {
			        	
			            clearInterval(slideInterval);
			            slideInterval = null;
			            
			        };
			        
			        setupSlideInterval();
			        
				}
				
		});
	
})(document.id);


