// No More IE6 Background Flicker - http://www.hedgerwow.com/360/bugs/dom-fix-ie6-background-image-flicker.html
(function(){ /*Use Object Detection to detect IE6*/ var m = document.uniqueID /*IE*/ && document.compatMode /*>=IE6*/ && !window.XMLHttpRequest /*<=IE6*/ && document.execCommand ; try{ if(!!m){ m("BackgroundImageCache", false, true) /* = IE6 only */ } }catch(oh){}; })();
// Load Function on DOM.Contentload - crossbrowser
function onContent(f){//(C)webreflection.blogspot.com
var b=navigator.userAgent,d=document,w=window,
c="__onContent__",e="addEventListener",o="opera",r="readyState",
s="<scr".concat("ipt defer src='//:' on",r,"change='if(this.",r,"==\"complete\"){this.parentNode.removeChild(this);",c,"()}'></scr","ipt>");
w[c]=(function(o){return function(){w[c]=function(){};f(o?o():o)}})(w[c]);
if(d[e])d[e]("DOMContentLoaded",w[c],false);
if(/WebKit|Khtml/i.test(b)||(w[o]&&parseInt(w[o].version())<9))
(function(){/loaded|complete/.test(d[r])?w[c]():setTimeout(arguments.callee,1)})();
else if(/MSIE/i.test(b))d.write(s);
};
/*
addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
*/
function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

Position.getPageSize = function() {
  var xScroll, yScroll;

  if (window.scrollMaxX) {  
    xScroll = window.innerWidth  + window.scrollMaxX;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else {
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  } 
  
  var windowWidth, windowHeight;
  if (self.innerHeight) { // all except Explorer
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }
  // for small pages with total height less then height of the viewport
  pageHeight = Math.max(windowHeight, yScroll);

  // for small pages with total width less then width of the viewport
  pageWidth = Math.max(windowWidth, xScroll);

  return { page: { width: pageWidth, height: pageHeight }, window: { width: windowWidth, height: windowHeight } };
}

var Sshow = {
	currentStat: 0,
	init: function() {
		Sshow.container = $('slidercontainer');
		Sshow.currentimage = $('currentimg');
		Sshow.changeimage = 'changeimg';
		Sshow.createIMG();
		if(Sshow.currentimage.hasClassName('none')) {
			Sshow.currentimage.hide();
		    Sshow.currentimage.removeClassName('none');
			new Effect.Appear(Sshow.currentimage, { 
			  duration: 3, 
			  afterFinish: function() { 
				$(Sshow.changeimage).style.display = 'block';						  
			  } 
			});
		} else {
			$(Sshow.changeimage).style.display = 'block';						  
		}
		Sshow.Request();
	},
	createIMG: function() {
		var objContainer = Sshow.container;
		var objImage = document.createElement("img");
		objImage.setAttribute('id',Sshow.changeimage);
		objImage.style.display = 'none';			
		objContainer.appendChild(objImage);		
	},	
	start: function() {
		imgArray.push(Sshow.currentimage.src);
		Sshow.setcurrent();		
  	    new PeriodicalExecuter(Sshow.cycle, 5); // change image every 5 seconds 
	},	
	cycle: function() { 
		new Effect.Fade(Sshow.currentimage, { 
		  duration: 1, 
		  afterFinish: function() { 
				Sshow.currentimage.src = Sshow.currentimg;
				window.setTimeout("Element.show(Sshow.currentimage)", 300);
				window.setTimeout("Sshow.setcurrent()", 500);
		  } 
		});
	},	
	preLoad: function() { 
		var imgPreloader = document.createElement('img');
		imgPreloader.setAttribute('src',Sshow.preloadimg);
	},
	setcurrent: function() { 
		if (Sshow.currentStat < Sshow.imgsum) {
			Sshow.currentStat = Sshow.currentStat+1;
		} else {
			Sshow.currentStat = 0;
		}
		Sshow.currentimg = Sshow.imgArray[Sshow.currentStat];
		Sshow.preloadimg = Sshow.imgArray[Sshow.currentStat+1];
		Sshow.preLoad();
		$(Sshow.changeimage).setAttribute('src', Sshow.currentimg);
	},
	Request: function(){
		new Ajax.Request('/tools/xml.php', {
			method: 'post',
			postBody: postVariable,
			onComplete:function(req){	
				 Sshow.imgArray = Sshow.setDataXML(req.responseXML);
				 Sshow.imgsum = Sshow.imgArray.length;
				 if(Sshow.imgArray.length>=1) {
					 Sshow.start();
				 }
			}
		});
	},
	setDataXML: function(responseXML){
		var imgArrayXML = responseXML.getElementsByTagName('gallery')[0].getElementsByTagName('image');
		imgArray = [];
		for (var i=0;i<imgArrayXML.length;i++)
		{
			imgArray.push(imgArrayXML[i].getAttribute('path'));
		}
		return imgArray;
	}
};


var enableLink = {
	init: function(restart){
		clickstate = true;
		$('c-content').getElementsByClassName('slider').each(function(link){
			var itemNext = link.nextSibling;
			if(itemNext.tagName == "DIV") {
				if(!restart) {
					itemNext.hide();
					if(itemNext.hasClassName('none') == true) {
						itemNext.removeClassName('none');
					}
				}
				Event.observe(link,'click',function(event){
				 Event.stop(event);
				 if(clickstate == true) {
					enableLink.SliderHideOpen(link);
				 }
				});	
			}
		});	
		$('c-content').getElementsByClassName('fullpage').each(function(link){
				Event.observe(link,'click',function(event){
				 Event.stop(event);
				 if(clickstate == true) {
					enableLink.FPstart(link.href);
				 }
				});
		});	
		if(!restart) {
			$('c-snav').getElementsByClassName('fullpage').each(function(link){
					Event.observe(link,'click',function(event){
					 Event.stop(event);
					 if(clickstate == true) {
						enableLink.FPstart(link.href);
					 }
					});
			});	
		}
	},
	SliderHideOpen: function(element){
		clickstate = false;	
		chide = $('c-content').getElementsByClassName('stat');
		cshow = element.next();
		if(chide.length == 0) {
			element.remove();
			new Effect.Parallel(
			[ new Effect.BlindDown(cshow, {sync: true }), 
			  new Effect.Appear(cshow, { sync: true} ) 
			], { duration: 1,
				 afterFinish: function() {
//					cshow.addClassName('stat');
					clickstate = true;	
				 }
			   }
			);		
		} else if(cshow.hasClassName('stat') == true) {
			new Effect.Parallel(
			[ new Effect.BlindUp(cshow, {sync: true }), 
			  new Effect.Fade(cshow, { sync: true} )
			], { duration: 1,
				 afterFinish: function() {
					cshow.removeClassName('stat');
					clickstate = true;	
				 }
			   }
			);		
		} else {
			new Effect.Parallel(
			[ new Effect.BlindDown(cshow, {sync: true }), 
			  new Effect.Appear(cshow, { sync: true} ),
			  new Effect.BlindUp(chide[0], {sync: true }), 
			  new Effect.Fade(chide[0], { sync: true} )
			], { duration: 1,
				 afterFinish: function() {
					chide[0].removeClassName('stat');
					cshow.addClassName('stat');
					clickstate = true;	
				 }
			   }
			);		
		}
	},
	Request: function(href){
		new Ajax.Request(href, {
			method: 'post',
			postBody: 'ajax=1',			
			onComplete:function(req){	
			enableLink.newHtml = req.responseText;
//			alert(enableLink.newHtml);
//			enableLink.newHtml = "das ist der neue text";
			}
		});
	},
	FPstart: function(href){
		clickstate = false;
		enableLink.Request(href);
		var sheight = $('c-main').getHeight();
		var cheight = $('c-content').getHeight();
		$('c-sidebar').setStyle({'height': sheight+'px', 'position':'absolute'});
		$('c-main').setStyle({'background-position': '0 0'});
		$('c-content').setStyle({'height': cheight+'px','width': '29.17em'});
		var v = Position.getPageSize();
		xpos = v.window.width/2;
		new Effect.Parallel(
			[ new Effect.Move('c-sidebar', {x: -xpos, y: 0, mode: 'absolute', sync: true }),
			  new Effect.Fade('c-sidebar', { sync: true}),
			  new Effect.Morph('c-content', {style:'opacity:0;width:60em;', sync: true })
			], { duration: 2,
				 beforeStart: function() {
					if($('request')) {
						$('request').style.display = "none";
					}					 
				 },
				 afterFinish: function() {
					$('c-content').setStyle({'height':'auto'});
					var objBack = document.createElement("div");
					objBack.setAttribute('id','fullpageBackJS');
					objBack.className = 'fpback';
					objBack.style.display = 'none';
					objBack.onclick = function() { 
						if (clickstate == true) {enableLink.FPstop();}
					}
//					objBack.innerHTML = 'Zurück';
					objBack.innerHTML = $('fullpageBack').firstChild.innerHTML;
					$('c-main').appendChild(objBack);		
					 enableLink.currentHtml	= $('c-content').innerHTML;
					 $('c-content').update(enableLink.newHtml);
					new Effect.Parallel(
						[ new Effect.Appear('c-content', {sync: true}),
						  new Effect.Appear('fullpageBackJS', {sync: true})
						], { duration: 1, 
							 afterFinish: function() {
									clickstate = true;
									$('c-content').style.opacity = "1.0";
							 }
						 	}
					 );
				 }
			   }
		);		
	},
	FPstop: function(){
		clickstate = false;
//		alert('jetzt wieder zurück');
		var sheight = $('c-main').getHeight();
		$('c-main').setStyle({'height': sheight+'px', 'overflow': 'hidden'});
		$('c-sidebar').setStyle({'height': sheight+'px'});
		new Effect.Parallel(
			[ new Effect.Move('c-sidebar', {x: 0, y: 0, mode: 'absolute', sync: true }),
			  new Effect.Appear('c-sidebar', { sync: true}),
			  new Effect.Fade('fullpageBackJS', { sync: true}),
			  new Effect.Morph('c-content', {style:'opacity:0;width:29.17em;', sync: true })
			], { duration: 2,
				 afterFinish: function() {
					$('c-main').setStyle({'background-position': '39em 0', 'overflow': 'visible'});
					$('fullpageBackJS').remove();	
//					$('c-sidebar').setStyle({'float': 'left'});
					$('c-content').update(enableLink.currentHtml);
//					$('c-content').innerHTML = enableLink.currentHtml;
//					$('c-main').setStyle({});
//					var sheight = $('c-main').getHeight();
//					alert(sheight);
//					$('c-sidebar').setStyle({'height': sheight+'px'});
					new Effect.Appear('c-content', {duration: 1, 
							 afterFinish: function() {
									enableLink.init(true);
									$('c-sidebar').setStyle({'height': 'auto'});
									$('c-main').setStyle({'height': ''});
									$('c-content').style.opacity = "1.0";
									if($('request')) {
										$('request').style.display = "block";
									}
							 }
					});
				 }
			   }
		);		
		
	}
}


if (!IEold) {
addEvent(window,'load', function(){enableLink.init();});
addEvent(window, 'load', function(){Sshow.init();});
}
