function setBookmark() {
  var brty = navigator.appName;
  var brve = navigator.appVersion;
  var url=document.location.href; 
  var titel = document.title; 
  if (brty.indexOf("Explorer")>-1) {
    // add this page to favorites for IE4+
    window.external.AddFavorite(url,titel);
  } else {
    alert(unescape("Diese Funktion steht nur f%FCr Internet Explorer zur Verf%FCgung"));
  }
}


function Top(){
 document.location.href="#Top";
}

function winOpen(theURL,winName,features) {
  winName = window.open(theURL,winName,features); 
  if(winName == null || winName.closed) {
    window.open(theURL,winName,features);
  } else {
    winName.location.href = theURL;
  } 
  if (!winName.closed) {
    winName.focus(); 
  }
}



$(document).ready(function(){
  initTabs();



// Teaser Border nur einblenden wenn ein Elemente im Teaser vorhanden ist!
//if ($("#teaser").children().size() > 0) {
//   $("div#teaser").addClass("addborder");
// document.getElementById("teaser").style.border = "1px solid #339999";
//}



  /* ::: Start Accordion Function ::: */
  $.each( $("div.onAccordion > div"), function(i, n){
    $(n).children("h2:first-child").addClass("hide");
    jQuery(n).before("<h2 class='onAccHead'>"+$(n).children("h2:first-child").html()+"</h2>");

    if ($(n).hasClass('open')) {
      $(n).prev(".onAccHead").addClass("selected")
      $(n).prev(".onAccHead").addClass("selected")
    } else {
      $(n).addClass("hide");
    }
  });

  $(".onAccHead").click(function() {
    $(this).addClass("current");
    $.each( $(this).parent(".onAccordion").children(".selected:not('.current')"), function(i, n){
      $(n).next("div").animate({ height: 'toggle', opacity: 'toggle'},{duration: 300,
        complete:function(){ 
          $(n).parent(".onAccordion").children(".onAccHead:not('.current')").removeClass("selected");
      } });
    });
    $(this).next("div").animate({ height: 'toggle', opacity: 'toggle'},{duration: 300, 
      complete:function(){
        $(this).prev(".onAccHead").toggleClass("selected");  
        $(this).prev(".onAccHead").removeClass("current");
    } });
  });
/* ##### End Accordion Function ##### */

});


function initTabs() {
  $("div.generate-ui-tab").prepend("<ul></ul>");
  $.each( $("div.generate-ui-tab > .supertab > h2"), function(i, n){
    var test = $(n).html();
    $(n).parent(".supertab").attr("id","tab_"+i+"");
    $(n).parent(".supertab").parent(".generate-ui-tab").children("ul").append("<li><a href='#tab_"+i+"'>"+test+"</a></li>");
    $(n).addClass("hide");
  });
  $.each( $("div.generate-ui-tab"), function(j, m){  
    $.each( $(m).children(".supertab"), function(i, n){  
      if($(n).parent(".generate-ui-tab").children().is(".defaulttab")){
        if($(this).is(".defaulttab")){
          $(this).parent(".generate-ui-tab").children("ul").tabs({ fx: { height: 'toggle', opacity: 'toggle' },selected: i });
        } 
      } else {
        $(n).parent(".generate-ui-tab").children("ul").tabs({ fx: { height: 'toggle', opacity: 'toggle' } });
      }
    });
  });
}















//-->checkbox/radio-replacement<--
jQuery.formreplacement = function () {
	$.each( $("label[for]"), function(i, n){
		if($(n).next("input").hasClass("replace")){
			$(n).next("input").removeClass("replace").addClass("chbxhide");
			if ($(n).next("input").attr("type") == "checkbox") {
				$(n).addClass("chbx");
				$(n).click(function(){
					$(n).toggleClass("chkd");
				});
			} else {
				$(n).addClass("rd");
				$(n).click(function(){
					labelname = $(n).next().attr("name");
					$.each( $("input[name="+labelname+"]"), function(j, o){
						if($(o).hasClass("chbxhide")){
							$(o).prev("label").removeClass("chkd");
						}
					});
					$(n).addClass("chkd");
				});
			}
			if ($(n).next("input").attr("checked")) {
						$(n).addClass("chkd");
			}
		}
	});
};
// addicons //
jQuery.addicons = function(options) {
	var elem = options.split(",");
	for(var i = 0; i<elem.length; i++){
		$(elem[i] +" a[target='_blank']").addClass("blank");
		$(elem[i] +" a[rel='external']").addClass("blank");
		$(elem[i] +" a[href*='pdf']").addClass("pdf");
		$(elem[i] +" a[href*='doc']").addClass("doc");
		$(elem[i] +" a[href*='xls']").addClass("xls");
		$(elem[i] +" a[href*='zip']").addClass("zip");
		$(elem[i] +" a[href*='mp3']").addClass("mp3");
		$(elem[i] +" a[href*='window.print()']").addClass("print");
		$(elem[i] +" a[href*='#top']").addClass("totop");
		$(elem[i] +" a[href*='mailto:']").addClass("mailto");
	}
};

// bpalib //
(function($j){
	$j.bpalib = function(enabled_modules){
		
		var modules = {
			
			striper: function(){
				$j(".striped").children(":odd").addClass("odd");
			},

			popup: function(){
				$j("a[rel^='popup']").click(function(){
					var dims = this.getAttribute('rel').match(/.*\[([0-9]+)-([0-9]+)\].*/);
					window.open(this.getAttribute('href'),'Info','width=' + dims[1] + ',height=' + dims[2] + ',resizable,scrollbars');
					return false;
				});
			},
			external: function(){
				$j("a[rel='external']").click(function(){
					window.open(this.getAttribute('href'));
					return false;
				});
			},
			autoClearInput: function(){
				$j("input.autoclear:text, input.autoclear:password").focus(function(){
					if (this._defaultValue == this.value){
						this.value="";
					}
				})
				.each(function(){
					this._defaultValue = this.getAttribute("value");
				});
			},
			
			autoFocusInput: function(){
				var focusElmts = $j("input.autofocus");
				if (focusElmts.length != 0){
					 focusElmts.get(0).focus();
				}
			}
		};
		
		if (enabled_modules){
			$j.each(enabled_modules,function(i,n){
				if(modules[n]){
					modules[n](i);
				}
			});
		}
		else {
			$j.each(modules,function(i,n){n();});
		}
		
	};
})(jQuery);

// scroll //
jQuery.getPos = function (e)
{
	var l = 0;
	var t  = 0;
	var w = jQuery.intval(jQuery.css(e,'width'));
	var h = jQuery.intval(jQuery.css(e,'height'));
	var wb = e.offsetWidth;
	var hb = e.offsetHeight;
	while (e.offsetParent){
		l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
		t += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
		e = e.offsetParent;
	}
	l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
	t  += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
	return {x:l, y:t, w:w, h:h, wb:wb, hb:hb};
};
jQuery.getClient = function(e) {
	if (e) {
		w = e.clientWidth;
		h = e.clientHeight;
	} else {
		w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
		h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
	}
	return {w:w,h:h};
};
jQuery.getScroll = function (e)  {
	if (e) {
		t = e.scrollTop;
		l = e.scrollLeft;
		w = e.scrollWidth;
		h = e.scrollHeight;
	} else  {
		if (document.documentElement && document.documentElement.scrollTop) {
			t = document.documentElement.scrollTop;
			l = document.documentElement.scrollLeft;
			w = document.documentElement.scrollWidth;
			h = document.documentElement.scrollHeight;
		} else if (document.body) {
			t = document.body.scrollTop;
			l = document.body.scrollLeft;
			w = document.body.scrollWidth;
			h = document.body.scrollHeight;
		}
	}
	return { t: t, l: l, w: w, h: h };
};
jQuery.intval = function (v) {
	v = parseInt(v);
	return isNaN(v) ? 0 : v;
};
jQuery.fn.ScrollTo = function(s) {
	o = jQuery.speed(s);
	return this.each(function(){
		new jQuery.fx.ScrollTo(this, o);
	});
};
jQuery.fx.ScrollTo = function (e, o) {
	var z = this;
	z.o = o;
	z.e = e;
	z.p = jQuery.getPos(e);
	z.s = jQuery.getScroll();
	z.clear = function(){clearInterval(z.timer);z.timer=null};
	z.t=(new Date).getTime();
	z.step = function(){
		var t = (new Date).getTime();
		var p = (t - z.t) / z.o.duration;
		if (t >= z.o.duration+z.t) {
			z.clear();
			setTimeout(function(){z.scroll(z.p.y, z.p.x)},13);
		} else {
			st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;
			sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;
			z.scroll(st, sl);
		}
	};
	z.scroll = function (t, l){window.scrollTo(l, t)};
	z.timer=setInterval(function(){z.step();},13);
};


/*
 * jQuery 'onImagesLoaded' plugin v1.1.0
 * Fires callback functions when images have loaded within a particular selector.
 *
 * Copyright (c) Cirkuit Networks, Inc. (http://www.cirkuit.net), 2008.
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * For documentation and usage, visit "http://includes.cirkuit.net/js/jquery/plugins/onImagesLoad/1.1/documentation/"
 */
(function($){$.fn.onImagesLoad=function(options){var self=this;self.opts=$.extend({},$.fn.onImagesLoad.defaults,options);self.bindEvents=function($imgs,container,callback){if($imgs.length===0){if(self.opts.callbackIfNoImagesExist&&callback){callback(container);}}else{var loadedImages=[];if(!$imgs.jquery){$imgs=$($imgs);}$imgs.each(function(i,val){$(this).bind('load',function(){if(jQuery.inArray(i,loadedImages)<0){loadedImages.push(i);if(loadedImages.length==$imgs.length){if(callback){callback(container);}}}}).each(function(){if(this.complete||this.complete===undefined){this.src=this.src;}});});}};var imgAry=[];self.each(function(){if(self.opts.itemCallback){var $imgs;if(this.tagName=="IMG"){$imgs=this;}else{$imgs=$('img',this);}self.bindEvents($imgs,this,self.opts.itemCallback);}if(self.opts.selectorCallback){if(this.tagName=="IMG"){imgAry.push(this);}else{$('img',this).each(function(){imgAry.push(this);});}}});if(self.opts.selectorCallback){self.bindEvents(imgAry,this,self.opts.selectorCallback);}return self.each(function(){});};$.fn.onImagesLoad.defaults={selectorCallback:null,itemCallback:null,callbackIfNoImagesExist:false};})(jQuery);


$(function(){
  //highlightWord($("body")[0],"Lorem");
  $.bpalib(["striper", "popup", "external", "autoClearInput", "jqtabs"]);
  $.formreplacement();
  $.addicons("body");
  
  // scroll to pagetop
  $('.totop').click(function(){$('#top').ScrollTo(800);return false});
  $('.tonavigation').click(function(){$('#navigation').ScrollTo(800);return false});
  $('.tocontent').click(function(){$('#content').ScrollTo(800);return false});

  //attach onImagesLoad to the body 
  $('body').onImagesLoad({ 
    selectorCallback: selectorImagesLoaded 
  }); 
  //the selectorCallback function, invoked once when all images contained within $('body') have loaded 
  function selectorImagesLoaded($selector){
	//::: set width of image-keeper for IE :::
    //note: $selector is $('body') here
    //$selector.prepend('<div class="loaded">All images have loaded within &lt;BODY&gt;</div>');
    $.each( $("div.imgleft"), function(i, n){
      var imgwidth = $(n).children("img:first:child").width();
      var linkedimgwidth = $(n).children("a:first").children("img:first").width();
      if(imgwidth != null){
        $(n).width(imgwidth+2);
      } else if (linkedimgwidth != null){
        $(n).width(linkedimgwidth+2);
      }
    });
    $.each( $("div.imgright"), function(i, n){
      var imgwidth = $(n).children("img:first:child").width();
      var linkedimgwidth = $(n).children("a:first").children("img:first").width();
      if(imgwidth != null){
        $(n).width(imgwidth);
      } else if (linkedimgwidth != null){
        $(n).width(linkedimgwidth);
      }
    });


  }

});

