var is_win;
var is_mac;
var is_unix;
var client_pc = navigator.userAgent.toLowerCase();
var client_ver = parseInt(navigator.appVersion);
var is_ie = ((client_pc.indexOf("msie") != -1) && (client_pc.indexOf("opera") == -1));
var is_win = (navigator.appVersion.indexOf("win") != -1);
var is_mac = (navigator.appVersion.indexOf("mac") != -1);

if( !is_mac && !is_win ) is_unix = true;
var ns4 = (document.layers)? true:false
var ie4 = (document.all)? true:false
var ns6=document.getElementById&&!document.all?1:0
window.defaultStatus = "";
var menudelay = 500;
var delayflag;

if (ie4) {
	if (navigator.userAgent.indexOf('MSIE 5')>0) {
		ie5 = true;
	} else {
		ie5 = false; }
} else {
	ie5 = false;
}

function preloadImages()
{ 
	var d=document; 
	if(d.images)
	{ 
		if(!d.MM_p)
		{
			d.MM_p=new Array();
		}
    	var i,j=d.MM_p.length,a=preloadImages.arguments; 
    	for(i=0; i<a.length; i++)
    	{
    		if (a[i].indexOf("#")!=0)
	    	{ 
	    		d.MM_p[j]=new Image; 
	    		d.MM_p[j++].src=a[i];
	    	}
    	}
	}
	
}

function reIm() { 
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function fiOb(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=fiOb(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function chIm() { 
  var i,j=0,x,a=chIm.arguments; document.sr=new Array; for(i=0;i<(a.length-1);i+=2)
   if ((x=fiOb(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+1];}
}

function shLa() {
  var i,p,v,obj,args=shLa.arguments;
  for (i=0; i<(args.length-1); i+=2) if ((obj=fiOb(args[i]))!=null) { v=args[i+1];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function shNa(nmbr) // show specified rollover&layer and hide others
{
	sh_args = new Array();
	reIm();
	for (i=1; i<=6 ; i++)
	{
		shLa('lay'+i, (i==nmbr)?'show':'hide');
	}		
	chIm('nav'+nmbr,root_path+'img/butstr.gif',1);
}

function rePa() // reset Page
{
	reIm();
	for (i=1; i<=6 ; i++)
	{
		shLa('lay'+i, 'hide');
	}		
}

function reDe() // reset Page after Delay
{
	delayflag = window.setTimeout("rePa()", 500);
}

function noRe() // delete Timeout for rePa()
{
	window.clearTimeout(delayflag);
}

function f1(id, show){
id2 = id;
show2 = show;
if(NS4){
	if(show2 == true)
	vis = "show";
	else
	vis = "hide";
	
	if(document.layers[id2].visibility != vis){
	if(vis == 'hide')
		delayflag = setTimeout("eval('f2(id2,show2)')", menudelay);
	else
		f2(id2,show2);
	}
}else if(IE4){
	if(show2 == true)
	vis = "visible";
	else
	vis = "hidden";
	if(document.all[id2].style.visibility != vis){
	if(vis == 'hidden')
		delayflag = window.setTimeout("eval('f2(id2,show2)')", menudelay);
	else
	f2(id2,show2);
}
}
}

function f2(id, show){
if(NS4){
if(show){
clearTimeout(delayflag);
document.layers[id].visibility = "show";
}else{
document.layers[id].visibility = "hide";
}
}else if(IE4){
if(show){
clearTimeout(delayflag);
document.all[id].style.visibility = "visible";
}else{
document.all[id].style.visibility = "hidden";
}
}
}

function h(htext){
window.status = htext;
}
function hf(objName, newText)
{
  status=newText;
  document.bon_returnValue = true;
  var obj = fiOb(objName); 
  if (obj) obj.value = newText;
}
function set_bg(obj)
{
	obj.style.backgroundColor = 'FFCCCC';
}
function unset_bg(obj)
{
	obj.style.backgroundColor = '';
}
function f3(layerID, imageID, newImage){
if(NS4){
cmd = "document."+ layerID +".document."+ imageID +".src = '/media/"+ newImage +".gif'";
eval(cmd);
}else if(IE4){
document.images[imageID].src = "/media/" + newImage + ".gif";
}
}
function f4(layerID, imageID, newImage){
if(NS4){
cmd = "document."+ layerID +".document."+ imageID +".src = newImage";
eval(cmd);
}else if(IE4){
document.images[imageID].src = newImage ;
}
}
function x(layerid,id){
if(document.layers){
temp = eval("document."+ layerid +".document."+ id);
}else if(document.all){
temp = eval(id + ".style");
}
temp.backgroundColor = "#000000";
}
function y(layerid,id){
if(document.layers){
temp = eval("document."+ layerid +".document."+ id);
}else if(document.all){
temp = eval(id + ".style");
}
temp.backgroundColor = "#cd0000";
}
function m(url){
window.location.href=url;
}
function sc(ta) 
{
	if (ta.createTextRange) ta.cp = document.selection.createRange().duplicate();
}
function opclw(pgc,u,W,H,X,Y,n,b,x,m,r) {
	var CWIN=window.open(u,n,'width='+W+',height='+H+',scrollbars=yes',true);
	CWIN.moveTo(50,50);
	CWIN.focus();
}

/**
 * deletes all options from select box
 *
 * @param	obj		Object of select box
 */ 
function delete_opt_val(obj)
{
	// terminate condition
	if(obj == null)
	{
		return false;	
	}	
	
	for( i = obj.options.length; i >= 0; i--)
	{
		obj.options[i] = null;
	}
	
	return true;
	
}	// eo delete_opt_val()


function box_close() {
	var box_obj =  $("#" + $("#bon-overlay").attr("rel"));
	box_obj.animate({'left': (-1 * box_obj.width()) - 10 }, 500, function() { box_obj.hide(); $("#bon-overlay").hide(); });
}

function box_print() {

        $("#" + $("#bon-overlay").attr("rel")).printElement();
}

function bon_reposition() {

	var w_width = $(window).width();
	
	$("#wrapper").css("left", ( (w_width > 968) ? ((w_width - 928) / 2) : '20') + 'px');
	$("body").css("background-position", ( (w_width > 968) ? ((w_width - 968) / 2) : '0') + 'px 0px');
}

function box_reposition(obj) {
	var scrollTop = $(window).scrollTop();
	var w_width = $(window).width();
	var w_height = $(window).height();
	var box_height = parseInt(obj.css("height"));
	var box_width = parseInt(obj.css("width"));
	var target_x = (w_width - box_width) / 2;
	var target_y = scrollTop + (w_height - box_height) / 2;
	target_y = target_y < scrollTop ? scrollTop : target_y;
	obj.stop().animate({'left': (target_x + 10) + 'px', 'top': target_y + 'px'}, 500);
}

$(function() 
{
	$(".divToggle").bind('mouseover', function() {
		$(".divToggle").not($(this)).next().slideUp("normal");
		$(this).next(":hidden").slideDown("normal");
	}).next().hide();
	
	// Bei Verlassen des Nav-Bereichs offenen Punkt schließen und aktiven oeffnen
	$(".nav").bind('mouseleave', function() {
		$(".divToggle").not($(".activated")).next().slideUp("normal");
		$(".activated").next().slideDown("normal");
	});

	$(".activated").next().show();
	$(".scrolling-content").hide();
	
	$(window).resize(function(){
		//bon_reposition();
		if($("#bon_box:visible").length > 0)
		{
			box_reposition($("#bon_box"));
		}
	});
	
	$(window).scroll(function () { 
		if($("#bon_box:visible").length > 0)
		{
			box_reposition($("#bon_box"));
		}
	});
	
	//bon_reposition();
	
	$("#bon-overlay").css("opacity", 0.8).show().attr("rel", "bon_box").click(function() {
		box_close();																  
	});
	
	var box_obj = $("#bon_box");
	box_obj.show();
	box_reposition(box_obj);
});
