var i=0,j=0,k=0;
var do_hersteller_bild="";
window.addEvent('domready', function() { 
	new Autocompleter.Request.HTML($('search'), 'inc/search/ajax/suggest.php', {
		'indicatorClass': 'autocompleter-loading' // class added to the input during request
	});
	
	/*if (document.getElementById("top_menu_container")) {
		var objElem = document.getElementById("top_menu_container");
		for(i = 0; i < objElem.getElementsByTagName('img').length; ++i)	{
			objIMG = objElem.getElementsByTagName('img')[i];
			objIMG.id = 'menu_b'+i;
			objIMG.onmouseover = new Function('f', 'bubble('+i+')');
			objIMG.onmouseout = new Function('f', 'rebubble('+i+')');
		}
		if ((objElem.getElementsByTagName('img').length % itemsperline)>0&&objElem.getElementsByTagName('img').length>itemsperline) {
			//var margin = (itemsperline - (objElem.getElementsByTagName('img').length % itemsperline)) * (116/2);
			var margin = (116/2);
			var itemformargin = itemsperline * Math.floor(objElem.getElementsByTagName('img').length/itemsperline);
			$('menu_b'+itemformargin).parentNode.parentNode.style.marginLeft = margin+'px';
		}
	}
	*/
	if (document.getElementById("layer02_container")) {
		var objElem = document.getElementById("layer02_container");
		for(i = 0; i < objElem.getElementsByTagName('div').length; ++i)	{
			objDIV = objElem.getElementsByTagName('div')[i];
			objDIV.id = 'menu_b'+i;
			objDIV = $('menu_b'+i);
			if (objDIV.hasClass('menub0')) {
				objDIV.onmouseover = new Function('f', 'bubble('+i+')');
				objDIV.onmouseout = new Function('f', 'rebubble('+i+')');
			}
		}
	}
	i++;
	if (document.getElementById("layer03_container")) {
		var objElem = document.getElementById("layer03_container");
		for(j = 0; j < objElem.getElementsByTagName('div').length; ++j)	{
			objDIV = objElem.getElementsByTagName('div')[j];
			objDIV.id = 'menu_b'+(j+i);
			objDIV = $('menu_b'+(j+i));
			if (objDIV.hasClass('menub0')) {
				objDIV.onmouseover = new Function('f', 'bubble('+(j+i)+')');
				objDIV.onmouseout = new Function('f', 'rebubble('+(j+i)+')');
			}
		}
	}
	
	i=i+j+1;
	if (document.getElementById("top_menu_container")) {
		var objElem = document.getElementById("top_menu_container");
		for(k = 0; k < objElem.getElementsByTagName('div').length; ++k)	{
			objDIV = objElem.getElementsByTagName('div')[k];
			objDIV.id = 'menu_b'+(k+i);
			objDIV = $('menu_b'+(k+i));
			if (objDIV.hasClass('menub0')) {
				objDIV.onmouseover = new Function('f', 'bubble('+(k+i)+')');
				objDIV.onmouseout = new Function('f', 'rebubble('+(k+i)+')');
			}
		}
	}		
		
		
		
	var objElem = document.getElementById("main_navi");
	for(i = 0; i < objElem.getElementsByTagName('img').length; ++i)	{
		objIMG = objElem.getElementsByTagName('img')[i];
		objIMG.style.zIndex=100-(i*10+10);
		objIMG.style.marginLeft=(i*135)+"px";
	}
	if($('zugehoerigkeit')) {
		var req = new Request.HTML({
			url:'templates/foerdertechnik/zugehoerigkeit.php?catid='+cat, 
			onSuccess: function(html) {	$('zugehoerigkeit').set('text', ''); $('zugehoerigkeit').adopt(html); },			
			onFailure: function() { alert('Fehler beim Speichern der Position'); }
		}).send();
	}
	if (do_hersteller_bild!="") {
		hersteller_bild(do_hersteller_bild);
	}
});

function bubble(id) {
	var objDIV = $("menu_b"+id).getElementsByTagName('div')[0].id;
	if (typeof $(objDIV).getStyle('background-position') != "undefined") {
		var x = ($(objDIV).getStyle('background-position')!="") ? $(objDIV).getStyle('background-position').split(" ")[0] : '0';
	} else if (typeof $(objDIV).getStyle('background-position-x') != "undefined") {
		var x = ($(objDIV).getStyle('background-position-x')!="") ? $(objDIV).getStyle('background-position-x') : '0';
	} else if (typeof $(objDIV).style.backgroundPosition != "undefined") {
		var x = ($(objDIV).style.backgroundPosition!="") ? $(objDIV).style.backgroundPosition.split(" ")[0] : '0';
	} else {
		var x = 0;
	}
	$("menu_b"+id).style.overflow = 'hidden';
	$(objDIV).style.overflow='hidden';
	$(objDIV).style.backgroundPosition = x+' -97px';
}
function rebubble(id) {
	var objDIV = $("menu_b"+id).getElementsByTagName('div')[0].id;
	if (typeof $(objDIV).getStyle('background-position') != "undefined") {
		var x = ($(objDIV).getStyle('background-position')!="") ? $(objDIV).getStyle('background-position').split(" ")[0] : '0';
	} else if (typeof $(objDIV).getStyle('background-position-x') != "undefined") {
		var x = ($(objDIV).getStyle('background-position-x')!="") ? $(objDIV).getStyle('background-position-x') : '0';
	} else if (typeof $(objDIV).style.backgroundPosition != "undefined") {
		var x = ($(objDIV).style.backgroundPosition!="") ? $(objDIV).style.backgroundPosition.split(" ")[0] : '0';
	} else {
		var x = 0;
	}
	$(objDIV).style.backgroundPosition = x+' 0px';
}

function hover() {
	$('highlight').style.backgroundColor = "#244363";
}
/*
window.addEvent("scroll", scrolled);
function scrolled() {
	var scrolledY = window.getScroll().y;
	var footerTop = $('footer').getPosition().y;
	var bannerHeight = $('banner').getSize().y;
	if (scrolledY>=131&&scrolledY+bannerHeight<footerTop) {
		$('banner').setStyle('position', 'fixed').setStyle('top', '5px');
	} else if(scrolledY+bannerHeight>=footerTop) {
		$('banner').setStyle('position', 'absolute').setStyle('top', (footerTop-bannerHeight)+'px');
	} else {
		$('banner').setStyle('position', 'absolute').setStyle('top', '131px');	
	}
}
*/

function hersteller_bild(pid) {
	var req = new Request.HTML({
		url:'templates/foerdertechnik/hersteller.php?pid='+pid, 
		onSuccess: function(html) {	$('pr_logobox').set('text', ''); $('pr_logobox').adopt(html); },			
		onFailure: function() { alert('Fehler beim Speichern der Position'); }
	}).send();
}

function hover_start(id) {
	$(id).set('style','background-image:url(templates/foerdertechnik/images/blue_box.png)'); 
	$(id+"n").set('style','color:#ffffff'); 
	$(id+"p").set('style','color:#ffffff'); 	
	$(id+"v").set('style','color:#ffffff');
}
function hover_back(id) {
	$(id).set('style','background-image:url(templates/foerdertechnik/images/silver_box.png)'); 
	$(id+"n").set('style','color:#345c88;'); 
	$(id+"p").set('style','color:#345c88;');
	$(id+"v").set('style','color:#345c88;');
}

function countdown(){
	if (document.count.menge.value != 0) document.count.menge.value = parseInt(document.count.menge.value) - 1;
}

function countup(){
	document.count.menge.value = parseInt(document.count.menge.value) + 1;
}

function product_listing(catid,page) {
	var filter=document.p_filter;
	var variables = "";
	for (var i = 0; i < filter.length; ++i) {
		if(filter.elements[i].type=="checkbox") {
			if(filter.elements[i].checked==true) {
				variables = variables +"&"+ filter.elements[i].name + "="+ filter.elements[i].value;
			}
		}
		if(filter.elements[i].type=="select-one") {
			if(filter.elements[i].options[filter.elements[i].selectedIndex].text!="") {
				variables = variables +"&"+ filter.elements[i].name + "="+ filter.elements[i].options[filter.elements[i].selectedIndex].text;
			}
		}		
	}
	var req = new Request.HTML({
		url:'templates/foerdertechnik/product_listing.php?id='+catid+'&s='+page+variables, 
		onSuccess: function(html) {	
			$('data_content').set('text', '');	$('data_content').adopt(html); 		
		},			
		onFailure: function() { alert('Fehler beim Speichern der Position'); }
	}).send();
}


var ad_cnt = 1;
var richtung = 1;
var from = 0;

function change_ad(richt) {
	if (typeof(richt)=="number") {
		richtung=richt;
		if (richt==-1&&ad_cnt==1) ad_cnt=2;
		if (richt==1&&ad_cnt==ad_max) ad_cnt=ad_max-1;
		clearInterval(ad_inter);
	}
	ad_cnt = ad_cnt + richtung;
	if (ad_cnt == ad_max) { richtung = -1; }
	else if (ad_cnt == 1) { richtung = 1; }
	var to = (ad_cnt -1) * -1000;

	myEffects = new Fx.Morph('box_inner', {duration: 700, transition: Fx.Transitions.Quad.easeOut})
		myEffects.start({
			'margin-left': [from, to]
		});
	from = to;
}

/* function start: menu slide deluxe */
function filter_select_box(elementid,richtung) {
	/* speed/morph festlegen id+elementid */
	$('bpf'+elementid).set('morph', {duration: 200, transition: 'quad:out'});
	/* wenn mouse over */
	if(richtung=='max'){ 
		/* ... dann breite und margin für id+elementid setzen */
		$('bpf'+elementid).morph({'width': '195px','margin-left': '-115px'});
		/* ... prüfen ob feld leer ist */
		if($('bpf'+elementid).getSelected()[0].value==""){
			/* ... opacity auf 0.3 setzen */
			$('label'+elementid).morph({'opacity': '0.3'});
		}
		/* sonst opacity auf 1 setzen */
		else{$('label'+elementid).morph({'opacity': '1'});
		}
	}
	/* wenn nicht breite und margin auf normal */
	else{ 
		if (!Browser.Engine.trident || richtung=="min_straight") {
			$('bpf'+elementid).morph({'width': '80px','margin-left': '0px'});
		} else {
			if (window.event.toElement != null) {
				$('bpf'+elementid).morph({'width': '80px','margin-left': '0px'});
			}
		}
		/* und opacity auf normal */
		$('label'+elementid).morph({'opacity': '1'});
	}	
}

function filter_select_ie_fix(elementid) {
	window.setTimeout('filter_select_box('+elementid+',"min_straight")',400);
}

function toogle_menupanel(div) {
	if (parseInt($(div).style.height)==0) {
		new Fx.Morph(div, {duration: 300, transition: Fx.Transitions.Sine.easeOut}).start({'height': [0, 200],'opacity': '0.97'});
		$(div+'_switch').setStyle('display','block');
		$(div+'_container').setStyle('height','241px');
		$('layertitle_back').setStyle('display','block');
	} else {
		new Fx.Morph(div, {duration: 300, transition: Fx.Transitions.Sine.easeIn}).start({'height': [200, 0],'opacity': '0'});
		$(div+'_switch').setStyle('display','none');
		$(div+'_container').setStyle('height','0px');
		$('layertitle_back').setStyle('display','none');
	}
}
