/* 
  +-------------------------------------------------------------------------+
  | JavaScript von joseph-marx-gesellschaft.org, 2006-05-27                 |
  | Autor: Oliver Prygotzki <http://oliver.prygotzki.de/>                   |
  +-------------------------------------------------------------------------+
*/

/* +++ Support for :hover on IE/Win ++++++++++++++++++++++++++++++++++++++ */

function ieHover(id,tag) 
{
  if (!document.getElementById || !document.getElementsByTagName) {
    return;
  }
  
  id = document.getElementById(id);
  if (!id) {
    return;
  }
  
  var list = id.getElementsByTagName(tag);
  if (!list) {
    return;
  }

  for (var i = 0; i < list.length; i++) {
	list[i].onmouseover = function() {
      this.className += " iehover";
	  this.innerHTML += ''; // Force redraw
	};
	list[i].onmouseout = function() {
	  this.className = this.className.replace(' iehover', '');
	  this.innerHTML += ''; // Force redraw
	};
  }
}

if ((navigator.appVersion.indexOf('MSIE 5') != -1 || navigator.appVersion.indexOf('MSIE 6') != -1) && navigator.appVersion.indexOf('Mac') == -1 && navigator.appVersion.indexOf('Opera') == -1) {
  addEvent(window,"load", function() {
    ieHover("menu","LI");
  } );
}

function getid(id)
{
  if (document.getElementById) {
    return document.getElementById(id); }
  else if (document.all) { 
    return document.all[id]; }
  else if (document.layers) { 
    return document.layers[id]; }
  else { 
    return null; }
}

function getBrowserWidth()
{
  if (window.innerWidth) {
    return window.innerWidth; }
  else if (document.documentElement && document.documentElement.clientWidth !== 0) {
    return document.documentElement.clientWidth; }
  else if (document.body) {
    return document.body.clientWidth; }
  else {
    return 0; }
}

function getBrowserHeight()
{
  if (window.innerHeight) {
    return window.innerHeight; }
  else if (document.documentElement && document.documentElement.clientHeight !== 0) {
    return document.documentElement.clientHeight; }
  else if (document.body) {
    return document.body.clientHeight; }
  else {
    return 0; }
}

function addEvent(el, trigger, event)
{
  var x = el;
  if (typeof el == 'string') {
    el = getid(el); }
  if (el === null) {
    if ('{LOCALHOST}' === '1')
      alert('Interner Fehler: NULL on '+x); /* XXX */
    return; }
  if (typeof el.addEventListener != 'undefined') {
	el.addEventListener(trigger, event, false); 
  }
  else if (el == window && typeof document.addEventListener != 'undefined') {
	document.addEventListener(trigger, event, false); 
  }
  else if (typeof el.attachEvent != 'undefined') {
	el.attachEvent('on'+trigger, event); }
  else {
    var eventChain = (eval('typeof el.on'+trigger) == 'function') ?
      eval('el.on'+trigger) : function() {};
  
    eval('el.on'+trigger+' = function()\n'+
'{\n'+
'eventChain();\n'+
'event();\n'+
'};');
  }
  return true;
}

function cancelEvent(event)
{
  if (event.preventDefault) event.preventDefault();
  if (event.stopPropagation) event.stopPropagation();
  if (this.cancelBubble) this.cancelBubble = true;
  if (event.returnValue) event.returnValue = false ;
  return false ;
}

function preload()
{
  for (var i = 0; i < arguments.length; i++) {
    (new Image()).src = arguments[i]; }
}

function sleep(ms)
{
  ms += (new Date()).getTime();
  while ((new Date()).getTime() < ms) {
  }
}

/* ------------------------------------------------------------------------ */

function drucken()
{
  switchlayout('lowend'); 
  sleep(1500);
  window.print(); 
  checkLayout();
}

function switchlayout(newstate)
{ 
	$('BODY:not(.start)').attr('class',newstate);
	var body = getid("body");
    body.innerHTML += ''; // Force redraw
    if (document.cookie) {
      document.cookie = ";path=/;domain=www.joseph-marx-gesellschaft.org;expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
    document.cookie = newstate+";path=/;domain=www.joseph-marx-gesellschaft.org";
}

var screen_size = null;

function checkLayout()
{
  if (getBrowserWidth() < 700 || getBrowserHeight() < 600) {
    screen_size = false;
    switchlayout('lowend'); 
  } else {
    screen_size = true;
    switchlayout('highend'); 
  }
}

function append(text)
{
  var body = getid("body");
  if (body !== null) {
    body.innerHTML += text;
  }
}

/* ------------------------------------------------------------------------ */

function addStyleRule(stylesheet, selector, rule) {
  if (!document.styleSheets) {
    return; }
  if (stylesheet === null) {
  	stylesheet = document.styleSheets[document.styleSheets.length-1]; }

	if (stylesheet.addRule) {
	  stylesheet.addRule(selector, rule); }
	else {
		var index = stylesheet.cssRules.length;
		stylesheet.insertRule(selector + "{" + rule + "}", index);
	}
}

function getLang($$)
{
  return $('HTML').attr('lang');
  
//   while (!$$.attr('lang')) {
//     $$ = $$.parent();
//   }
//   return $$.attr('lang');
}

function silbentrennung()
{
	var lang = $('HTML').attr('lang');
	if (!lang) {
	  lang = 'de';
	}
		
	$('P, LI, BLOCKQUOTE').each(function() {
	  var $$ = $(this);
	  var ta = $$.css('text-align');
	  if (ta == ''||ta.toUpperCase() == 'LEFT'||ta.toUpperCase() == 'START'||ta.toUpperCase() == 'AUTO') {
	  $$.filter(':not(.donthyphenate)').addClass('hyphenate');
		if (!$$.attr('lang')) {
			$$.attr('lang',lang);
		}
	  }
	});

	Hyphenator.run();
}

var tech_hinweis_2 = 'Technischer Hinweis: Wenn Sie <strong>das Browserfenster vergrößern</strong>, wird die Seite in einem schöneren Layout angezeigt.';
var tech_hinweis_3 = 'Technischer Hinweis: Wenn Sie <strong>CSS</strong> aktivieren und diese Seite neu laden, wird sie in einem schöneren Layout angezeigt.';

function runonload() 
{
  checkLayout();
  
  if (screen_size !== true) {
    append('<div id="tech_hinweis" class="noprint">\
<hr class="hidden">'+tech_hinweis_2+'</div>');
  }
  
  append('<div class="hidden"><hr>'+tech_hinweis_3+'</div>');
 
  if ($('BODY:not(.start)').length) {
	  silbentrennung();
  }  
}

$(runonload);

$(window).bind('resize',checkLayout);


/* ------------------------------------------------------------------------ */
/* --- End of JavaScript by Oliver Prygotzki ------------------------------ */
/* ------------------------------------------------------------------------ */

