/*******************************************************************
* Methoden für die Suche
*******************************************************************/

/**
 * Methode entfernnt den Wert im Knoten <code>node</code>
 *
 * @param	Node	Der Knoten, in dem das Attribut valöue gelöscht werden soll
 *
 * @return	boolean
 */
function clearValue(node) {
	node.value = "";
	return true;
}

/*******************************************************************
* Actionen, die nach Laden der Seite ausgeführt werden sollen
*******************************************************************/

$(document).ready(function() {

	/* ---------- Footernavigation zentrieren ---------- */
	try {
		var intWidthFooter = $('.footer').width();
		var objToolNavi = $('.toolnavigation');
		var intWidthToolNavi = objToolNavi.width();
		var intWidthFooterNavi = $('.footernavigation').width();
		
		var intMargin = (intWidthFooterNavi + intWidthToolNavi);
		if (intMargin < intWidthFooter) {
			intMargin = (intWidthFooter - intMargin)/2;
		} else {
			intMargin = 0;
		}
		objToolNavi.css("margin-left", intMargin+"px");
		
	} catch (e) {}	
	
	/* ---------- Warenkorb ---------- */
	try {
		// Warenkorb öffnen
		$('#basket .more').click(function() {
			if (!$(this).parents('#basket').hasClass('is-open')) {
				$(this).parents('#basket').addClass('is-open');
			}
		});
		// Warenkorb schließen
		$('#basket').mouseleave(function() {
			if ($(this).hasClass('is-open')) {
				$(this).removeClass('is-open');
			}
		});			
	} catch (e) {}
	
	/* ---------- Layer Hauptmenü Produkte ---------- */
	try {
		var currentProductCatalogElem = null;
		var futureProductCatalogElem = null;
		var timer = null;
		
		var currentSubCategory = null;
		
		// Hauptpunkte
		$('.product-catalog .main-category').each(function(intIndex) {
			
			//1. Element markieren
			if ($(this).hasClass('current')) {
				currentProductCatalogElem = this;
			}
			
			$(this).mouseenter(function() {
				// Timer entfernen
				clearTimeout(timer);
				if (!$(this).hasClass('current')) {
					futureProductCatalogElem = this;
					// Timer für verzögertes Öffnen nutzen
					timer = setTimeout(function () {
						$(futureProductCatalogElem).addClass('current');
						$(currentProductCatalogElem).removeClass('current');
						currentProductCatalogElem = futureProductCatalogElem;
						futureProductCatalogElem = null;
					}, 200);
				} 
			});
		});
		
		// Unterpunkte
		$('.product-catalog .sub-category-link').each(function(intIndex) {
			
			$(this).prev().hide();
			
			$(this).mouseenter(function() {
				if (!$(this).hasClass('current')) {
					$(this).addClass('current');					
					$(currentSubCategory).removeClass('current');
					$(this).prev().slideDown('fast');
					$(currentSubCategory).prev().slideUp('fast');					
					currentSubCategory = this;
				}
			});
		});
	} catch (e) {}
});
