/*******************************************************
* Anpassen an Browserfenster
* COOKIES für font-size
* Last Update
	
*******************************************************/

/***********************************
    Globales
***********************************/

document.write ('<style> #main{} #nav{} #main .pageindex{} .vokabels{} .sidebox{} .sidebox_left .sidebox{} body{}</style>');   
var newCSS = document.styleSheets[document.styleSheets.length-1],
  newRules = newCSS.cssRules || newCSS.rules;  // für alle Browser ansprechbar
  
function getClassNames(array, className, tagName) {
  array = [];
  for (i in document.getElementsByTagName(tagName))     
	if (document.getElementsByTagName(tagName)[i].className==className)
	  array[array.length] = document.getElementsByTagName(tagName)[i];
  if (array[0]) return array;
  else return null;
}


/***********************************
    Anpassen an Browserfenster
***********************************/

function sizeX() {	
  var normW = 1024, 
    thisW = window.innerWidth ||  document.documentElement.offsetWidth || 0,
    rand_abstand = (thisW > normW)? Math.round((thisW - normW)/20*3) : 0;
  if (newRules) {
    newRules[0].style.marginRight =  
    newRules[0].style.marginLeft = (100+rand_abstand)+'px'; //#main
    newRules[1].style.left = rand_abstand+'px'; //#nav
    newRules[2].style.right = rand_abstand+'px'; //.pageindex
    newRules[3].style.marginRight = (-rand_abstand-220)+'px'; //.vokabels
    newRules[4].style.right = rand_abstand+'px'; //.sidebox 
    newRules[5].style.left = rand_abstand+'px'; //.sidebox_left .sidebox
  }
} 
sizeX();

////////////////////////////////////////////////////
///           COOKIES für font-size             ////
//credits: PPK, www.quirksmode.org/js/cookies.html//

function checkFont() {
  var newFont = 15;
  if (document.cookie) {
    ca = document.cookie.split(';');
    for(var i in ca) {
      var c = ca[i].replace(/\s/g,'');
	  if (c.indexOf("rjFont=") == 0) 
	    newFont = c.substring(7,c.length); // 7 = 'rjFont='.length
	}
  }
  return newFont;
}

var fontGr = checkFont();
newRules[6].style.fontSize = fontGr+"px";

function setFont(size) {
  var date = new Date(), days = 60;
  date.setTime(date.getTime()+(days*24*60*60*1000));
  var expires = '; expires='+date.toGMTString();
  document.cookie = 'rjFont='+size+expires+'; path=/';
  writeFont(size);
}	 

function writeFont(size) {  
  if (typeof document.body.style.maxHeight == "undefined" || //exclude IE < 7
   !navigator.cookieEnabled ) 
      return; 
	  
  var fontSize = size || fontGr;
  newRules[6].style.fontSize = fontSize+"px";
    
  var topLine = ( document.getElementById("topline").className == "side" ) ? document.body : 
    document.getElementById("topline"),
    ftChanger = document.getElementById('fontS') || 
      topLine.insertBefore(document.createElement('div'), topLine.firstChild); 
      ftChanger.id = "fontS";   
      ftChanger.innerHTML='Schriftgr&ouml;&szlig;e <strong id="q">'+fontSize+'px</strong> +/&minus;';
	
  var ftWahl= ftChanger.appendChild(document.createElement('div')),
	font = [13, 15, 16, 18, 20];
	  
  for (var i=0; i<font.length; i++) {
	with (ftWahl.appendChild(document.createElement('a'))) {
	  innerHTML = font[i];
	  style.fontSize = font[i]+'px';
	  //h = parseInt(style.height);
	  //style.top = Math.floor(36-font[i]*1.4+2)/2+'px';
	  //style.bottom = 0;
	  var leftM = 12;
	  for (var z = i-1; z>-1; z--)
		leftM += Math.round(font[z]*1.4);
	  style.left = leftM+'px';
      href = 'javascript:setFont(' + font[i] + ')';
	}
  }
    var ftHelp = ftWahl.appendChild(document.createElement('a'));
	  ftHelp.innerHTML = ' ? ';
	  ftHelp.href = '../start/konzept.htm#schrift';
	with (ftHelp.style) {
	  cursor = 'help';	
	  fontSize = 15+'px';	
	  right = 5+'px';		
	  //top = 6+'px';
	}
}


  
////////////////////////////////////////////////////
///          Last Update                        ////
////////////////////////////////////////////////////
  

function lastUpdate() {

  if (!document.lastModified) return;
	
  var mod = new Date(document.lastModified),
    //monat = ["Januar","Februar","M&auml;rz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],
    datum = mod.getDate()+'. '+(mod.getMonth()+1)+'. '+mod.getFullYear(),
    today = new Date(),
    daysago = Math.round( (today.getTime()- mod.getTime())/(24*60*60*1000) );
	
  var wann = (daysago == 0) ? ': heute' : 
      (daysago == 1) ? ': gestern':  
        (daysago>1 && daysago< 30) ?  ' vor ' + daysago + ' tagen' : ': ' + datum,
    update = 'Letzte &Auml;nderung' + wann;
	
    wo = getClassNames('updates', 'update', 'div') || null;
    if (wo[0]) wo[0].innerHTML = update;
}

 
function showLastModified() {
  var d = new Date();
  var a ='Letztes Update: '
  if (wo[0]) wo[0].innerHTML = (d.toLocaleDateString) ? 
    a+d.toLocaleDateString(document.lastModified) : a+document.lastModified;
  
}

window.onload = function() {writeFont(); lastUpdate();}; //
window.onresize = function() { hideDiv(); sizeX();};

