var aktuelle_box = 1;
var anzahl_boxen = 10;
var box_hoehe = new Array();
var box_hoehe_max = 0;
var box_id = "";

window.addEvent('load', function() {
			
	if(document.location.search.indexOf("PRINTPREVIEW") > -1)
	{
		/*console.log("TEST");*/
		ss = document.getElementsByTagName("link");
		for(var i in ss)
		{
			if(typeof ss[i].media == "string" && ss[i].media.indexOf("screen") > -1)
			{
				ss[i].href = "/fileadmin/styles/print.css";
			}
			else if(typeof ss[i].media == "string" && ss[i].media.indexOf("print") > -1)
			{
				//nix machen...
			}
		}
	}
	
	
	
	if($('scrollbar'))
	{
		
		/*var maxheight = $('sb_text_1').offsetHeight+147;
		for(var i = 2; i <= $('spbsplength').value; i++)
		{
			$('sb_text_'+i).setStyle('display','block');
			if($('sb_text_'+i).offsetHeight+147 > maxheight) {
				maxheight = $('sb_text_'+i).offsetHeight+147;
			}
			$('sb_text_'+i).setStyle('display','none');
		}
		$('spendenbeispiel').setStyle('height',maxheight);
		*/
		var ael = $('scrollbar');
		new Slider(ael, ael.getElement('.slider'), {
			steps: ($('spbsplength').value),
			offset: ((Math.floor((217/$('spbsplength').value )/2)-12)*-1),
			//snap: true,
			onChange: function(value){
				if(value != $('spbsplength').value)
				{
					showSB(value+1);
				}
			}
		}).set(0);
	}
	
	if($('box_container'))
	{
		var aktdia = 1;
		var anzdia = $('spbsplength').value;
		var direction = "forward";
		var Diashow = startDiashow.periodical(6000);
	}
	function startDiashow()
	{
		if(direction == "forward")
		{
			boxforward(); aktdia++; if(aktdia == anzdia) { direction = "backward"; }
		}
		else if(direction == "backward")
		{
			boxbackward(); aktdia--; if(aktdia == 1) { direction = "forward"; }
		}
	}
	
	// Remove Blur
	removeBlur();

});



function showSB(bsp)
{
	$$('#spendenbeispiel .sb_image').setStyle('display','none');
	$('sb_image_'+bsp).setStyle('display','block');
	$$('#spendenbeispiel .sb_text').setStyle('display','none');
	$('sb_text_'+bsp).setStyle('display','block');
	$$('#spendenbeispiel .sb_betrag').setStyle('font-weight','normal');
	$('sb_betrag_'+bsp).setStyle('font-weight','bold');

}

launchPV = function()
{
	var l = window.location;
	var s = l.search+"";
	l = l+"";
	l += (s.length>0?"&":"?") + "PRINTPREVIEW=true";
	window.open(l);
}

setFS = function(ipt)
{
	var mxfs = 16;
	var mnfs = 8;
	
	var elem = $('content');
	
	if(!elem)
	{
		var elem = $('content_sub');
	}
	
	var myFS = parseFloat(elem.style.fontSize) || 12;
	
	

	var newFS = myFS + ipt * 10;
	var myFS = ipt==null?mnfs:newFS > mxfs?mxfs:newFS < mnfs?mnfs:newFS;

	if(!ipt)
	{
		elem.style.fontSize = 12 + "px";
	}
	else
	{
		elem.style.fontSize = myFS + "px";
	}
}

function boxforward() {
	
	var anotherEl = $('termin_movebox');
	var morph = new Fx.Morph('anotherElement');
	if(aktuelle_box < anzahl_boxen)
	{
		var dawn = (aktuelle_box)*(-217);
		anotherEl.tween('left', dawn);
		aktuelle_box++;
	}
}

function boxbackward() {
	
	var anotherEl = $('termin_movebox');
	var morph = new Fx.Morph('anotherElement');
	if(aktuelle_box > 1)
	{
		var dawn = (aktuelle_box-2)*(-217);
		anotherEl.tween('left', dawn);
		aktuelle_box--;
	}
}


removeBlur = function()
{
			$$("a").addEvents({'focus': function(e) {
				this.blur();
			}
			});
}

// Fix für den Link "zum Bestellformular" im Shop der Roten Schleife
scrollToDiv = function()
{
	var myFx = new Fx.Scroll(window,{duration:0}).toElement("spendenformular");
}

var schalter = false;
var css = new CSS();
kontrast = function()
{	
	if(schalter == false)
	{
		schalter = true;
		css.add_rules({
		    'body,p':
		    {
		        'background': '#000',
		        'color':'#ffffff'
		    },
		    'a, #content_sub h1, #content_sub h2, #content h1, #content h2':
		    {
		    	'color':'#ffffff'
		    },
		    '#sub_navi a':
		    {
				'color':'#fff'
			 },
			 '#container #page_container #navi_headerpic_logo #header_navi, #container #page_container #main_navi_container #main_navi':
			 {
			  	'background':'#000000'
			 },
			 '#navi_headerpic_logo #header_navi a, #main_navi_container #main_navi a':
			 {
			 	'color':'#fff'
			 },
			 '.spendenbox .spendenbox_kommtan, .newstermine .newsterminzeile .newsterminheader':
			 {
			 	'color':'#000'	
			 }
		    
		}).refresh();	
	}
	else
	{
		schalter = false;
		css.add_rules({
		    'body,p':
		    {
		        'background': '#fff',
		        'color':'#000'
		    },
		    'a, #content_sub h1, #content_sub h2, #content h1, #content h2':
		    {
		    	'color':'#000'
		    },
		    '#sub_navi a':
		    {
				'color':'#000'
			 },
			 '#container #page_container #navi_headerpic_logo #header_navi, #container #page_container #main_navi_container #main_navi':
			 {
			  	'background':'#fff',
			  	'color':'#000'
			 },
			 '#navi_headerpic_logo #header_navi a, #main_navi_container #main_navi a':
			 {
			 	'color':'#000'
			 },
			 '.spendenbox .spendenbox_kommtan, .newstermine .newsterminzeile .newsterminheader':
			 {
			 	'color':'#000'	
			 }
		   
		}).refresh();
	}
}

function printme(text){
	text=document;
	print(text);
	//document.print();
	}
