/*
 * Hinweis auf veralteten Browser
 * http://www.browser-update.org/
 */
var $buoop = {} 
$buoop.ol = window.onload; 
window.onload=function(){ 
  if ($buoop.ol) $buoop.ol(); 
  var e = document.createElement("script"); 
  e.setAttribute("type", "text/javascript"); 
  e.setAttribute("src", "http://browser-update.org/update.js"); 
  document.body.appendChild(e); 
}
/*
 * jSEfU Tooltips
 * http://jquery.com/
 */

$(window).load(function () {
  $('.visible').hide();
  $('.invisible').fadeIn();
  
  // Im Fehlerfall zur ersten Fehlermeldung scrollen
  if ($(".ui-state-error.ui-corner-all").length > 0) {
    $('html, body').animate({scrollTop: $(".ui-state-error.ui-corner-all:first").offset().top - 20}, 1000);
  }
});

$(document).ready(function() {
  // Buttons
  // $(".radio_list").buttonset();
  // SubMenuitems
  $("ul.nav li[class!=secondary] ul li[title]").tooltip({
      tipClass: "square_tooltip_right", 
      offset: [10, 10], 
      position: 'center right', 
      effect: 'slide'
    }).dynamic({ bottom:{ direction: 'left', bounce: true }});
  // Secondary SubMenuitems
  $("ul.nav li.secondary ul li[title]").tooltip({tipClass: "square_tooltip_left", offset: [10, -10], position: 'center left', effect: 'slide'}).dynamic({ bottom:{ direction: 'left', bounce: true }});
  // Menüitems Toplevel
  $("ul.nav li[title]").tooltip({tipClass: "bubble_tooltip_top", offset: [10, 2], effect: 'slide'}).dynamic({ bottom:{ direction: 'down', bounce: true }});
  // Formularfelder
  $("form :input[title]").tooltip({tipClass: "square_tooltip_right", position: "center right", offset: [-2, 10], effect: "fade", opacity: 0.9 });
  // Kategorieauswahl
  $(".catbox[title]").tooltip({
    tipClass: "square_tooltip_category", 
    position: "center right", 
    offset: [-2, 10], 
    effect: "fade", 
    opacity: 0.9
  });
  // Tabellenelemente
  $("td[title]").tooltip({tipClass: "square_tooltip_right", position: "center right", offset: [-2, 10], effect: "fade", opacity: 0.9 });
  
  // Icons
  $("a img[class^=erlaeuterung_]").hover(
      function () {
        $("#"+this.className).addClass('erlaeuterung_highlight');
      },
      function () {
        $("#"+this.className).removeClass('erlaeuterung_highlight');
      }
    );
    
  // Secondary SubMenuItems nicht über den Seiterand hinausschauen lassen
  $("ul.nav li.secondary:first ul li a").width($("ul.nav.main li.secondary:first a").width());
    
  // Fancybox
  if(typeof $("a.zoom").fancybox == 'function') { 
    $("a.zoom").fancybox(); 
  }
  
  // nav in IE6
  if ($.browser.msie && $.browser.version.substr(0,1)<7) {
    // search for selectors you want to add hover behavior to
     $('ul.nav li').hover(
       function() {
         $(this).children('ul').css('display', 'block')
                               .css('height', '100px')
                               .css('width', '100px');
       },
       function() {
         ($(this).children('ul')).css('display', 'none');
       });
  }
  
  // Adds event handler to each submit 
  // Button to hide it after clicking
  $(document).ready(function() {
    $('button:submit').click(function() {
      $(this).after($('<span/>').addClass('spinning').html('L&auml;dt...bitte warten!')).hide().submit();
    });
  });
  
  // Prevent text selection on elements
  // with css class noSelect
  $.extend($.fn.disableTextSelect = function() {
		return this.each(function(){
			if($.browser.mozilla){//Firefox
				$(this).css('MozUserSelect','none');
			}else if($.browser.msie){//IE
				$(this).bind('selectstart',function(){return false;});
			}else{//Opera, etc.
				$(this).mousedown(function(){return false;});
			}
		});
	});
	$('.noSelect').disableTextSelect();
});
