
function checkHeight(){
  obj = document.getElementById('wrapper');
  var fh = Fensterhoehe();
  var fw = Fensterweite();
  if (fh > 0 && fh < obj.offsetHeight){
    obj.style.marginTop = '0px';
    obj.style.top = '0px';
  }
  else{
    obj.style.marginTop = '';
    obj.style.top = '';
  }
  if (fw > 0 && fw < obj.offsetWidth){
    obj.style.marginLeft = '0px';
    obj.style.left = '0px';
  }
  else{
    obj.style.marginLeft = '';
    obj.style.left = '';
  }
}

function Fensterweite () {
  if (window.innerWidth) {
    return window.innerWidth;
  } else if (document.body && document.body.offsetWidth) {
    return document.body.offsetWidth;
  } else {
    return 0;
  }
}

function Fensterhoehe () {
  if (window.innerHeight) {
    return window.innerHeight;
  } else if (document.body && document.body.offsetHeight) {
    return document.body.offsetHeight;
  } else {
    return 0;
  }
}

$(document).ready(function(){
  $("#content").jScrollPane();
  window.onresize = checkHeight;
  checkHeight();
  $('.fancybox').fancybox({
    'titlePosition' : 'over',
    'transitionIn' : 'elastic'
  });
  $('.fancyframe').fancybox({
    type: 'iframe',
    titleShow: false,
    transitionIn: 'fade',
    autoDimensions: false,
    width: 900,
    height: 600
  });
});

function loadContent(page){
  $.ajax({
    url: '?page='+page,
    dataType: 'html',
    success: function(html){
      var pagetitle = html.substr(html.indexOf('<div id="pagetitle">'));
      pagetitle = pagetitle.substr(pagetitle.indexOf('>')+1);
      pagetitle = pagetitle.substr(0, pagetitle.indexOf('</div>'));
      $('#pagetitle').animate({opacity:"0"}, 500, function(){
        $('#pagetitle')[0].innerHTML = pagetitle;
      });
      $('#pagetitle').animate({opacity:"1"}, 500);
      var pagecontent = html.substr(html.indexOf('<!-- BEGIN content -->'));
      pagecontent = pagecontent.substr(0, pagecontent.indexOf('<!-- END content -->') + 20);
      $('#contentbox').animate({opacity:"0"}, 500, function(){
        $('#contentbox')[0].innerHTML = pagecontent;
        $("#content").jScrollPane();
      });
      $('#contentbox').animate({opacity:"1"}, 500, function(){
        $('.fancybox').fancybox({
          'titlePosition' : 'over',
          'transitionIn' : 'elastic'
        });
        $('.fancyframe').fancybox({
          type: 'iframe',
          titleShow: false,
          transitionIn: 'fade',
          autoDimensions: false,
          width: 900,
          height: 600
        });
      });
      pageTracker._trackPageview("?page="+page);
    },
    error: function(){alert("Fehler beim Laden!")}
  });
  return false;
}
