var ziel = Array();
var pageid = 0;


dlhooks.push(function (){ eval_init(); })

	    	

function eval_init(){

	if($('eval_filter_land') && $('eval_filter_thema') && $('eval_filter_nummer')){
		
		var filter_land = $('eval_filter_land_list').effect('height', {duration: 600, transition: Fx.Transitions.Cubic.easeIn});
		var filter_thema = $('eval_filter_thema_list').effect('height', {duration: 600, transition: Fx.Transitions.Cubic.easeIn});
		var filter_nummer = $('eval_filter_nummer_list').effect('height', {duration: 600, transition: Fx.Transitions.Cubic.easeIn});
		
		ziel['ziel_land'] = $('eval_filter_land_list_content').offsetHeight+19;
		ziel['ziel_thema'] = $('eval_filter_thema_list_content').offsetHeight+19;
		ziel['ziel_nummer'] = $('eval_filter_nummer_list_content').offsetHeight+19;
		
		var act_land = "zu";
		var act_thema = "zu";
		var act_nummer = "zu";
		
		var act_bar = "";
		
		
		var filtervars = '';
		var suchwort = '';
		
		pageid = $('hiddenid').value;
		
		
		// --------- dev: open on load
		//$('eval_filter_open').setStyle('background-Position','0px -52px');
		//filter.start(0,ziel); 
		
		// Openbutton Events
		$('eval_filter_land').addEvents({
	    'mouseenter': function(){
	    	if($('eval_filter_land_list').getStyle('height') == '0px'){
	       $(this.id).setStyle('background-Position','0px -26px');
	      }
	    },
	    'mouseleave': function(){
	    	if($('eval_filter_land_list').getStyle('height') != ziel['ziel_land']+'px' && act_land == "zu"){
	       $(this.id).setStyle('background-Position','0px 0px');
	      }
	    },
	    'click': function(){
	    	
	    	if(ziel['ziel_land'] == 0) ziel['ziel_land'] = $('eval_filter_land_list_content').offsetHeight+19;
				
	    	// autoclose on open other
	    	if(act_nummer == "auf") {
	    		filter_nummer.start(ziel['ziel_nummer'],0); act_nummer = "zu"; 
	    		$('eval_filter_nummer').setStyle('background-Position','-181px 0px');
	    	}
	    	if(act_thema == "auf") {
	    		filter_thema.start(ziel['ziel_thema'],0); act_thema = "zu"; 
	    		$('eval_filter_thema').setStyle('background-Position','-84px 0px');
	    	}
	    	
	    	if($('eval_filter_land_list').getStyle('height') != ziel['ziel_land']+'px'){
	    		$(this.id).setStyle('background-Position','0px -52px');
	    		filter_land.start(0,ziel['ziel_land']); act_land = "auf";
	    	}else{
	    		$(this.id).setStyle('background-Position','0px -26px');
	    		filter_land.start(ziel['ziel_land'],0); act_land = "zu";
	    	}
	    }
		});
		
		$('eval_filter_thema').addEvents({
	    'mouseenter': function(){
	    	if($('eval_filter_thema_list').getStyle('height') == '0px'){
	       $(this.id).setStyle('background-Position','-84px -26px');
	      }
	    },
	    'mouseleave': function(){
	    	if($('eval_filter_thema_list').getStyle('height') != ziel['ziel_thema']+'px' && act_thema == "zu"){
	       $(this.id).setStyle('background-Position','-84px 0px');
	      }
	    },
	    'click': function(){
	    	
	    	if(ziel['ziel_thema'] == 0) ziel['ziel_thema'] = $('eval_filter_thema_list_content').offsetHeight+19;
				
	    	// autoclose on open other
	    	if(act_land == "auf") {
	    		filter_land.start(ziel['ziel_land'],0); act_land = "zu";  
	    		$('eval_filter_land').setStyle('background-Position','0px 0px');
	    	}
	    	if(act_nummer == "auf") {
	    		filter_nummer.start(ziel['ziel_nummer'],0); act_nummer = "zu"; 
	    		$('eval_filter_nummer').setStyle('background-Position','-181px 0px');
	    	}	    	
	    	
	    	if($('eval_filter_thema_list').getStyle('height') != ziel['ziel_thema']+'px'){
	    		$(this.id).setStyle('background-Position','-84px -52px');
	    		filter_thema.start(0,ziel['ziel_thema']); act_thema = "auf";
	    	}else{
	    		$(this.id).setStyle('background-Position','-84px -26px');
	    		filter_thema.start(ziel['ziel_thema'],0); act_thema = "zu";
	    	}
	    }
		});
		$('eval_filter_nummer').addEvents({
	    'mouseenter': function(){
	    	if($('eval_filter_nummer_list').getStyle('height') == '0px'){
	       $(this.id).setStyle('background-Position','-181px -26px');
	      }
	    },
	    'mouseleave': function(){
	    	if($('eval_filter_nummer_list').getStyle('height') != ziel['ziel_nummer']+'px' && act_nummer == "zu"){
	       $(this.id).setStyle('background-Position','-181px 0px');
	      }
	    },
	    'click': function(){
	    	
	    	if(ziel['ziel_nummer'] == 0) ziel['ziel_nummer'] = $('eval_filter_nummer_list_content').offsetHeight+19;
	    	
	    	// autoclose on open other
	    	if(act_land == "auf") {
	    		filter_land.start(ziel['ziel_land'],0); act_land = "zu"; 
	    		$('eval_filter_land').setStyle('background-Position','0px 0px');
	    	}
	    	if(act_thema == "auf") {
	    		filter_thema.start(ziel['ziel_thema'],0); act_thema = "zu"; 
	    		$('eval_filter_thema').setStyle('background-Position','-84px 0px');
	    	}
	    	
	    	if($('eval_filter_nummer_list').getStyle('height') != ziel['ziel_nummer']+'px'){
	    		$(this.id).setStyle('background-Position','-181px -52px');
	    		filter_nummer.start(0,ziel['ziel_nummer']); act_nummer = "auf";
	    	}else{
	    		$(this.id).setStyle('background-Position','-181px -26px');
	    		filter_nummer.start(ziel['ziel_nummer'],0); act_nummer = "zu";
	    	}
	    }
		});
		
		// Closebutton Events
		$('eval_filter_land_close').addEvents({
	    'click': function(){
	    	$('eval_filter_land').setStyle('background-Position','0px 0px');
	    	filter_land.start(ziel['ziel_land'],0); act_land = "zu";
	    }
	  });
	  
	  $('eval_filter_thema_close').addEvents({
	    'click': function(){
	    	$('eval_filter_thema').setStyle('background-Position','-84px 0px');
	    	filter_thema.start(ziel['ziel_thema'],0); act_thema = "zu";
	    }
	  });
	  
	  $('eval_filter_nummer_close').addEvents({
	    'click': function(){
	    	$('eval_filter_nummer').setStyle('background-Position','-181px 0px');
	    	filter_nummer.start(ziel['ziel_nummer'],0); act_nummer = "zu";
	    }
	  });
	  
	  
	  
	  
	  // Filterbuttons Events
		$$('.eval_opt').addEvents({
			 'mouseenter': function(){
			 	//alert($(this.id).getStyle('background-color'));
	    	if($(this.id).getStyle('background-color') == 'transparent') {
	       $(this.id).setStyle('background-color','#339933');
	       $(this.id).setStyle('color','#fff');
	      }
	    },
	    'mouseleave': function(){
	    	if($(this.id).getStyle('background-color') == '#339933' && act_bar != this.id) {
	       $(this.id).setStyle('background-color','transparent');
	       $(this.id).setStyle('color','#339933');
	      }
	     },
	    'click': function(){
	    	if(act_bar == this.id) {
	    		act_bar = '';
	    		if($("eval_downloads")) { 
	    			var parentList = $("eval_downloads").getParent();
	    			var grandparentList = $(parentList.id).getParent();
	    			$(grandparentList.id).setStyle('height',$(grandparentList.id).getStyle('height').toInt()-$("eval_downloads").offsetHeight.toInt());
	    			ziel[grandparentList.getProperty('class')] = $(grandparentList.id).getStyle('height').toInt();
	    			//console.log(ziel[grandparentList.getProperty('class')]);
	    			$("eval_downloads").remove();
	    		}
	    	}else{
	    		act_bar = this.id;
	    		ajaxRequest(this.id); 
	    		$$('.eval_opt').setStyle('background-color','transparent');
	       	$$('.eval_opt').setStyle('color','#339933');
	       	$(this.id).setStyle('background-color','#339933');
	        $(this.id).setStyle('color','#fff');
	    	}	    	
	    }
	  });
	  
	  // Filterinput Events
	  $('eval_search').addEvents({
	 	 'keyup': function(){
	 	 	suchwort = $('eval_search').value;
	 	 	
	 	 		if($('eval_filter_nummer_list').getStyle('height') == ziel['ziel_nummer']+'px'){
	    		$(this.id).setStyle('background-Position','-181px -26px');
	    		filter_nummer.start(ziel['ziel_nummer'],0); act_nummer = "zu";
	    	}
	 	 		if($('eval_filter_thema_list').getStyle('height') == ziel['ziel_thema']+'px'){
	    		$(this.id).setStyle('background-Position','-84px -26px');
	    		filter_thema.start(ziel['ziel_thema'],0); act_thema = "zu";
	    	}
	 	 		if($('eval_filter_land_list').getStyle('height') == ziel['ziel_land']+'px'){
	    		$(this.id).setStyle('background-Position','0px -26px');
	    		filter_land.start(ziel['ziel_land'],0); act_land = "zu";
	    	}
	 	 	
	 	 	ajaxRequest(suchwort);
	 	 },
	 	 'focus': function(){
	 	 	$('eval_search').value = '';
	 	 }
	  });
	  
	  // Filterinput Events
	  $$('.eval_download').addEvents({
	    'click': function(){
	    	var fid = this.id.split('eval_download_').join('');
	    	//alert('test');
	    	window.location="http://www.welthungerhilfe.de/"+pageid+".html?fid="+fid;
	    }
	  });
	}
}


function ajaxRequest(params)
{
	if($("eval_downloads2")) { 
		$("eval_downloads2").remove();
	}

	if($("eval_downloads")) { 
		var parentList = $("eval_downloads").getParent();
	  var grandparentList = $(parentList.id).getParent();
	  $(grandparentList.id).setStyle('height',$(grandparentList.id).getStyle('height').toInt()-$("eval_downloads").offsetHeight.toInt());
		ziel[grandparentList.getProperty('class')] = $(grandparentList.id).getStyle('height').toInt();
		$("eval_downloads").remove();
	}
	var ergebnis  = new Element('div', {id: 'eval_downloads'});
	ergebnis.setHTML('<div class="eval_loader"></div>');
	if($(params)) {
		ergebnis.injectAfter($(params));
		var parentList = $(params).getParent();
	  var grandparentList = $(parentList.id).getParent();
		$(grandparentList.id).setStyle('height',$(grandparentList.id).getStyle('height').toInt()+100+'px');
		ziel[grandparentList.getProperty('class')] = $(grandparentList.id).getStyle('height').toInt();
	}else{
		ergebnis.injectInside($('suchergebnis'));
	}

		
	
	var alias = $('eval_alias').value+'.html';
	var myAjax = new Ajax(alias+'?&ajax=true&params='+params, { 
		method: "post", 
		onComplete: function(html) {
			$("eval_downloads").innerHTML = html;
			//$("eval_filter_thema_list").setStyle('height') = $("eval_downloads").offsetHeight.toInt() + $("eval_filter_thema_list").getStyle('height').toInt()+'px';
			
			var parentList = $("eval_downloads").getParent();
			if(parentList.id != "suchergebnis")
			{
	    	var grandparentList = $(parentList.id).getParent();
	    	ziel[grandparentList.getProperty('class')] = $(grandparentList.id).getStyle('height').toInt()-100 + $("eval_downloads").offsetHeight.toInt();
				$(grandparentList.id).setStyle('height',ziel[grandparentList.getProperty('class')]+'px');
				
			}
			// Filterinput Events
			$$('.eval_download').addEvents({
	    'click': function(){
	    	var fid = this.id.split('eval_download_').join('');
	    	window.location="?fid="+fid;
	    }
	  });
		}
	}).request();
	
	
}

