(function() {
	if (!Browser.Platform.ios) return;
	window.addEvent('domready', function() {
		document.body.setStyle('background-color','#000000');
		$$('.navigation-main .if-sub').each(function(el){
			el.addEvent('click', function(e){
				el.addClass(':hover');
			});
		});
		
		$$('#global-wrap').each(function(el) {
			var myScroll = new iScroll(el, { 
				zoom: true,
				zoomMin: 1,
				zoomMax: 2
			});
			
			el.addEventListener('touchmove', function(e){ e.preventDefault(); }, false);
			
		});
		
	});
	
})();

(function() {
	window.addEvent('domready', function() {
		if (!$('livebox')) return;
		$('livebox').addEvent('click', function(){
			var el = this;
			this.set('tween', {duration: 800, transition: Fx.Transitions.Sine.easeIn});
			this.tween('margin-top', 0);
			this.store('status', 'open');
			setTimeout(function() {
				window.addEvent('click', function windowClickCallback(e) {
					var target = e.target;
					if (el.contains(target)) return;
					el.tween('margin-top', -el.getSize().y);
					window.removeEvent('click', windowClickCallback);
				});
			}, 500);
		});
	});
})();

(function() {
	window.addEvent('domready', function() {
		/* Preload Background Hover for Main-Menu */
		var myImage = new Image;
		var livebox = $('livebox');
		var leftslider = $$('.content-left-slider');
		var rightslider = $$('.content-right-slider');
		myImage.src = 'typo3conf/ext/s2_template/base/gfx/dropdown-bg.png';
		
		 /* IE6 PNG Fixing  */
		
		if (Browser.ie6) {
			
			var moosizer = new mooSizer({ bgElement:'bg' });
			
			DD_belatedPNG.fix('.logo');
			DD_belatedPNG.fix('.content-top-bg-start');
			DD_belatedPNG.fix('.content-top-bg');
			DD_belatedPNG.fix('.box-title');
			DD_belatedPNG.fix('.login-box');
			DD_belatedPNG.fix('.livebox-bg');
			DD_belatedPNG.fix('.content-column-2-start clearfix');
			DD_belatedPNG.fix('.content-column-2');
			DD_belatedPNG.fix('.tip-top');
			DD_belatedPNG.fix('.tip');
			DD_belatedPNG.fix('.tip-bottom');
			DD_belatedPNG.fix('.weather-image');
			
		};
		
		/* Livebox Infos und Anlagen */
		if (!$('livebox')) return;
		$('livebox').store('status', 'closed');
		
		livebox.store('activePanel', 'right');
		leftslider.fade('in');
		rightslider.fade('out');
		
		livebox.addEvent('mouseenter', function(){
			livebox.set('tween', {duration: 500, transition: Fx.Transitions.Sine.easeOut});
			livebox.tween('margin-top', 0);
			livebox.store('status', 'open');
		})
		
		livebox.addEvent('mouseleave', function(){
			livebox.set('tween', {duration: 800, transition: Fx.Transitions.Sine.easeIn});
			livebox.tween('margin-top', -150);
			livebox.store('status', 'closed');
		})
		
		var liveboxInterval = setInterval(function(){
			if (livebox.retrieve('status') == 'closed') return;
			
			leftslider.fade($('livebox').retrieve('activePanel') == 'left' ? 'in' : 'out');
			rightslider.fade($('livebox').retrieve('activePanel') == 'left' ? 'out' : 'in');
			livebox.store('activePanel', $('livebox').retrieve('activePanel') == 'left' ? 'right' : 'left');
			
		}, 5000);
		
		/* Fade Transitions Livebox */
		leftslider.addEvent('mouseclick', function(){
			leftslider.fade('out');
			rightslider.fade('in').delay(500);
		})
		
		/* Tooltips */
		var myTips = new Tips('.tool-tip');
		
		myTips.addEvent('show', function(tip, el){
		    tip.fade('in'); 
		});
		myTips.addEvent('hide', function(tip, el){
		    tip.fade('out');
		});
	
	});
})();


/* Facebook Slider Box :: Iphone Optimierung */
(function() {
	window.addEvent('domready', function() {
		if (!$('facebook-slider-box')) return;
		$('facebook-slider-box').addEvent('click', function(){
			var el = this;
			this.set('tween', {duration: 800, transition: Fx.Transitions.Sine.easeIn});
			this.tween('margin-top', 0);
			this.store('status', 'open');
			setTimeout(function() {
				window.addEvent('click', function windowClickCallback(e) {
					var target = e.target;
					if (el.contains(target)) return;
					el.tween('margin-top', -el.getSize().y);
					window.removeEvent('click', windowClickCallback);
				});
			}, 500);
		});
	});
})();


/* Facebook Slider Box */
(function() {
	window.addEvent('domready', function() {	
		if (!$('facebook-slider-box')) return;
		var facebookbox = $('facebook-slider-box');
		facebookbox.store('status', 'closed');
			
		facebookbox.addEvent('mouseenter', function(){
			var facebookheight = facebookbox.getSize();
			facebookbox.set('tween', {duration: 500, transition: Fx.Transitions.Sine.easeOut});
			facebookbox.tween('margin-top', 0);
			facebookbox.store('status', 'open');
			$('facebook-slider-title').setStyle('top', facebookheight.y)
		})
		
		facebookbox.addEvent('mouseleave', function(){
			var facebookheight = facebookbox.getSize();
			facebookbox.set('tween', {duration: 800, transition: Fx.Transitions.Sine.easeIn});
			facebookbox.tween('margin-top', -facebookheight.y);
			facebookbox.store('status', 'closed');
			$('facebook-slider-title').setStyle('top', facebookheight.y)
		})
	});
})();

/* iPad/iPhone Hover Fix */
(function(){
	window.addEvent('domready', function() {	
		if(Browser.Platform.ios){
			var elements = $$('.navigation-main > li.if-sub');
			var subNavi = $$('.navigation-main-zone ul.navigation-sub-1');
			var lastIndex = 0;
			
			elements.addEvent('click', function(e){
				var columnIndex = elements.indexOf(this);
				this.addClass('hover');
				if (lastIndex != columnIndex) {
					subNavi[lastIndex].setStyle('display','none');
					subNavi[columnIndex].setStyle('display','block');
					elements[lastIndex].removeClass('hover');
					lastIndex = columnIndex;
				}
			});
		}
	});
})();
