window.addEvent('domready', function() {

if ($("menu_glowne")) {

	var margin_element = new Fx.Tween($("prawa_strona").getFirst(), {link:"cancel", transition: Fx.Transitions.Quad.easeInOut});
		

	$("menu_glowne").getElements("a").forEach(function(el,index){
	
		el.addEvent("mouseover", function() {
		
			margin_element.start('margin-top',(index)*-340)
		
		})
	
	
	})


}

if ($("oferta")) {

	var size2 = $("lewa").getSize();

	$("lewa").getElements("ul").forEach(function(el) {
		
		var size = el.measure(function(){
		    return this.getSize();
		});
		
		var position = el.measure(function(){
		    return this.getPosition($("lewa"));
		});
				
		var t = size.y + position.y;
				
		if (t > size2.y) el.setStyle("margin-top", -1*(size.y+position.y-size2.y)-10)
	
	})

	$("lewa").getElements("li > a, li > span").forEach(function(el) {
	
		el.addEvent("mouseover",function() {
		
			this.getParent().getSiblings().getElements("ul").forEach(function(el_ul){
				el_ul.setStyle("display","none");	
			});

			this.getParent().getSiblings().getElements("li").forEach(function(el_sib){
				el_sib.removeClass("hover");
			})

			this.getParent().getSiblings().forEach(function(el_sib){
				el_sib.removeClass("hover");
			})

			
			if (this.getParent().getChildren().length>1) {
				this.getParent().getElement("ul").setStyle("display","block");
				this.getParent().addClass("hover");
			}
		
		})
	
	})

	$("lewa").addEvent("mouseleave", function() {
	
		$("oferta").getElements("ul ul").setStyle("display","none");
		$("oferta").getElements("li.trail > ul").setStyle("display","block");
	
	})
}


if (Browser.safari){

alert("x");

}

})
