//Class app
var app_ww, app_wh, fenster, breite, quotient, // Window width/height...fenster width/height
    app_agent = navigator.userAgent.toLowerCase(), // Browser type
    app_version = parseInt(navigator.appVersion),
    app_is_ie = app_agent.indexOf('msie') >= 0 && app_agent.indexOf('opera') < 0,
    app_is_opera = app_agent.indexOf('opera') >= 0,
    app_is_safari = app_agent.indexOf('safari') >= 0,
    image_area, image_div, image_span, side_td; // Containers
var oc = -15;
	
function app_init() {
  image_area = document.getElementById('container');
  image_div = document.getElementById('image');
  image_span = document.getElementById('image_span');
  side_td = document.getElementById('icon-nav');
   
  if (window.attachEvent) window.attachEvent('onresize', app_onresize);
  else if (window.addEventListener) window.addEventListener('resize', app_onresize, false);
  
  app_getwinsize();
  adjust();
  image_fit();
  //fadeIn();
 setTimeout('load_next()',500);
}

function app_onresize() {
  app_getwinsize();
  adjust();
  image_fit();
}

function app_getwinsize() {
  if (typeof(window.innerWidth) == 'number') {
    app_ww = window.innerWidth; app_wh = window.innerHeight;
  } else if (document.documentElement.clientHeight) {
    app_ww = document.documentElement.clientWidth; app_wh = document.documentElement.clientHeight;
  } else {
    app_ww = document.body.clientWidth; app_wh = document.body.clientHeight;
  }
}

function adjust() {
	if (home) {
	fenster = app_wh-70;
	} else {
	fenster = app_wh-106;
	}
	quotient = data_ih/data_iw;
	if (quotient < 1) {
		breite = min((app_ww - 200), data_iw);
	} else{
	breite = Math.round(min(1000, data_ih)/quotient);
	}
	var s = Math.round((fenster-(quotient*breite))/2);
	 if (s < 32) s=32;
	document.getElementById('container').style.height = fenster + 'px';
	document.getElementById('image').style.paddingTop = s + 'px';
	document.getElementById('icon-nav').style.paddingTop = max(Math.round(((app_wh-170)/2)-130),0) + 'px';
}

function image_fit() {
	var  w = breite, h = Math.round(quotient*w),
	ah = fenster-64, aw = Math.round(ah/quotient), a=0;
	if (ah == 0) {ah = fenster; aw= Math.round((w/h)*fenster);}
	if (w > aw || h > ah) {
	w = aw; h = ah;
  }
     if(!app_is_ie){
    document.slide.width = w;
    document.slide.height = h;}
	if (app_is_ie){image_span.innerHTML = '<a href="' + next_url + '"><img name="slide" src="picture/bilder/' + data_name
      + '" ' + 'width="' + w + '" height="' + h + '"' + ' border="0" alt=""/></a>';}
}
function fadeIn() {
        //document.getElementById('slide').style.filter='Alpha(opacity='+5*oc+')'
		//document.getElementById('slide').style.opacity = oc/20;
		document.getElementById('slide').style.marginTop = (oc*20) + 'px';
        if(oc!=0) setTimeout('oc++;fadeIn()',1);
} 
function load_next() {
        var bild = new Image();
		bild.src = next_name;
} 
 function max(a,b) { return (a>b)?a:b; }
function min(a,b) { return (a<b)?a:b; }