/**
 * Functions for making the vacancies filter work.
 *
 * @copyright Adrian Foeder <a.foeder@iveins.de>
 * @since 06.08.2008
 */




function init_filterboxes(parms)	{
	var ctr=0;

	//clear all boxes (just to go sure...):
	$(document.body).getElement('div.tx-sbstellenangebote-pi3 ul').empty();

	$each(tx_sbstellenangebote_pi3_filterItems, function(expElem,expIndex){
		currentLi = new Element('li',{
				'html':expIndex,
				//'class':(expIndex==parms.selExpertise?'selected':''),
				'events': {
					'click': function(){
						//remove all "parent's child's" (siblings and me) selected-state:
						this.getParent().getChildren('li').removeClass('selected');
						//and set mine state selected:
						this.addClass('selected');
						//clear the right box:
						$(document.body).getElement('div.tx-sbstellenangebote-pi3 div.section ul').empty();
						//loop through the child object that contains the section information
						$each(expElem, function(sectElem, sectIndex){
							//populate the right (sections) box:
							$(document.body).getElement('div.tx-sbstellenangebote-pi3 div.section ul').grab(
								new Element('li',{
									'html':sectIndex,
									'class':(parms.selSectStr==sectElem||'*'==sectElem?'selected':''),
									'events':{
										'click':function(){
											//remove all "parent's child's" (siblings and me) selected-state:
											this.getParent().getChildren('li').removeClass('selected');
											//and set mine state selected:
											this.addClass('selected');
											//replace the filter ###filterSect### ("#" encoded as %23) with the stored section identifier shortcut
											window.location.href = parms.useParams.replace(/(%23){3}filterSect(%23){3}/g, sectElem);
										}
									}
								})
							);
						})
					}
				}
			});

		//attach the li-element to the ul
		$(document.body).getElement('div.tx-sbstellenangebote-pi3 div.experience ul').grab(currentLi);

		//if the current expertise is selected, do the stuff as it has been clicked.
		if(expIndex==parms.selExpertise)	{
			currentLi.fireEvent('click');
		}
		ctr++;
	});

	if(1==ctr) { //there is only one "parent" item (e.g. "Services" or "Students"), so...
		currentLi.fireEvent('click'); //...fire the event of the last (and so single) "li item" as it has been clicked

		//set the first ('all') element selected when none other elem is selected.
		if(!$(document.body).getElement('div.tx-sbstellenangebote-pi3 div.section ul').getElement('li.selected'))	{
			$(document.body).getElement('div.tx-sbstellenangebote-pi3 div.section ul').getFirst('li').addClass('selected');
		}
	} else { //there are more items, make the first clicked if no other is selected
		if(!$(document.body).getElement('div.tx-sbstellenangebote-pi3 div.experience ul').getElement('li.selected'))	{
			$(document.body).getElement('div.tx-sbstellenangebote-pi3 div.experience ul').getFirst('li').fireEvent('click');
		}
	}
}
