
/* Definitions for global access */
aEtfClasses = new Array();
aDropdownsFilterNavi = new Array();
sStatusCookie = 'dbxtrackers%2Ecom%2Dattributfilter';

/* Class for attribute */
var Attribute = new Class({
	options: {
		bIsAttributeSet: false,
		bHitsAvailable: false,
		iAttributeNr: 0,
		sLink: 'not defined',
		sName: 'not defined'
	},
	initialize: function(options){
		this.setOptions(options);
		var iAttribute = iGetNumericParameterFromUrl('inattributneu', this.sGetLink())
		iAttribute = iAttribute < 0 ? iAttribute * -1 : iAttribute;
		this.options.iAttributeNr = iAttribute;
	},
	iGetAttributeNr: function(){
		return this.options.iAttributeNr;
	},
	sGetName: function(){
		return this.options.sName;
	},
	sGetLink: function(){
		return this.options.sLink;
	},
	bHasHits: function(){
		return this.options.bHitsAvailable;
	},
	bIsAttributeSet: function(){
		return this.options.bIsAttributeSet;
	}
});
Attribute.implement(new Options);

/* Class for attribute classes */
var AttributeClass = new Class({
	options: {
		aAttributes: null,
		bHitsAvailable: false,
		iAttributeClassNr: 0,
		oSelectBoxDropDown: null,
		sLink: 'not defined',
		sName: 'not defined'
	},
	initialize: function(options){
		options.aAttributes = new Array();
		this.setOptions(options);
		
		var iClassAttribute = iGetNumericParameterFromUrl('inattributklasse', this.options.sLink);
		if (iClassAttribute !== null)
			this.options.iAttributeClassNr = iClassAttribute;
	},
	addAttribute: function(oNewAttribute){
		this.options.aAttributes.push(oNewAttribute);
	},
	sGetName: function(){
		return this.options.sName;
	},
	bHasActiveAttributes: function(){
		for (var i = 0; i < this.options.aAttributes.length; i++)
		{
			if (this.options.aAttributes[i].bIsAttributeSet())
				return true;
		}
	},
	bHasHits: function(){
		return this.options.bHitsAvailable;
	},
	iGetAttributeClassNr: function(){
		return this.options.iAttributeClassNr;
	},
	oGetAttributeById: function(sId) {
		for (var i = 0; i < this.options.aAttributes.length; i++)
		{
			if (this.options.aAttributes[i].iGetAttributeNr() == sId)
			{
				return this.options.aAttributes[i];
			}
		}
	},
	vDisplayAttributeSelectBox: function(oEvent){
		/* We need to fire the click event before this function executes and not after! */
		oEvent.stop();
		$(document.body).fireEvent('click'); 
		
		var oReferingObject = oEvent.target;
		var oLayer = this.oGetAndCreateSelectBoxLayer(oReferingObject);
		oLayer.setStyle('display', 'block');
		oLayer.fireEvent('resize'); // resize of document takes place after positioning and displaying the element (e.g. due to scrollbar insertion), thus we correct the position whenever displaying the element
		this.oGetShadowRight(oLayer).injectAfter(oLayer);
		this.oGetShadowBottom(oLayer).injectAfter(oLayer);
	},
	oGetAndCreateSelectBoxLayer: function(oBox){
		if (this.options.oSelectBoxDropDown != null)
		{
			return this.options.oSelectBoxDropDown;
		}
		
		/* correct the root node (for the box) if we click on a node inside the root node */
		while(!$(oBox).hasClass('cAttributeSelectBox'))
		{
			var oBox = $(oBox).getParent();
		}
		
		var oDropDown = new Element('div');
		
		/* element position */
		oDropDown.addClass('cAttributeSelectBoxDropDown');
		
		/* correct position on resize */
		oDropDown.addEvent('resize', function(){
			var oCoordinates = oBox.getCoordinates();
			oDropDown.setStyle('width', oCoordinates.width - (window.ie6 ? 0 : 2));
			oDropDown.setStyle('top', oCoordinates.top);
			oDropDown.setStyle('left', oCoordinates.left);
		});
		oDropDown.fireEvent('resize'); //this places element in correct position before display
		window.addEvent('resize', function(){oDropDown.fireEvent('resize');}); // fire resize of menu whenever window resizes
		
		/* compile content */
		oDropDown.adopt(this.oGetHeadSectionBox());
		oDropDown.adopt(this.oGetMultipleSelectionBox());
		oDropDown.adopt(this.oGetAttributeLinkBox());
		
		
		/* inject in dom, add event, return object */
		oDropDown.injectBefore('maincontainer'); // insert "beside" top div
		
		$(document.body).addEvent('click', function(){
			oDropDown.setStyle('display', 'none'); 
			$$('.cDropdownShadowRight').each(function(obj){
				obj.remove();
			});
			$$('.cDropdownShadowBottom').each(function(obj){
				obj.remove();
			});
		});
		this.options.oSelectBoxDropDown = oDropDown
		return this.options.oSelectBoxDropDown;
	},
	oGetHeadSectionBox: function() {
		var oHead = new Element('div');
		oHead.addClass('cAttributeSelectBoxHead');
		oHead.setHTML('<a href="' + this.options.sLink + '">' + this.options.sName + '</a>');
		return oHead;
	},
	oGetMultipleSelectionBox: function(sCssClass) {
		/* Create Link */
		var oLink = new Element('a');
		oLink.setText(document.translation['mehrfachauswahl']);
		oLink.addEvent('click', this.vOpenMultipleSelectionBox.bindWithEvent(this));
		
		/* Create Box */
		var oBox = new Element('div');
		if (sCssClass === undefined || sCssClass === null)
		{
			oBox.setHTML('&raquo; ');
		}
		oBox.adopt(oLink);
		sCssClass = sCssClass ? sCssClass : 'cAttributeSelectBoxMultipleSelection';
		oBox.addClass(sCssClass);
		
		return oBox;
	},
	oGetAttributeLinkBox: function() {
		var oNewLink;
		var oNewBox;
		var oLinks = new Element('div');
		oLinks.addClass('cAttributeSelectBoxLinks');
		oLinks.addClass('clearfix');
		
		for (var iAttributeIndex = 0; iAttributeIndex < this.options.aAttributes.length; iAttributeIndex++)
		{
			if (this.options.aAttributes[iAttributeIndex].bHasHits() && (this.options.aAttributes[iAttributeIndex].bIsAttributeSet() || !this.bHasActiveAttributes()))
			{
				oNewBox = new Element('div');
				oNewBox.addClass('clearfix');
				oNewBullet = new Element('span');
				oNewBullet.setHTML(' &raquo; ');
				oNewLink = new Element('a');
				oNewLink.setHTML(this.options.aAttributes[iAttributeIndex].sGetName());
				oNewLink.setAttribute('href', this.options.aAttributes[iAttributeIndex].sGetLink());
				oNewLink.addEvent('click', vXhrProductNavigationLinkClick);
				oNewBox.adopt(oNewBullet);
				oNewBox.adopt(oNewLink);
				oLinks.adopt(oNewBox);
			}
		}
		
		return oLinks;
	},
	oGetShadowRight: function(oBox) {
		var oCoordinates = oBox.getCoordinates();
		var oShadow = new Element('div');
		oShadow.addClass('cDropdownShadowRight');
		oShadow.setStyle('left', oCoordinates.right);
		oShadow.setStyle('top', oCoordinates.top);
		oShadow.setStyle('height', oCoordinates.height);
		oShadow.setStyle('width', 4);
		return oShadow;
	},
	oGetShadowBottom: function(oBox) {
		var oCoordinates = oBox.getCoordinates();
		var oShadow = new Element('div');
		oShadow.addClass('cDropdownShadowBottom');
		oShadow.setStyle('left', oCoordinates.left);
		oShadow.setStyle('top', oCoordinates.bottom);
		oShadow.setStyle('height', 5);
		oShadow.setStyle('width', oCoordinates.width + 4);
		return oShadow;
	},
	vOpenMultipleSelectionBox: function(oEvent) {
		/* grey fading bg */
		var oBackground = new Element('div');
		oBackground.addClass('cFadeBackground');
		oBackground.injectTop('mainbody');
		oBackground.setStyle('height', $('mainbody').getCoordinates().height);
		
		/* add selection box */
		var oSelectionBox = new Element('div');
		oSelectionBox.addClass('cMultipleSelectionBox');
		oSelectionBox.injectTop('mainbody');
		if (window.ie6)
		{
			oSelectionBox.setStyle('height', '213px');
		}
		
		/* close button */
		var oButtonClose = new Element('img');
		oButtonClose.addClass('cCloseButton');
		oButtonClose.setProperty('src', apUrlZusatz + 'images/button_mehrfachauswahl_schliessen.png');
		oButtonClose.addEvent('click', function(){oBackground.remove(); oSelectionBox.remove();});
		oButtonClose.injectInside(oSelectionBox);
		
		/* headline */
		var oHeadline = new Element('h1');
		oHeadline.setText(document.translation['mehrfachauswahl']);
		oHeadline.injectInside(oSelectionBox);
		
		var oSeparator = new Element('div');
		oSeparator.addClass('cHorizontalRule');
		oSeparator.injectInside(oSelectionBox);
		
		/* formular */
		var sFormularLink = sGetFormularLink(this.options.aAttributes[0].sGetLink());
		
		var oFormular = new Element('form');
		oFormular.injectInside(oSelectionBox);
		oFormular.setProperty('action', sFormularLink);
		oFormular.setProperty('method', 'post');
		
		var oFormContent = new Element('div');
		oFormContent.addClass('cFormContent');
		oFormContent.injectInside(oFormular);
		
		var oFormControl;
		var oFormGroup = null;
		var oCheckBox;
		var oLabel;
		var iDisplayedAttributeCounter = 0;
		var iTotalVisibleAttributes = 0;
		var iEntriesPerRow;
		
		var iCountActiveFilters = function(){
				var iActiveFilterCounter = 0;
				aEtfClasses.each(function(oClass, iClassIndex){
					if (oClass.bHasActiveAttributes())
					{
						iActiveFilterCounter++;
					}
				});
				return iActiveFilterCounter;
			};
		var iActiveFilters = iCountActiveFilters();
		
		var bDisableCheckboxes = false;
		if (iActiveFilters > 0)
		{
			if (iActiveFilters == 1)
			{
				// Only disable if current class has the only attribute set
				if (!this.bHasActiveAttributes())
				{
					bDisableCheckboxes = true;
				}
			}
			else
			{
				bDisableCheckboxes = true;
			}
			
		}
		
		//count the attributes which shall be displayed
		for (var iAttributeIndex = 0; iAttributeIndex < this.options.aAttributes.length; iAttributeIndex++)
		{
			if (!this.options.aAttributes[iAttributeIndex].bHasHits())
			{
				iTotalVisibleAttributes++;
			}
		}
		
		iEntriesPerRow = (iTotalVisibleAttributes / 4).toInt();
		iEntriesPerRow += iEntriesPerRow == 0 ? 1 : 0;
		for (var iAttributeIndex = 0; iAttributeIndex < this.options.aAttributes.length; iAttributeIndex++)
		{
			if (iDisplayedAttributeCounter % iEntriesPerRow == 0)
			{
				if (oFormGroup != null)
				{
					oFormGroup.injectInside(oFormContent);
				}
				oFormGroup = new Element('div');
				oFormGroup.addClass('cFormGroup');
				oFormGroup.injectInside(oFormContent);
			}
			
			var oFormControl = new Element('div');
			oFormControl.addClass('cFormControl');
			oFormControl.injectInside(oFormGroup);
			
			oCheckBox = new Element('input');
			oCheckBox.addClass('cMultipleSelectionCheckbox');
			oCheckBox.setProperty('type', 'checkbox');
			oCheckBox.setProperty('name', 'smultibox');
			oCheckBox.setProperty('id', 'Mehrfachauswahl_' + this.options.aAttributes[iAttributeIndex].iGetAttributeNr());
			oCheckBox.setProperty('value', this.options.aAttributes[iAttributeIndex].iGetAttributeNr());
			oCheckBox.injectInside(oFormControl);
			if (this.options.aAttributes[iAttributeIndex].bIsAttributeSet())
			{
				oCheckBox.setProperty('checked', 'checked');
			}
			//Disable checkbox if no hits available
			oCheckBox.disabled = bDisableCheckboxes && (! this.options.aAttributes[iAttributeIndex].bHasHits());
			
			oLabel = new Element('label');
			oLabel.setProperty('for', 'Mehrfachauswahl_' + this.options.aAttributes[iAttributeIndex].iGetAttributeNr());
			oLabel.setHTML(this.options.aAttributes[iAttributeIndex].sGetName());
			oLabel.injectInside(oFormControl);
			
			iDisplayedAttributeCounter++;
		}
		
		/* set checkboxes now, because IE forgets state if checked above */
		if (window.ie6)
		{
			var aCheckboxes = $$('.cMultipleSelectionCheckbox');
			for (var k = 0; k < aCheckboxes.length ; k++)
			{
				sId = aCheckboxes[k].getProperty('value');
				if (this.oGetAttributeById(sId).bIsAttributeSet()) 
				{
					aCheckboxes[k].setProperty('checked', 'checked');
				}
			}
		}
		
		/* clear float */
		var oClear = new Element('div');
		oClear.addClass('clear');
		oClear.injectInside(oFormular);
		
		/* submit button */
		var oAttributeClass = this;
		var oSubmitButton = new Element('input');
		oSubmitButton.setProperty('type', 'button');
		oSubmitButton.setProperty('id', 'iSubmitMultipleSelection');
		oSubmitButton.setProperty('value', document.translation['auswahl_treffen']);
		oSubmitButton.addEvent('click', function(e){
			var sValue;
			var aCookieTemp;
			var aCheckBoxes = $$('input.cMultipleSelectionCheckbox');
			
			if (!Cookie.get(sStatusCookie))
			{
				aCookieTemp = ['', ''];
			}
			else
			{
				aCookieTemp = Cookie.get(sStatusCookie).split('=');
			}
			var aCookie = aCookieTemp[1].split(',');
			
			for (var i = 0; i < aCheckBoxes.length; i++)
			{
				sValue = aCheckBoxes[i].getProperty('value');
				if (aCheckBoxes[i].checked)
				{
					/* if checked then add to array of not existent */
					if (!aCookie.contains(sValue))
					{
						aCookie.push(sValue);
					}
				}
				else
				{
					/* if unchecked then remove from array */
					aCookie.remove(sValue);
				}
			}
			
			/* write array comma separated to cookie */
			aCookie.remove('');
			Cookie.set(sStatusCookie, aCookieTemp[0] + '=' + aCookie.join(','), {path: '/'});
			oButtonClose.fireEvent('click');
			
			/* no real submit: */
			var sRedirectLink = sGetFormularLink(oAttributeClass.options.aAttributes[0].sGetLink());
			window.location.replace(sRedirectLink);
		});
		oSubmitButton.injectInside(oFormular);
	},
	oGetFilterLinks: function() {
		var oContainer = new Element('div');
		this.options.aAttributes.each(function(oAttribute, iAttributeIndex){
			if (oAttribute.bHasHits() && oAttribute.bIsAttributeSet())
			{
				var oLinkLine = new Element('div');
				var oLink = new Element('a');
				if (oAttribute.bIsAttributeSet())
					oLink.addClass('aktiv');
				oLink.setProperty('href', oAttribute.sGetLink());
				oLink.setHTML(oAttribute.sGetName());
				oLink.injectInside(oLinkLine);
				oLinkLine.injectInside(oContainer);
			}
		});
		
		//add multiplie selection
		this.oGetMultipleSelectionBox('cMultipleSelection').injectInside(oContainer);
		
		var oRemoveFilterBox = new Element('div');
		oRemoveFilterBox.addClass('cRemoveSelection');
		
		var oRemoveLink = new Element('a');
		var sRemoveFilterLink = this.options.sLink;
		if (iGetNumericParameterFromUrl('inreset', sRemoveFilterLink) == 1)
		{
			var page = iGetNumericParameterFromUrl('pageid', sRemoveFilterLink);
			if (page == null)
			{
				sRemoveFilterLink = sRemoveFilterLink.replace(/[\?|&]inreset=[0-9]*/, '&inattributklasse=1');
			} else {
				sRemoveFilterLink = 
					'showpage.asp?pageid=' + page +
					'&inreiter=' + document.iAktuellerReiter + 
					'&inetfgruppe=' + iGetNumericParameterFromUrl('inetfgruppe', sRemoveFilterLink) + 
					'&inattributklasse=1';
			}
		}
		
		oRemoveLink.setText(document.translation['filter_entfernen']);
		oRemoveLink.setProperty('href', sRemoveFilterLink);
		oRemoveLink.injectInside(oRemoveFilterBox);
		oRemoveFilterBox.injectInside(oContainer);
		
		return oContainer;
	}
});
AttributeClass.implement(new Options);

/*
	Return an appropriate Link for a formular action (multiple selection does not work via form)
*/
function sGetFormularLink(sCurrentUrl) {
	if (sCurrentUrl.indexOf('pageid') > -1)
	{
		return 'showpage.asp?pageid=' + iGetNumericParameterFromUrl('pageid', sCurrentUrl);
	}
	else if (sCurrentUrl.indexOf('url=/') > -1)
	{
		return 'showpage.asp?url=' + sGetParameterFromUrl('url', sCurrentUrl);
	}
	else
	{
		return sCurrentUrl.split('?')[0];
	}
}

/* 
	creates the product navigation dynamically
 */
function vInitializeProductNavigation()
{
	vCreateObjectsAndRemoveSecondaryClassesFromDom();
	vCreateProductNavigationFromObjectStructure();
}

/* 
	Creates the object structure and removes all navigation categories except the main one. 
	(object structure will be used else where to create a DHTML Menu)
 */
function vCreateObjectsAndRemoveSecondaryClassesFromDom() {
	var aClassChildren;
	var bAttributeState;
	var bIsClass;
	var bIsAttribute;
	var iClassCounter = -1;
	var oTemp;
	var sThisOnesName;
	var sThisOnesLink;
	
	var oNavi = $('iNaviProdukte');
	var aNaviChildren = oNavi.getElements('.cAttributKlasse');
	
	/* Get all attribute classes */
	for (var iIndexClass = 0; iIndexClass < aNaviChildren.length; iIndexClass++)
	{
		/* Get all attributes */
		aClassChildren = aNaviChildren[iIndexClass].getChildren();
		for (var iIndexAttribute = 0; iIndexAttribute < aClassChildren.length; iIndexAttribute++)
		{
			/* Get the anchor tag */ 
			aAttributChildren = aClassChildren[iIndexAttribute].getChildren();
			if (aAttributChildren.length > 0)
			{
				oAnchor = aAttributChildren[0];
				bAttributeState = aClassChildren[iIndexAttribute].hasClass('cAttributAktiv');
				bAttributeHasHits = !aClassChildren[iIndexAttribute].hasClass('cAttributOhneTreffer');
				bIsAttribute = aClassChildren[iIndexAttribute].hasClass('cAttribut');
				bIsClass = aClassChildren[iIndexAttribute].hasClass('cAlleAttribute');
				bHasXhrLink = bIsClass || bIsAttribute;
				sThisOnesName = oAnchor.innerHTML;
				sThisOnesLink = oAnchor.getAttribute('href');
				
				/* Create Class Attribute object */
				if (bIsClass)
				{
					oTemp = new AttributeClass({sName: sThisOnesName, sLink: sThisOnesLink, bHitsAvailable: bAttributeHasHits});
					aEtfClasses.push(oTemp);
					iClassCounter++;
				}
				
				/* Create Attribute object and add it to the corresponding Class Attribute object */
				if (bIsAttribute)
				{
					oTemp = new Attribute({sName: sThisOnesName, sLink: sThisOnesLink, bIsAttributeSet: bAttributeState, bHitsAvailable: bAttributeHasHits});
					aEtfClasses[iIndexClass].addAttribute(oTemp);
				}
				
				/* create click events for xhr requests on links */
				if (iIndexClass == 0 && bHasXhrLink) 
				{
					oAnchor.addEvent('click', vXhrProductNavigationLinkClick);
				}
			}
		}
		
		/* remove each navigation box except the first (main) Attribute Class */
		if (iIndexClass != 0)
		{
			aNaviChildren[iIndexClass].remove();
		}
		
	}
}

var vXhrProductNavigationLinkClick = function(clickevent) {
	var sLink = this.href;
	var sDelimiter;
	var sParameter = 'inreiter=' + document.iAktuellerReiter;
	var oRegex = /inreiter=-?\d+/;
	
	if (sLink.search(oRegex) == -1)
	{
		sDelimiter = sLink.indexOf('?') > -1 ? '&' : '?';
		
		//anhängen
		sLink += sDelimiter + 'inreiter=' + document.iAktuellerReiter;
	}
	else
	{
		//ersetzen
		sLink = sLink.replace(oRegex, sParameter);
	}
	
	this.href = sLink;
}

/* 
	Uses the previously created object structure to compile special controls for navigation
 */
function vCreateProductNavigationFromObjectStructure() {
	var oSelect;
	var oSelectShadow;
	
	for (var iIndexClass = 1; iIndexClass < aEtfClasses.length; iIndexClass++)
	{
		oSelectShadow = new Element('div');
		oSelectShadow.addClass('cAttributeSelectBoxShadow');
		oSelectShadow.injectInside('iNaviProdukte');
		
		oSelect = new Element('div');
		oSelect.addClass('cAttributeSelectBox');
		if (aEtfClasses[iIndexClass].bHasActiveAttributes())
		{
			oSelect.addClass('cActiveSelectBox');
		}
		if (aEtfClasses[iIndexClass].bHasHits())
		{
			oSelect.addEvent('click', aEtfClasses[iIndexClass].vDisplayAttributeSelectBox.bindWithEvent(aEtfClasses[iIndexClass]));
		}
		else
		{
			oSelect.addClass('cSelectBoxWithoutHits');
		}
		oSelect.setHTML(aEtfClasses[iIndexClass].sGetName());
		oSelect.injectInside(oSelectShadow);
	}
}

var oRealtimeBoxScroll;

function vClearRealtimeBoxScroll() {
	$clear(oRealtimeBoxScroll);
	oRealtimeBoxScroll = null;
}

/* 
	Find table body of realtimebox and initialize it
 */
function vInitializeRealtimeBox() {
	var oTable = $('iNaviRealtimeBox').getElement('div.cTableBody');
		
	oTable.setStyle('width', '100%');
	oTable.setStyle('height', '165px');
	oTable.setStyle('overflow', 'hidden');
	
	var oScroll = new Fx.Scroll(oTable, {
	wait: false,
	duration: 100,
	transition: Fx.Transitions.linear
	});
	var realtimeBoxScrollDown = function() {
		var oSize = oTable.getSize();
		var y = oSize.scroll.y;
		y += 20;
		if (y >= oTable.getElement('table').getSize().size.y - oTable.getSize().size.y) {
			oTable.getElement('tbody').appendChild(oTable.getElement('tbody').firstChild);
			y -= 20;
			oTable.scrollTo(0, y - oTable.getElement('tbody').lastChild.getSize().size.y);
		}
		oScroll.scrollTo(0, y);
	}
	var realtimeBoxScrollUp = function() {
		var oSize = oTable.getSize();
		var y = oSize.scroll.y;
		y -= 20;
		if (y < 0) {
			oTable.getElement('tbody').insertBefore(oTable.getElement('tbody').lastChild, oTable.getElement('tbody').firstChild);
			y += oTable.getElement('tr').getSize().size.y;
			oTable.scrollTo(0, y + 20);
		}
		oScroll.scrollTo(0, y);
	}
	
	$('iNaviRealtimeBoxScrollDown').addEvent('mouseenter', function() {
		vClearRealtimeBoxScroll();
		realtimeBoxScrollDown();
		if (oRealtimeBoxScroll === null)
			oRealtimeBoxScroll = realtimeBoxScrollDown.periodical(100);
	});
	
	$('iNaviRealtimeBoxScrollDown').addEvent('mouseleave', function() {
		vClearRealtimeBoxScroll();
	});
	
	$('iNaviRealtimeBoxScrollUp').addEvent('mouseenter', function() {
		vClearRealtimeBoxScroll();
		realtimeBoxScrollUp();
		if (oRealtimeBoxScroll === null)
			oRealtimeBoxScroll = realtimeBoxScrollUp.periodical(100);
	});
	
	$('iNaviRealtimeBoxScrollUp').addEvent('mouseleave', function() {
		vClearRealtimeBoxScroll();
	});
	
}

function vInitializeXhrOnObject(oNode) {
	var aLinks = oNode.getElements('a.cXHR');
	var oFxNode = new Fx.Scroll(window);
	
	aLinks.each(function(oLink, iLinkIndex){
		oLink.addEvent('click', function(oEvent){
			oEvent = new Event(oEvent).stop();
			oFxNode.toTop();
			var sURL = oLink.getProperty('href');
			blnLadeAjaxInhalt(sURL, oNode)
			return false;
		});
	});
	
	var aForms = oNode.getElements('form.cXHR');
	aForms.each(function(oForm, iLinkIndex){
		oForm.addEvent('submit', function(){
			oFxNode.toTop();
			blnLadeAjaxInhalt(this, oNode);
		});
	});
}

function vInitializeRowHighlightingOnTableBody(oTable, iIndex) {
	var aRows = oTable.getElements('tbody tr');
	
	aRows.each(function(oRow, iRowIndex) {
		oRow.addEvent('mouseenter', function(){
			oRow.addClass('cHighlight');
		});
		
		oRow.addEvent('mouseleave', function(){
			oRow.removeClass('cHighlight');
		});
	});
}

function vInitializeProductTable() {
	if ($defined($('portfoliorechner')))
		return;
	
	$$('.cTabelleEtfUebersicht').each(vInitializeRowHighlightingOnTableBody);
	
	if ($defined($('iPushkursBox_content')))
		vInitializeXhrOnObject($('iPushkursBox_content'));
	
	if ($defined($('iEtfUebersicht_content')))
		vInitializeXhrOnObject($('iEtfUebersicht_content'));
		
	if ($defined($('iSuchergebnis_content')))
		vInitializeXhrOnObject($('iSuchergebnis_content'));
}

function vInitializeDropdownFilter() {
	var iBoxMargin = 6;
	var iHeightFactor = 40;
	var iMaxWidth = 418;
	
	var aFilterBoxen = aHoleDropdownFilterBoxen(); //defined inline
	var oDropdown = new Element('div');
	var iTotalWidth = 0;
	oDropdown.id = 'iFilterSelectBox'
	oDropdown.injectTop($(document.body));
	
	aFilterBoxen.each(function(sFilterBox, iFilterBoxIndex){
		var oFilterBox = $(sFilterBox);
		oFilterBox.addEvent('click', vOpenFilterBoxDropDown.bindWithEvent(oFilterBox));
		iTotalWidth += oFilterBox.getCoordinates().width + iBoxMargin;
	});
	
	$(document.body).addEvent('click', function(){
		if (oDropdown) {
			oDropdown.setStyle('display', 'none');
		}
		$$('.cFilterSelectBoxShadowRight').each(function(obj){
			obj.remove();
		});
		
		$$('.cFilterSelectBoxShadowBottom').each(function(obj){
			obj.remove();
		});
		
		$$('.cFilterSelectBoxShadowEdge').each(function(obj){
			obj.remove();
		});
	});
}

function oGetFilterDropdown(iClass) {
	var oEtfClass;
	
	for(var i = 0; i < aEtfClasses.length; i++)
	{
		oEtfClass = aEtfClasses[i];
		if (oEtfClass.iGetAttributeClassNr() == iClass)
		{
			return oEtfClass.oGetFilterLinks();
		}
	}
}

function vOpenFilterBoxDropDown(oEvent){
	/*fire click before function executes*/
	oEvent.stop();
	$(document.body).fireEvent('click'); 
	
	//var sId = oFilterBox.id.substr(17);
	var ie6correction = window.ie6 ? 1 : 0;
	var sId = this.id.substr(17);
	var iKlassenNr = parseInt(sId);
	iKlassenNr = iKlassenNr == 1 ? 0 : iKlassenNr;
	//var oCoordinates = oFilterBox.getCoordinates();
	var oCoordinates = this.getCoordinates();
	
	var oDropdown = $('iFilterSelectBox');
	oDropdown.setHTML('');
	oDropdown.adopt(oGetFilterDropdown(iKlassenNr));
	oDropdown.setStyle('display', 'block');
	oDropdown.setStyle('left', oCoordinates.left + ie6correction);
	oDropdown.setStyle('top', oCoordinates.bottom - 1  + ie6correction);
	
	//add shadoweffects
	oCoordinates = oDropdown.getCoordinates();
	var oShadow = new Element('div');
	oShadow.addClass('cFilterSelectBoxShadowRight');
	oShadow.setStyle('left', oCoordinates.right);
	oShadow.setStyle('top', oCoordinates.top);
	oShadow.setStyle('height', oCoordinates.height);
	oShadow.injectTop($(document.body));
	
	oShadow = new Element('div');
	oShadow.addClass('cFilterSelectBoxShadowBottom');
	oShadow.setStyle('left', oCoordinates.left);
	oShadow.setStyle('top', oCoordinates.bottom );
	oShadow.setStyle('width', oCoordinates.width);
	oShadow.injectTop($(document.body));
	
	oShadow = new Element('div');
	oShadow.addClass('cFilterSelectBoxShadowEdge');
	oShadow.setStyle('left', oCoordinates.right);
	oShadow.setStyle('top', oCoordinates.bottom);
	oShadow.injectTop($(document.body));
	
}

function vInitializeDropdownCurrencies() {
	var oButton = $('iEtfUebersichtWaehrungen').getElement('.cButton');
	var oDropDown = $('iEtfUebersichtWaehrungen').getElement('.cDropDown');
	
	oButton.addEvent('click', function(oEvent){
		oEvent.stop();
		oDropDown.setStyle('display', 'block');
	}.bindWithEvent(this));
	
	oDropDown.addEvent('click', function(oEvent){
		oDropDown.setStyle('display', 'none');
	});
	
	$(document.body).addEvent('click', function(oEvent){
		oDropDown.setStyle('display', 'none');
	});
}

window.addEvent('domchanged', function(){
	if ($defined($('iEtfUebersichtWaehrungen')))
	{
		vInitializeDropdownCurrencies();
	}
	
	vInitializeProductTable();
});

window.addEvent('domready', function(){
	if ($defined($('iNaviProdukte')))
	{
		vInitializeProductNavigation();
	}
	if ($defined($('iNaviRealtimeBox')))
	{
		vInitializeRealtimeBox();
	}
	if ($defined($('iNaviFilter')))
	{
		vInitializeDropdownFilter();
	}
	if ($defined($('iEtfUebersichtWaehrungen')))
	{
		vInitializeDropdownCurrencies();
	}
	vInitializeProductTable();
});
