document.onload=function(){
	if(arguments.callee.inited) return;
	else arguments.callee.inited=1;
	
	_("div.image").insert("s");
	_("ul.menu a:0").insert("i").classname("con");
	
	if(_("div.slideshow")){
		new SlideShow(_("div.slideshow"), {img:"img:0", link:"a:0", items:"div a"}, {delay:5});
		_("div.slideshow_box").insert("i").classname("slideshow_con_l");
		_("div.slideshow_box").insert("i").classname("slideshow_con_r");
	}
	
	if(_("div.slider_logos")){
		new _Slider(_("div.slider_logos"), {canvas:"div.canvas", scroll:"span", arr_l:"a.arr_l", arr_r:"a.arr_r"});
	}
	
	//init sub menu
	_("ul.menu li ul").repeat(function(){create_shad_block(this)});
	_("div.top ul").repeat(function(){create_shad_block(this)});
	
	
	if(BROWSER.ie6){
		
		_("ul.menu>li").event({
			onmouseover:function(){this.classname("+hover");},
			onmouseout:function(){this.classname("-hover")}
		});
		
		ie6_fixes(document);
	}
	
	if(window.$ && _("a.fancybox")){
		$("a.fancybox").fancybox({'titleShow':false, 'transitionIn':'elastic','transitionOut':'elastic','overlayOpacity':0.7,'overlayColor':'#000'});
	}
	
	
	var js_dir=get_js_dir('script.js');
	
	if(window.sIFR){
		var sifr_font_1 = { src: js_dir+'sifr/thesanslight.swf' };
		var sifr_font_2 = { src: js_dir+'sifr/thesanslight-italic.swf' };	
		sIFR.useStyleCheck = true;
	
		sIFR.activate(sifr_font_1);	
		sIFR.activate(sifr_font_2);	
		
		sIFR.replace(sifr_font_1, {
		  selector: 'h1.big'
		  ,css: '.sIFR-root { font-size:33px; color: #ffffff; letter-spacing:0.5; leading:-18; }'
		  ,wmode: 'transparent'
		  ,tuneHeight: (+10)
		});
		sIFR.replace(sifr_font_1, {
		  selector: 'h1'
		  ,css: '.sIFR-root { font-size:29px; color: #ffffff; letter-spacing:0.5; leading:-18; }'
		  ,wmode: 'transparent'
		  ,tuneHeight: (+10)
		});
		sIFR.replace(sifr_font_1, {
		  selector: 'h2'
		  ,css:[ '.sIFR-root { font-size:29px; color: #3a8cd6; leading:-12; }', 'a { text-decoration: none; color:#3a8cd6; }', 'a:hover { text-decoration: underline; color:#3a8cd6; }']
		  ,wmode: 'transparent'
		  ,tuneHeight: (+1)
		});
		sIFR.replace(sifr_font_2, {
		  selector: 'blockquote'
		  ,css: '.sIFR-root { font-size:25px; color: #6E747A; leading:-5; text-align:center; }'
		  ,wmode: 'transparent'
		  ,tuneHeight: (+1)
		});
	}
	
	_("a.showhide_o").repeat(function(i){
		if(i || this.target=="kundenliste") showhide(this, 1);
		if(!this.trigger){
			var _this=this;
			this.trigger=_(this.parentNode, "h2") || _(this.parentNode, "h5");
			this.trigger.event({onclick:function(){showhide(_this)}});
			//this.trigger.css({"cursor":"pointer"});
		}
	});
};

	

function addEvent(el, evname, func) {
	if(!el["on"+evname] && el!=window && el!=document) return el["on"+evname]=func;
	if(el.attachEvent) el.attachEvent("on"+evname, func); // IE
	else if(el.addEventListener) el.addEventListener(evname, func, true); // Gecko / W3C
	else el["on"+evname]=func;
};
	addEvent(window, "load", function(){
		setTimeout(function(){
			_(".page h2").repeat(function(i){
				//if(_(this, "object").offsetHeight>50) alert(_(this, "object").offsetHeight);//
				this.css({height:"auto"});
			});
		}, 500);
	});


function create_shad_block(obj){
		obj.css({display:"block"});
		var sub=_(obj.parentNode).insert("div").classname("sub");
		var h=obj.offsetHeight;
		sub.insert("div").classname("sub_m").css({height:h}).insert("div");
		sub.insert("div").classname("sub_r").css({height:h}).insert("div");
		sub.insert("div").classname("sub_c").insert("div");
		sub.insert("div").classname("sub_b").insert("div");
		sub.insert("div").classname("sub_a").insert("div");
		sub.insert(obj);
		if(BROWSER.ie){
			var minW=parseInt(sub.currentStyle["min-width"] || sub.css("minWidth"));
			sub.css({width:obj.offsetWidth>minW?obj.offsetWidth:minW});
		}
}



function lang_show(obj){
	obj.isOpen=obj.isOpen?0:1;
	_(obj.target, "<").slide(obj.isOpen);
	return false;
}


function get_js_dir(cur_fname){
	var path="";
	re=new RegExp(cur_fname+"$");
	_("script").repeat(function(){if(re.test(this.src)) path=this.src.replace(re, "")});
	return path;
}


function showhide(obj, first_hide_mode){
	var target=_(obj.parentNode, "."+obj.target);
	if(!target) return false;
	if(!obj.alt_real) obj.alt_real=obj.innerHTML;
	if(obj.first_hided){target.css({height:"auto", overflow:"visible"}); target.slide(); obj.first_hided=null}
	if(first_hide_mode) obj.first_hided=target.css({height:"0", overflow:"hidden"});
	else target.slide();
	_(obj).classname("showhide_"+(target.isVisible?"o":"c"));
	_(obj).innerHTML=obj.attr(target.isVisible?"alt_real":"alt");
	return false;
}


function init_sum_fields(id){
	var root=_(id);
	var div=_(root.parentNode).insert("div", root);
	div.classname("budget_block").insert(root);
	var inps=_(root, ".inp_1");
	inps.event({onkeyup:function(){
		if(/[^0-9]/.test(this.value)) this.value=this.value.replace(/[^0-9]/, "");
		_(root, ".inp_2").value=calc_fields(inps);
	}});
}

function calc_fields(inps){
	var sum=0;
	inps.repeat(function(){sum+=Number(this.value)});
	return sum;
}
