/* Kod wykonywany przy ładowaniu strony */
window.addEvent("load",function(){
	/* Dodanie efektu slide przy przewijaniu */
	new SmoothScroll({duration: animation_speed_slide});
	
	/* utworzenie efektów opacity dla elementów membersarea */
	stylebox_transparent = new Fx.Opacity('stylebox',{duration: animation_speed_usermenu});
	loginbox_transparent = new Fx.Opacity('loginbox',{duration: animation_speed_usermenu});
	
	/* pokazanie elementów membersarea (wcześniej są ukryte przez CSS by nie było efektu mignięcia)  */
	$('stylebox').setStyle('display','block');
	$('loginbox').setStyle('display','block');
	
	/* Ukrycie elementów membersarea */
	stylebox_transparent.hide();
	loginbox_transparent.hide();
	
	/* Załadowanie domyślnych efektów pokazywania/ukrywania headera */
	transIn = Fx.Transitions.bounceOut;
	transOut = Fx.Transitions.elasticOut;
	
	/* Pobranie z cookie informacji o wybranej przez użytkownika animacji */
	if( Cookie.get('header_anim') === '1' || Cookie.get('header_anim') === '2' || Cookie.get('header_anim') === '3' ){
		var h_status = Cookie.get('header_anim');
		/* odpowiednie ustawienie typów animacji w zależności od wyboru użytkownika */
		switch(h_status){
			case '1':transIn=Fx.Transitions.bounceOut;transOut=Fx.Transitions.elasticOut;break;
			case '2':transIn=Fx.Transitions.quintOut;transOut=Fx.Transitions.quintOut;break;
			case '3':transIn=Fx.Transitions.bounceOut;transOut=Fx.Transitions.bounceOut;break;
		}
	}
	
	/* efekt zwijania headera */
	if($('spotlight')){
	
	spotlight_heightIn = new Fx.Height('spotlight',{
		duration: animation_speed_header,
		wait: true,
		transition: transIn
	});
	
	/* efekt rozwijania headera */
	spotlight_heightOut = new Fx.Height('spotlight',{
		duration: animation_speed_header,
		wait: true,
		transition: transOut
	});
	
	}
	
	/* dodanie zdarzenia onclick do buttontools */
	$('buttontools').addEvent('click',function(event){
		var event = new Event(event);
		event.preventDefault();
		/* pokazanie / ukrycie bloków membersarea */
		tools_transparent();
	});
	
	if($('spotlight')){
	
	/* Dodanie zdarzeń onclick do strzałek rozwijających / zwijających header */
	$('arrow-a').addEvent('click',function(event){
		var event = new Event(event);
		event.preventDefault();
		/* zwijanie headera */
		header_zwijanie();
	});
	
	$('arrow-b').addEvent('click',function(event){
		var event = new Event(event);
		event.preventDefault();
		/* rozwijanie headera */
		header_rozwijanie();
	});
	
	/* Dodanie zdarzeń onclick do przycisków wyboru animacji headera */
	$('anim-1').addEvent('click',function(event){
		var event = new Event(event);
		event.preventDefault();
		
		/* wysłanie cookie z ustawieniem pokazywania headera */
		Cookie.set('header_anim','1',{path: "/"});
		
		transIn=Fx.Transitions.bounceOut;
		transOut=Fx.Transitions.elasticOut;
		
		/* Nowe definicje obiektów ukrywajacych / pokazujacych header */
		spotlight_heightIn = new Fx.Height('spotlight',{
			duration: animation_speed_header,
			wait: true,
			transition: transIn
		});
	
		spotlight_heightOut = new Fx.Height('spotlight',{
			duration: animation_speed_header,
			wait: true,
			transition: transOut
		});
		
		header_menu_s();
	});
	
	$('anim-2').addEvent('click',function(event){
		var event = new Event(event);
		event.preventDefault();
		/* wysłanie cookie z ustawieniem pokazywania headera */
		Cookie.set('header_anim','2',{path: "/"});
		
		transIn=Fx.Transitions.quintOut;
		transOut=Fx.Transitions.quintOut;
		
		/* Nowe definicje obiektów ukrywajacych / pokazujacych header */
		spotlight_heightIn = new Fx.Height('spotlight',{
			duration: animation_speed_header,
			wait: true,
			transition: transIn
		});
	
		spotlight_heightOut = new Fx.Height('spotlight',{
			duration: animation_speed_header,
			wait: true,
			transition: transOut
		});	

		header_menu_s();
	});
	
	$('anim-3').addEvent('click',function(event){
		var event = new Event(event);
		event.preventDefault();
		
		/* wysłanie cookie z ustawieniem pokazywania headera */
		Cookie.set('header_anim','3',{path: "/"});
		
		transIn = Fx.Transitions.bounceOut;
		transOut = Fx.Transitions.bounceOut;
		
		/* Nowe definicje obiektów ukrywajacych / pokazujacych header */
		spotlight_heightIn = new Fx.Height('spotlight',{
			duration: animation_speed_header,
			wait: true,
			transition: transIn
		});
	
		spotlight_heightOut = new Fx.Height('spotlight',{
			duration: animation_speed_header,
			wait: true,
			transition: transOut
		});	
		
		header_menu_s();
	});
	
	/* Utworzenie efektów dla menu wyboru animacji */
	header_menu_effect1 = new Fx.Opacity('animwrap');
	header_menu_effect2 = new Fx.Height('animwrap');
	
	/* pokazanie ukrytego przez CSS wrappera animacji */
	$('animwrap').setStyle('display','block');
	
	/* ukrycie wrappera animacji */
	header_menu_effect1.hide();
	header_menu_effect2.hide();
	
	/* Dodanie zdarzenia onclick do przycisku menu animacji  */
	$('animwrap-button').addEvent('click',function(event){
		var event = new Event(event);
		event.preventDefault();
		header_menu_s();
	});
	
	/* Pobieranie informacji o pokazywaniu / ukrywaniu headera */
	if( Cookie.get('header_status') === '0' || Cookie.get('header_status') === '1' ){
		var h_status = Cookie.get('header_status');
		/* Pokazywanie odpowiednich strzałek w zależności od statusu headera */
		if(h_status === '1'){
			$('arrow-b').setStyle('display','none');
			$('spotlight').setStyle('display','block');
		}
		else{
			$('arrow-a').setStyle('display','none');
			$('spotlight').setStyle('display','block');
			spotlight_heightIn.hide();
			spotlight_heightOut.hide();
		}
	}
	else{
		$('arrow-b').setStyle('display','none');
		$('spotlight').setStyle('display','block');
	}
	
	}
});

/* funkcja pokazywania / ukrywania bloków w membersarea */
function tools_transparent(){
	$('buttontools').removeEvents('click');
	
	/* ukrycie bloków membersarea */
	stylebox_transparent.toggle();
	loginbox_transparent.toggle();
	
	/* Zabezpieczenie przed klikaniem podczas wykonywania efektu */
	$('buttontools').addEvent('click',function(event){
		var event = new Event(event);
		event.preventDefault();
		tools_transparent();
	});
}

/* Funkcja zwijająca header */
function header_zwijanie(){
	spotlight_heightIn.toggle();
	
	var arrowa = $('arrow-a'); 
	
	/* stworzenie nowego elementu tła strzałek */
	var arrowa2 = new Element('a');
	arrowa2.setProperties({
		href: '#',
		id: 'arrow-a2'
	});
	
	/* kopiowanie nowopowstałego elementu */
	var klon2 = arrowa2.clone();
	
	/* umieszczenie kopii w dokumencie */
	klon2.injectInside(document.body);
	
	/* zamiana kopii z oryginałem */
	$('arrow-a').replaceWith('arrow-a2');
	
	/* dodanie zdarzenia onclick */
	$('arrow-a2').onclick = function(event){
		var event = new Event(event);
		event.preventDefault();
	};
	
	/* zamiana kopii na oryginał po określonym przez użytkownika czasie */
	(function(){$('arrow-a2').replaceWith(arrowa)}).delay(animation_speed_header);
	
	/* pokazywanie odpowiednich strzałek gdy header jest zwinięty */
	(function(){var h = $('spotlight').getStyle('height').toInt();
	if(h == 0 || h == '0'){
		$('arrow-a').setStyle('display','none');
		$('arrow-b').setStyle('display','block');
	}}).delay(animation_speed_header+10);
	
	/* wysłanie cookie z informacją o statusie headera */
	Cookie.set('header_status','0',{path: "/"});
}

/* Funkcja rozwijająca header */
/* analogiczne działanie do funkcji poprzedniej */
function header_rozwijanie(){
	spotlight_heightOut.toggle();

	var arrowb = $('arrow-b'); 
	var arrowb2 = new Element('a');
	arrowb2.setProperties({
		href: '#',
		id: 'arrow-b2'
	});
	
	var klon2 = arrowb2.clone();
	
	klon2.injectInside(document.body);
	
	$('arrow-b').replaceWith('arrow-b2');
	
	$('arrow-b2').onclick = function(event){
		var event = new Event(event);
		event.preventDefault();
	};
	
	(function(){$('arrow-b2').replaceWith(arrowb)}).delay(animation_speed_header);
	
	(function(){var h = $('spotlight').getStyle('height').toInt();
	if(h != 0 || h != '0'){
		$('arrow-b').setStyle('display','none');
		$('arrow-a').setStyle('display','block');
	}}).delay(animation_speed_header+10);
	
	Cookie.set('header_status','1',{path: "/"});
}

/* Funkcja pokazująca / ukrywająca menu animacji */

function header_menu_s(){
	/* Pokazanie / ukrycie menu animacji */
	header_menu_effect1.toggle();
	header_menu_effect2.toggle();
}
