// globale varabler, som jeg gerne vil have bliver husket
var the_div;
var div_width;
var div_height;
var zoom_step_w; // zoom hastigheden udregnet 
var zoom_step_h;

var zoom_hastighed = 5 ; // i millisekunder, højere = langsommere
var zoom_trin = 7; // antal trin vi rykker zoomen i

function show_zoom_div (elem) {
 
	lav_baggrundslayer();
		
	// find størrelser på det div der skal vises
    the_div = document.getElementById(elem) ;
	 //   the_div.style.visibility = 'visible';
    div_width = parseInt(the_div.style.width) ;
    div_height = parseInt(the_div.style.height) ;

    // lav den halv størrelse:
    //the_div.style.width = (div_width / 2) + 'px' ;
    //the_div.style.height = (div_height / 2) + 'px';

    // centrer det og lav det fuldstændig gennemsigtigt, og bagefter synligt
    ;
	the_div.style.visibility = 'visible';
    setOpacity(the_div, 0) ;
    centrer_div() 
	
    // start loopet i et timeout
    zoom_step_w = div_width / (2 * zoom_trin);
    zoom_step_h = div_height / (2 * zoom_trin);
    setTimeout("inc_div(0)",zoom_hastighed );
}
function inc_div (nr) {
	//the_div.style.width = parseInt(the_div.style.width) + zoom_step_w + 'px' ;
	//the_div.style.left = parseInt(the_div.style.left) - zoom_step_w / 2 + "px" ;
	//the_div.style.height = parseInt(the_div.style.height) + zoom_step_h + 'px' ;
	//the_div.style.top = parseInt(the_div.style.top) - zoom_step_h / 2 + "px" ;
    nr += 1;
	setOpacity(the_div, nr * 100/zoom_trin)
	setOpacity(document.getElementById('bagrunds_div'), nr * 50/zoom_trin)
	if(nr == zoom_trin) {
		//the_div.style.width = div_width + 'px';
		//the_div.style.height = div_height + 'px';
		document.getElementById('bagrunds_div').style.top = "0px";
		document.getElementById('bagrunds_div').style.height = document.documentElement.scrollHeight + "px";
		return;
	}
	setTimeout("inc_div(" + nr + ")",zoom_hastighed );
}

function hide_zoom_div (elem) {
	the_div = document.getElementById(elem);
	decrease_div(zoom_trin)
}
function decrease_div (nr) {
	//the_div.style.width = parseInt(the_div.style.width) - zoom_step_w + 'px' ;
	//the_div.style.left = parseInt(the_div.style.left) + zoom_step_w / 2 + "px" ;
	//the_div.style.height = parseInt(the_div.style.height) - zoom_step_h + 'px' ;
	//the_div.style.top = parseInt(the_div.style.top) + zoom_step_h / 2 + "px" ;
    nr -= 1;
	setOpacity(the_div, nr * 100/zoom_trin)
	setOpacity(document.getElementById('bagrunds_div'), nr * 50/zoom_trin)
	if(nr == 0) {
		document.getElementById('bagrunds_div').style.visibility = 'hidden';
		the_div.style.visibility = 'hidden';
		//the_div.style.width = div_width + 'px' ;
        //the_div.style.height = div_height + 'px';
		return;
	}
	setTimeout("decrease_div(" + nr + ")",zoom_hastighed );
}
function centrer_div(){
    var wid = parseInt(the_div.style.width);
    var hei = parseInt(the_div.offsetHeight);
    var stor = vindue_storXY();
    var scro = vindue_scrollXY();
    the_div.style.left = stor[0] / 2 + scro[0] - wid / 2 + "px";
    the_div.style.top = stor[1] / 2 + scro[1] - hei / 2 + "px";
}

function lav_baggrundslayer () {
	if(!document.getElementById('bagrunds_div')) {
		var bagrunds_div = document.createElement('div');
	    bagrunds_div.id = "bagrunds_div";
	    bagrunds_div.style.width= '100%' ;
	    //bagrunds_div.style.top = "0px";
        bagrunds_div.style.left = "0px";
	    bagrunds_div.zIndex = 100;
	    //bagrunds_div.style.height = '99%';
	    bagrunds_div.style.backgroundColor = "#000000";
	    bagrunds_div.style.position = 'absolute';
	    bagrunds_div.style.visibility = 'hidden';
	    document.body.appendChild(bagrunds_div);
	    bagrunds_div.style.visibility = 'visible';	
	    setOpacity(bagrunds_div, 0)
    } else {
	    document.getElementById('bagrunds_div').style.visibility = 'visible';	
    }
	// sæt størrelse til vindue størrelse
	var stor = vindue_storXY();
	var scrol = vindue_scrollXY();
	document.getElementById('bagrunds_div').style.height = vindue_storXY()[1] + 'px';
	document.getElementById('bagrunds_div').style.top = vindue_scrollXY()[1] + 'px';
}

function setOpacity( elem, level ) {
    // If filters exist, then this is IE, so set the Alpha filter "alpha(opacity='0')";
    if ( elem.filters ) elem.style.filter = "alpha(opacity=" + level + ")"
    // Otherwise use the W3C opacity property
    else elem.style.opacity = level / 100;
}

function vindue_storXY() {
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [myWidth, myHeight];
};
function vindue_scrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
      //Netscape compliant
      scrOfY = window.pageYOffset;
      scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
      //DOM compliant
      scrOfY = document.body.scrollTop;
      scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
      //IE6 standards compliant mode
      scrOfY = document.documentElement.scrollTop;
      scrOfX = document.documentElement.scrollLeft;
    }
    return [scrOfX, scrOfY];
}
