zindex = 22;
timesST = "";
thatsouraccnum = new Array();
var Site = {
	
	start: function(){
		
		Site.appearText();
		
		if ($('kwick')) Site.parseKwicks();
		
		
	},
	
	parseKwicks: function(){
		var kwicks = $$('#kwick .kwick');
		var fx = new Fx.Elements(kwicks, {wait: false, duration: 200, transition: Fx.Transitions.quadOut});
		kwicks.each(function(kwick, i){
			kwick.addEvent('mouseover', function(e){
				e = new Event(e).stop();
				var obj = {};
				obj[i] = {
					'width': [kwick.getStyle('width').toInt(), 606]
				};
				kwicks.each(function(other, j){
					if (other != kwick){
						var w = other.getStyle('width').toInt();
						if (w != 10) obj[j] = {'width': [w, 10]};
					}
				});
				fx.start(obj);
			});
		});
		
		document.addEvent('mouseover', function(e){
			e = new Event(e);
			var rel = e.relatedTarget;
			if (!rel) return;
			if (rel.hasClass && (rel.hasClass('kwicks') || rel.hasClass('kwick') || rel.id == 'kwick')){
				var obj = {};
				kwicks.each(function(other, j){
					obj[j] = {'width': [other.getStyle('width').toInt(), 21]};
				});
				fx.start(obj);
			};
		});
	},
	
	appearText: function(){
		var timer = 0;
		var sideblocks = $$('#sidebar li');
		
		var slidefxs = [];
		var colorfxs = [];
		
		sideblocks.each(function(el, i){
			el.setStyle('margin-left', '-155px');
			timer += 150;
			
			

		}, this);
	}
};



window.addEvent('domready', Site.start);


function start () 
{
   reflekt();
   dragger();
   var periodHidin = function(){  hideTheBoxes(); };
	periodHidin.periodical(5000);
	Shadowbox.init();
  
}

window.onload = start;
function oeffnen(){
		draggables.setStyle('width', '785px');
}


function dragger(momDiv){
	/* setup draggables */
	var startNotice = function(e) {
		e.setStyle('z-index', zindex);
		zindex++
		var motherID = e.getParent('div').get('id');
		timesST = motherID;
	}
	
	var stopNotice = function(e) {
		//draggables.setStyle('z-index', '2');
		//e.setStyle('z-index', zindex);

	}

	var draggables = $$('.drag');
	draggables.each(function(el){
		var motherID = el.getParent('div').get('id');
		
		if(momDiv!=motherID) { 
		timesST[motherID] = new Date().getTime();
		
		}
		//el.addEvent("mouseenter", function() {
			//timesST[motherID] = "invulnerable";
		//});
	
		// make the box draggable using this handle
		el.makeDraggable({
			handle: el.getElements('.handle')[0],
			onStart: function(el) {
				
				startNotice(el); //notice box text
				}, 
			onComplete: function() {
				stopNotice(el); // stop the notice
				}
		});
		
		
	}); 	}

function hideTheBoxes() {

	$$('.drag').each(function(el){
							  
							  var motherID = el.getParent('div').get('id');
		
		if(timesST!=motherID) {
			ajaxpage('article1.php', 'c0'+el.getElements('.close')[0].get('href').replace(/.*c0(\d{1,4})'.*/i,"$1"),true);
			
		}
	});	
}

function accc(zahl){
			var myAcc = new Fx.Accordion($$('.toggle_'+zahl), $$('.art_'+zahl), {
    opacity: true, transition: Fx.Transitions.sineOut,
    onActive: function(myBox, i){
        myBox.removeClass('background').addClass('active');
		thatsouraccnum[zahl] = this.previous;
		if(this.previous!=0) {		makeScrollbar( $("innerc_"+zahl+'_'+this.previous), $('scrollbar_'+zahl+'_'+this.previous), $('scrollh_'+zahl+'_'+this.previous) );
		}
    },
    onBackground: function(myBox, i){
        myBox.removeClass('active').addClass('background');
    }  
});
	
	$$('#c0'+zahl+' .nextbut').addEvent("click",function() {
		
		
		if(myAcc.togglers.length>(thatsouraccnum[zahl]+1)) {
		thatsouraccnum[zahl] = thatsouraccnum[zahl]+1;
		myAcc.display(thatsouraccnum[zahl]);
		
		}
	});
	
	$$('#c0'+zahl+' .prevbut').addEvent("click",function() {
		//console.log(thatsouraccnum[zahl]);
		if(thatsouraccnum[zahl]>0) {
			thatsouraccnum[zahl] = thatsouraccnum[zahl]-1;
		myAcc.display(thatsouraccnum[zahl]);
		
		}
	});
	
	$$('#c0'+zahl+' .ivz_'+zahl).each(function(el,i) {
		el.addEvent("click",function(event) {
		event.stop();
		myAcc.display((el.get('rel')-1));
		});
		
		
	
	});
	
}
	
	

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid,xstatus){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
	if (page_request.readyState==4 && page_request.status==200)
    {
    loadpage(page_request, containerid,xstatus);
    }

}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid,xstatus){
	
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
document.getElementById(containerid).innerHTML=page_request.responseText

if(xstatus==false || typeof xstatus=="undefined" && xstatus!=true) {
	$$('#'+containerid+' .drag').setStyle("z-Index",zindex);
timesST = containerid;

dragger(containerid);
zindex++;

}
noSpam();

	if (containerid == "c01") {accc(1);}
	if (containerid == "c02") {accc(2);}
	if (containerid == "c03") {accc(3);}
	if (containerid == "c04") {accc(4);}
	if (containerid == "c05") {accc(5);}
	if (containerid == "c06") {accc(6);}
	if (containerid == "c07") {accc(7);}
	if (containerid == "c08") {accc(8);}
	if (containerid == "c09") {accc(9);}
	if (containerid == "c010") {accc(10);}
	if (containerid == "c011") {accc(11);}
	if (containerid == "c012") {accc(12);}
	if (containerid == "c013") {accc(13);}
	if (containerid == "c014") {accc(14);}
	if (containerid == "c015") {accc(15);}
	
	$('shadowbox_overlay').dispose();
	$('shadowbox_container').dispose();
	
var sboxload = function() { Shadowbox.init({
         skipSetup:      false, // skip the automatic setup
     }); }
sboxload.delay(1000);
	reflekt();}
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}	
}
}



function makeScrollbar(content,scrollbar,handle,heightx,horizontal,ignoreMouse){
	// alert(content.getScrollSize().y-content.getSize().y + " | " + content.getScrollSize().y + " | " + content.getSize().y);

	
	if ( content.getScrollSize().y-content.getSize().y > 0){
		if(Browser.Engine.trident==true) { scrollbar.setStyle('height', '100px');}
		
	
			scrollbar.fade(1);
			content.scrollTo(0,0);
			 scrollbar.scrollTo(0,0);
			var slider = new Slider(scrollbar, handle, {
				steps: 100,
				mode: (horizontal?'horizontal':'vertical'),
				onChange: function(step){
					// Scrolls the content element in x or y direction.
					var x = (horizontal?(((content.getScrollSize().x-content.getSize().x)/100)*step):0);
					var y = (horizontal?0:(((content.getScrollSize().y-content.getSize().y)/100)*step));
					content.scrollTo(x,y);
				}
			}).set(0);
		if( !(ignoreMouse) ){
			// Scroll the content element when the mousewheel is used within the
			// content or the scrollbar element.
			$$(content, scrollbar).addEvent('mousewheel', function(e){
				e = new Event(e).stop();
				var step = slider.step - e.wheel * 2;
				slider.set(step);
			});
		}
		// Stops the handle dragging process when the mouse leaves the document body.
		$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});

	}
	else {scrollbar.fade(0);}
}

function noSpam() {
    if (document.getElementById) {
		var at = "@";
	  	var links = document.getElementsByTagName('a');
	  
	  	for (var i = 0; i < links.length; i++) {
		  	var linkElem = links[i];
			
		  	if (linkElem.className == 'escape') {
		  		var mail = linkElem.firstChild; var domain = linkElem.lastChild;
		  		mail.nextSibling.firstChild.innerHTML = at;
		  		linkElem.href = "mailto:" + mail.data + at + domain.data;
		  	}
			
	  	} // End for
	  
    } // End if
}


// ohne Framework
//window.onload = noSpam;

// Prototype
//Event.observe(window, 'load', noSpam, false);

// Mootools
window.addEvent('domready', noSpam);

// jQuery
// $(document).ready(function() { noSpam() });

// YUI
//YAHOO.util.Event.onDOMReady(noSpam);

