//Robert Penner Easings (gibt keine besseren)
jQuery.extend(jQuery.easing, {
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeInCubic: function(x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function(x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	}
});
function initSite() {
	var onstart = [];
	middle_open = {};
	left_open = {};
	var act = $(".breadcrumb,.breadcrumb_black").text();
	var dtm = false;
	if(act && act.indexOf("DTM") > -1) {
		dtm = true;
	}
	$(".left .toggle").each(function() {
		var rel = $(this).attr("rel");
		var idx = rel.split("_")[2];
		this.rel = rel;
		this.block = $("#"+rel);
		this.block.hide();
		if(idx==(dtm ? 1 : 0)) {
			onstart.push(this);
		}
	}).toggle(function() {
		this.block.slideDown();
		$(this).addClass("hover");
		for(var n in left_open) {
			if(left_open[n] && n != this.rel) {
				$(".left .toggle[rel="+n+"]").click();
			}
		}
		left_open[this.rel] = true;
		
	},function() {
		left_open[this.rel] = false;
		this.block.slideUp();
		$(this).removeClass("hover");
	});
	
	$(".middle .toggle").each(function() {
		var rel = $(this).attr("rel");
		var idx = rel.split("_")[2];
		this.rel = rel;
		this.block = $("#"+rel);
		this.block.hide();
		if(idx==0) onstart.push(this);
	}).toggle(function() {
		this.block.slideDown();
		$(this).addClass("hover");
		for(var n in middle_open) {
			if(middle_open[n] && n != this.rel) {
				$(".middle .toggle[rel="+n+"]").click();
			}
		}
		middle_open[this.rel] = true;
		
	},function() {
		middle_open[this.rel] = false;
		this.block.slideUp();
		$(this).removeClass("hover");
	});
	var sd = $(".submenu li").length > 1;
	if(sd) $(".submenu").hide();
	setTimeout(function() {
		if(sd) $(".submenu").slideDown();
		for(var i=0;i<onstart.length;i++) {
			$(onstart[i]).click();
		}
		delete onstart;
	},500);
	var idx = 0;
	sidebar_data = {
		cur:0
	}
	$(".sidebar_link").each(function() {
		this.idx = idx;
		idx++;
	}).hover(function() {
		if(sidebar_data.cur == this.idx) return;
		//$(".sidebar :animated").stop(false,true);
		
		$("#sb_p"+sidebar_data.cur).fadeOut();
		$("#sb_l"+sidebar_data.cur).removeClass("active");

		$("#sb_p"+this.idx).fadeIn();
		$(this).addClass("active");
		
		sidebar_data.cur = this.idx;
	});
	$(".hoverImg").each(function() {
		this.orig = this.src;
		this.over = $(this).attr("rel");
		this.act = this.over != "";
	}).hover(function() {
		if(this.act) this.src = this.over;
	},function() {
		if(this.act) this.src = this.orig;
	});
	window.setTimeout(initLogo,1500);
}

function onVideoPlayPause(ident,f) {
}
function onVideoInitialized(ident) {
	flTell(ident,"showVideo");
}
function onVideoDone(ident) {
}
function getVideoData(ident) {
	var res = videos[ident];
	return res;
}
function flTell(ident,fn,p) {
	var fl = document.getElementById(ident);
	if(!fl) return;
	fl.flCall(fn,p);
}
function initPictures(id) {
	var nid = "#"+id;
	var el = window['pictureSet'+id] = {cur:0,nid:nid};
	var m = 0;
	$(nid+" img.picture").each(function() {
		var h = $(this).height();
		m = Math.max(m,h);
	}).css({top:0,left:0});
	$(nid+" .pictures").height(m);
	
	var idx = 0;
	$(nid+" img.thumb").each(function() {
		this.idx = idx;
		idx++;
	}).click(function() {
		var img = $(nid).find(".picture:eq("+this.idx+")").css("position","absolute").fadeIn("fast");
		if(this.idx != el.cur) $(nid).find(".picture:eq("+el.cur+")").fadeOut("fast");
		el.cur = this.idx;
	}).css({cursor:"pointer"});
	
}
function initLogo() {
	var lg = $("#logoBox");
	if(!lg || lg.length==0) return;
	var pict = lg.find("img");
	var a = lg.find("a");
	if(!pict || pict.length==0 || !a || a.length==0) return;
	var href = a.attr("href");
	var w = pict.width();
	var h = pict.height();
	if(w < 1) return;
	var el = lg.get(0);
	if(!el) return;
	var href = a.attr("href");
	lg.css({width:w,height:h,position:"relative",overflow:"hidden"});
	var params = {
		movie:"files/logo-intact.swf",
		allowFullScreen:"false",
		FlashVars:"ident=flLogo&href="+escape(href),
		quality:"high",
		bgcolor:"#000000",
		wmode:"opaque",
		menu:"false"
	}
	var ob = "<object id='flashLogo' name='flashLogo' type='application/x-shockwave-flash'";
	ob += " data='files/logo-intact.swf' width='"+w+"px' height='"+h+"px'>";
	var pp = "";
	for(var n in params) {
		pp += "<param name='"+n+"' value='"+params[n]+"'>";
	}
	ob += pp+"</object>";
	var div = document.createElement("div");
	div.style.position="absolute";
	div.style.width=w+"px";
	div.style.height=h+"px";
	div.style.top="-2px";
	div.style.left="-1000px";
	div.id="flHolder";
	el.appendChild(div);
	div.innerHTML=ob;
	
}
function onLogo(s) {
	mv = document.getElementById("flashLogo");
	if(!mv) return;
	switch(s) {
		case "ready":
			$("#flHolder").css({left:"1px",cursor:"pointer"});
			$("#logoBox a img").hide();
			$("#logoBox a").remove();
			tellLogo("start");
		break;
		case "done":
			window.setTimeout(function() {
				tellLogo("start");
			},3500);
		break;
		default:
			
	}
}
function tellLogo(s) {
	mv = document.getElementById("flashLogo");
	if(!mv) return;
	mv.logoDo(s);
}
function trace(s) {
	if(window.console) console.log(s);
}
function initBatteryBrowser(o) {
	var c = $("#"+o.id);
	if(!c || !c.length) return;
	o._width = c.width();
	var idx = 0;
	o.maxHeight = 0;
	o.slides = c.find(".slides .holder");
	o.texts = c.find(".texts .holder");
	o.menu = c.find(".slideMenu");
	o.length = c.find(".slide").length;
	c.find(".holder").width(o._width*o.length);
	c.find(".slideText").each(function() {
		this.style.visibility = "visible";
		o.maxHeight = Math.max(o.maxHeight,$(this).height());
		
	});
	o.menu.find("a").each(function() { this.idx = parseInt(this.rel)}).click(function() {
		o.select(this.idx,false);
		return false;
	});
	if(o.length > 1) {
		c.find(".buttonFwd").click(function() {	o.select(0,1); });
		c.find(".buttonBwd").click(function() {	o.select(0,-1);	});
	} else {
		$(".buttonFwd,.buttonBwd",c).hide();
	}
	o.select = function(i,d) {
		var tx = 0;
		if(d) {
			o.cur += d;
			if(o.cur >= o.length) o.cur = 0;
			if(o.cur < 0) Math.max(o.cur = o.length-1,0);
		} else {
			o.cur = i;
		}
		tx = -o.cur*o._width;
		
		o.slides.animate({left:tx},700,"easeInOutCubic");
		o.texts.animate({left:tx},700,"easeInOutCubic");
		o.menu.find("a").each(function() {
			this.className = this.idx==o.cur ? "active" : "";
		});
	}
	c.find(".texts").css({height:o.maxHeight});
	o.cur = 0;
	o.select(0);
}