
function setitems() {
	
	$$('#setitems ul').each(function(ul) {
		ul.hide();		
		lis = ul.getChildren("li")[0].get("text");
		if ( !$("images_"+lis+"_thumbnailsize") ) {
		} else {
			
			pid = $("images_"+lis+"_thumbnailsize").getParent();	
			ul.getChildren("li")[0].dispose();
		
			pid.addEvent("mouseover",function(p) {
				$$('.product').each(function(div) {
					div.hide();
				});
				
				ul.getChildren("li").each(function(li) {
					$("images_"+li.get("text")+"_thumbnailsize").getParent().show();				
				});
				pid.show();
			});
		}
	});
}

function reload_basket() {
	new Request({
		url: 'ajax.php',
		method: 'get',
		onSuccess: function(responseText) {
			$('shop_warenkorb_mini').set("html",responseText);	
			requested();
		},
		evalScripts: true					
	}).send("action=fmd&id=29&g=1");			

}

function requested() {
	Mediabox.scanPage();

}

function setwait() {

}

function releasewait() {

}

function tobasket() {

	$$('.tobasket').each(function(o) {
		/*
		o.removeEvent("click");
		*/
		o.removeEvents();
		o.addEvent("click",function() {
			setwait();
			new Request({
				url: 'ajax.php',
				method: 'get',
				onSuccess: function(responseText) {
					/*
					*/
					
					reload_basket();
					requested();					
				},
				evalScripts: true					
			}).send("action=fmd&id=32&g=1&tobasket="+o.id);			
		});
		
	});	
}


function log(what,where) {
		$(where).set("text","");
	w = "";
	w += what;
	w += "<br>";
	$(where).set("html",$(where).get("html")+""+w);
}



function navi() {
	$$('ul.level_1 li a').each(function(o) {
		o.getParent().addEvent('click',function() {
			document.location = o.href;
		});
	});

	
	$$('#nav_hauptnavigation').addEvent('mouseover',function() {
		this.setStyle("padding-bottom","30px");
	});
	$$('#nav_hauptnavigation').addEvent('mouseout',function() {
		this.setStyle("padding-bottom","0px");
	});
	
	$$('#nav_hauptnavigation li.submenu ul').each(function(ul) {
		var w = 0;
		ul.getElements("li").each(function(li) {
			w += parseInt(li.measure(function() { return this.getSize().x }));
			if ( li.get("class").contains("last") ) {
			} else {
				w += 5 // im stylesheet nachschauen wie der abstand nach rechts ein soll
			}
		});
		$(ul).setStyle("width",w+"px");
	});

	if ( !$('nav_tableau') ) return false;
	
	$('nav_tableau').addEvent("mouseenter",function() {
		$('nav_tableau').show();
		$$('#nav_hauptnavigation li.tableau').addClass("hover");
	});
	
	$('nav_tableau').addEvent("mouseleave",function() {
		$('nav_tableau').hide();
		$$('#nav_hauptnavigation li.tableau').removeClass("hover");
	});
	
	$$('#nav_hauptnavigation li.tableau').each(function(li) {
		li.addEvent("mouseover",function() {
	
			mex = parseInt(li.measure(function() { return this.getSize().x }));
			mey = parseInt(li.measure(function() { return this.getSize().y }));
						
			$('nav_tableau').setStyle("left",mex+"px");
			$('nav_tableau').setStyle("top",mey+"px");
			$('nav_tableau').show();
			
			
		});
		li.addEvent("mouseout",function() {
			$('nav_tableau').hide();
		});		
	});
	


}

function toggler() {
	$$('.toggler').each(function(o) {
		o.addEvent('click',function() {			
			i = document.location+"?toggler="+o.get("text");
			piwikTracker.trackLink( i, 'link' );
		});
	});	
	
	$$('img').each(function(o) {
		o.addEvent('click',function() {			
			i = document.location+"?img="+o.get("src");
			piwikTracker.trackLink( i, 'link' );
		});
	});	
	
}

function starter() {
	return true;
}

function sameheight() {
	
	sn = $('container').getDimensions().height;
	sn += 122;
	sn += "px";
	if ( $('left') ) $('left').setStyle("height",sn);
	if ( $('right') ) $('right').setStyle("height",sn);
}
	
function site() {
	this.init = function() {

		navi();
		starter();
		tobasket();
		//toggler();
		
		sameheight();
		setitems();
	}
}


site = new site();


window.addEvent('domready', site.init );

function nope() {
	return false;
}
window.onerror = nope;


function scrollpositions() {
	
}

function scrollpositions_alt() {
	scrollpositions1();
	scrollpositions2();
	scrollpositions3();
}

function scrollpositions3() {
	
	if ( !$('mbCenter') ) return false;
	if ( $('mbCenter').getStyle("display").contains("none") ) return false;
	
	ns = Math.floor(window.getSize().y)-Math.floor($('mbCenter').getSize().y/2)+window.getScroll().y;
	$('mbCenter').setStyle("top",ns+"px");
	
	
}

function scrollpositions1() {
	if ( !$('shop_warenkorb_mini')) return false;

	var sc = document.getScroll();
	var sd = $('shop_warenkorb_mini').getSize();
	var sp = $('shop_warenkorb_mini').getPosition();
	if ( sc.y > 125 ) {
		$('shop_warenkorb_mini').addClass("floaty");
	} else {
		$('shop_warenkorb_mini').removeClass("floaty");	
	}

}


function scrollpositions2() {
	if ( !$('nav_links_produkte')) return false;

	var sc = document.getScroll();
	var sd = $('nav_links_produkte').getSize();
	var sp = $('nav_links_produkte').getPosition();
	if ( sc.y > 125 ) {
		$('nav_links_produkte').addClass("floatyb");
	} else {
		$('nav_links_produkte').removeClass("floatyb");	
	}

}

window.addEvent("scroll",scrollpositions);


