//initialize date-picker for the submit-form (http://www.electricprism.com/aeron/calendar/):
window.addEvent('domready', function() { myCal = new Calendar({ startdate: 'd/m/Y', enddate: 'd/m/Y' }); });
window.addEvent('domready', function(){

	var vis_state;
	var tab_id;
// var mySlider: hide and show the layer with the travelconfig via slide-effect
	var mySlider = new Fx.Slide('container-travelconfigurator', {wait: false, mode: 'vertical', duration: 400, transition: Fx.Transitions.Circ.easeOut});
 mySlider.wrapper.setStyles({
		'visibility':'hidden',							
        'position': 'fixed',
        'top': 0
      });
// mySlider.wrapper.set('class', 'test');
// var myRequest: used for setting visibility-status in the FE-user-session at toggle-event (slide travelconfig up and down)
	var myRequest = new Request.HTML({method: 'get', url: '/?'});

	var img_toggle_res = new Array('fileadmin/templates/grafik/toggle_configurator.gif','fileadmin/templates/grafik/hide_configurator.gif');

//var img_toggle_res[0] = 'fileadmin/templates/grafik/toggle_configurator.gif'; 
//var img_toggle_res[1] = 'fileadmin/templates/grafik/hide_configurator.gif'; 

// var myVisibilityStatusRequest: used for getting visibility-status in the FE-user-session at page reload (should travelconfig-layer be shown or not?)
	var myVisibilityStatusRequest = new Request.HTML({method: 'get', url: '/?', onSuccess: function(response1,response2,response3,response4) {
	if(response3 == 0) {
		vis_state = 0;
		 mySlider.wrapper.setStyles({
'visibility':'visible'
      });
		$('container-travelconfigurator').set('styles', {visibility: 'visible'});
		mySlider.hide();
//		$('img-toggle-configurator').setProperty('src', img_toggle_res[0]);
		}
	else {
		vis_state = 1;
		mySlider.wrapper.setStyles({
			'visibility':'visible'
      		});
		$('container-travelconfigurator').set('styles', {visibility: 'visible'});
		mySlider.show();
//		$('img-toggle-configurator').setProperty('src', img_toggle_res[1]);
		}
	}
});

// var myTabStatusRequest: used for getting visibility-status in the FE-user-session at page reload (should travelconfig-layer be shown or not?)
	var myTabStatusRequest = new Request.HTML({method: 'get', url: '/?', onSuccess: function(response1,response2,response3,response4) {
		if (response3) {
			tab_id = response3;
		}
		else {
			tab_id = 'overview';
		}
//		alert(response3);
		// this request is used for updating the correct area in the correct tab (the previously selected tab before page reload) of the travelconfigurator
		new Request.HTML({method: 'get', 
						 	url: '/?', 
							update: $('tx-travelconfig-pi1-' + tab_id + '-my-journey'), 
							onComplete: function() {
			 								$('tx-travelconfig-pi1-' + tab_id + '-my-journey').removeClass('ajax-loading');
			 				}, 
			 				onRequest: function() {
											$('tx-travelconfig-pi1-' + tab_id + '-my-journey').addClass('ajax-loading');}}).send('eID=travelconfig&command=print_full_ses_data&tab_id=' + tab_id);
							}
						});

//call request
myTabStatusRequest.send('eID=travelconfig&command=get_config_status&code=tab_id');

//call request	
myVisibilityStatusRequest.send('eID=travelconfig&command=get_config_status&code=visibility');
	if($('tx_travelconfig_pi1_submit_form')) {
	$('tx_travelconfig_pi1_submit_form').addEvent('submit', function(e) {
				/**
				 * Prevent the submit event
				 */
				new Event(e).stop();
				var sender = new Request();
				sender.onSuccess=function(responseText, responseXML){log.set('html', responseText); log.removeClass('ajax-loading');};
				sender.send({data: this, url: this.get('action')});
				/**
				 * This empties the log and shows the spinning indicator
				 */
				var log = $('tx-travelconfig-pi1-form').empty().addClass('ajax-loading');
			});
	}//if

//$$('.toggle-travelconfigurator').each(function(button,i){
$$('.maptoggletravelconfigurator').each(function(button,i){
	button.addEvents({
	click: function(e){
	e.stop(); //prevents browser from doing default-behavior for links
//	alert('hello!');
//	myToggleStatusRequest.send();
	if(vis_state == 0) {
		vis_state = 1;
//		alert('hoho');
		//change picture of the button (if travelconfig is visible -> picture should show a "minus")
//		$('img-toggle-configurator').setProperty('src', img_toggle_res[1]);
		//change style of the wrapping a-tag to prevent the button from scrolling together with the content
//		$('toggle-travelconfigurator').set({'styles': {'position': 'fixed','left': '983px'}});
	}
	else {
		vis_state = 0;
		//change picture of the button (if travelconfig is visible -> picture should show a "plus")
//		$('img-toggle-configurator').setProperty('src', img_toggle_res[0]);
		//change style of the wrapping a-tag to make the button scroll together with the content		
//		$('toggle-travelconfigurator').set({'styles': {'position': 'relative','left': '0px'}});
	}
	myRequest.send('eID=travelconfig&command=set_config_status&show_tc=' + vis_state);
	mySlider.toggle();		
		}
	});
	});
});

