 
// 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;
	}
}

function printPage(lightbox) {
	$$('#c-content .button').each(function(link){
		var itemNext = link.next();
		if(itemNext.tagName == "DIV") {
			itemNext.show();
		}
	});	
	$('headerimage').show();
	if(lightbox == true) {
	$('lightbox').style.display = 'block';
	$('lightboxImage').style.opacity = '1.0';
	}
	window.print();
}

function enableButtons() {
    clickstate = true;
	$$('#c-content .button').each(function(link){
		var itemNext = link.next();
		if(itemNext.tagName == "DIV") {
			itemNext.hide();
			if(itemNext.hasClassName('none') == true) {
				itemNext.removeClassName('none');
			}
			Event.observe(link,'click',function(event){
			 Event.stop(event);
			 if(clickstate == true) {
			 	hideOpen(link);
			 }
			});	
		}
	});	
	if($('ctop')) {
	Event.observe('ctop','click',function(event){
		Event.stop(event);
		new Effect.ScrollTo('c-parent');
	});
	}
}
function hideOpen(element) {
    clickstate = false;	
	chide = $('c-content').getElementsByClassName('stat');
	cshow = element.next();
	if(chide.length == 0) {
		new Effect.Parallel(
		[ new Effect.BlindDown(cshow, {sync: true }), 
		  new Effect.Appear(cshow, { sync: true} ) 
		], { duration: 1,
			 afterFinish: function() {
				cshow.addClassName('stat');
    			clickstate = true;	
				//cshow.setStyle({'position': 'relative'});
			 }
		   }
		);		
	} 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;	
			 }
		   }
		);		
	}
//	.style.position = 'relative';	
//$$('#c-content ul li').each.setStyle({'position': 'relative'});

}
function createImg(element) {
		var objImg = document.createElement("img");
		objImg.setAttribute('class','imgstat w270');
		objImg.setAttribute('alt', element.getAttribute('title'));
		objImg.setAttribute('src', element.getAttribute('href'));
		objImg.setAttribute('src', element.getAttribute('href').replace(/\/html/, ""));
		objImg.style.display = 'none';
		element.appendChild(objImg);
		return objImg;
}

var Sshow = {
	currentStat: 0,
	init: function() {
		Sshow.container = $('headercontainer');
		Sshow.currentimage = $('headerimage');
		Sshow.changeimage = 'headerimage2';
		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;
	}
};


if (!IEold) {
addEvent(window,'load',enableButtons);
addEvent(window, 'load', function(){Sshow.init();});
}
