window.addEvent('domready', function() {
	
	//create our Accordion instance
	var myAccordion = new Fx.Accordion($('accordion1'), 'h3.toggler', 'div.element', {
		display: 0,
		show: 0,
		opacity: true,
		onActive: function(toggler, element){
			toggler.set('class', 'toggler active');
		},
		onBackground: function(toggler, element){
			toggler.set('class', 'toggler');
		}
	});
	//create our Accordion instance
	var myAccordion = new Fx.Accordion($('accordion2'), 'h3.toggler', 'div.element', {
		display: 0,
		opacity: true,
		onActive: function(toggler, element){
			toggler.set('class', 'toggler active');
		},
		onBackground: function(toggler, element){
			toggler.set('class', 'toggler');
		}
	});

	// NAVIGATION
	$$('#navi a').each(function(el) {
		//css
		var reset = false;
		var fx = new Fx.Tween(el,{
			duration: 500,
			link: 'cancel',
			onComplete:function() {
				if(reset) {
					el.setStyle('background-position','0 0');
				}
			}
		});
		var fx2 = new Fx.Tween(el,{
			duration: 500,
			link: 'cancel',
			onComplete:function() {
				if(reset) {
					el.setStyle('color','#363b31');
				}
			}
		});
		//events
		el.setStyle('background-position','0 0').addEvents({
			'mouseenter': function(e) {
				e.stop();
				fx.start('background-position','-185px 0');
				fx2.start('color','#FABB00');
				reset = false;
			},
			'mouseleave': function(e) {
				reset = true;
				fx.start('background-position','-400px 0');
				fx2.start('color','#363b31');
			}
		});
	});
    
    
	if ($('infobox')) {
	var tabs = new SimpleTabs($('infobox'), {
  		selector: '.tabh',
  		classMenu: 'tab-menu bggrey orange hl',
  		classContainer: 'tab-container bgorange'
		
 	});
 	}
 	// Declaring increment vars
var totIncrement = 0;
var increment = 900;
var maxRightIncrement = increment*(-7);
// FX var
var stabs = new Fx.Tween('slider-list', {
	duration: 500,
	transition: Fx.Transitions.Back.easeInOut,
	wait: true
	});

// Previous Button
$$('.prevp').addEvents({
	'click' : function(event){
		if(totIncrement<0){
			totIncrement = totIncrement + increment;
			//stabs.cancel();
			stabs.start('left',totIncrement);
		}
	}
});
$$('.prevp1').addEvents({
	'click' : function(event){
		if(totIncrement<0){
			totIncrement = increment*(-1);
			//stabs.cancel();
			stabs.start('left',totIncrement);
		}
	}
});

// Next Button
$$('.nextp').addEvents({
	'click' : function(event){
		if(totIncrement>maxRightIncrement){
			totIncrement = totIncrement - increment;
			//stabs.cancel();
			htmlupdate();
			stabs.start('left',totIncrement);
		}
	}
});

// Bestellung Ausgabe updaten
function htmlupdate(){
	
	var allesok = true;
    $('anschrift').empty(); 
	$('anschrift').innerHTML = $('firma').value + ' ' + $('vorname').value + ' ' + $('nachname').value + ' ' + $('adrzusatz').value + ' ' + $('strasse').value + ' ' + $('hausnr').value + ' ' + $('plz').value + ' ' + $('ort').value; 
	if ($('vorname').value.length < 3) allesok = false; 
    if ($('nachname').value.length < 3) allesok = false;
    if ($('strasse').value.length < 3) allesok = false;
    if ($('plz').value.length < 5) allesok = false;
    if ($('ort').value.length < 3) allesok = false;
    if ($('GebDatum').value.length < 8) allesok = false;
    $('kontakt').empty(); 
	$('kontakt').innerHTML = $('email').value + ' ' + $('teltag').value + ' ' + $('telabend').value + ' ' + $('HVorwahl').value + '/' + $('Handy').value;
	if ($('email').value.length < 5) allesok = false;
    if ($('kontonr').value.length < 5 || $('blz').value.length < 8) allesok = false;
    
    $('stnr2').empty(); 
	$('stnr2').innerHTML = $('stnr').value;
	$('bank').empty(); 
	$('bank').innerHTML = 'Konto ' + + $('kontonr').value + ' ' + $('blz').value + ' (' + $('bankname').value + '), Inhaber: ' + $('kontoinhaber').value;
	$('rech').empty(); 
	if ($('perpost').value.toInt() == 1) $('rech').innerHTML = 'per Post als Brief - mtl. zzgl. 3 Euro';
	else $('rech').innerHTML = 'zum Download als PDF - gratis';
	
    var t = {};
    $('optionen').empty(); 
	
    $$('#moreoptions input').each(function(el){
    if (el.checked) $('optionen').innerHTML += el.value + ', ';
    });
    
	    
    if ($('agbs').checked == true) { 
		$('agbs2').innerHTML = 'gelesen und akzeptiert'; 
		}
	else { 
		$('agbs2').innerHTML = '<span class="red">Bitte lesen und akzeptieren!</span>';
        allesok = false; 
		}
	if (allesok) { $('bestellen').setStyle('visibility','visible');$('hinweise').setStyle('visibility','hidden'); }
    else { $('bestellen').setStyle('visibility','hidden'); $('hinweise').setStyle('visibility','visible'); }
	
};



});

