/*
(c) 2006 Klaus Meusburger, http://www.gmg.biz

This script needs library prototype.js.

// To resize three divs on your site, when window will be resized make this
DivResizer.add("IDofDiv1",200,100); // id,width,height
DivResizer.add("IDofDiv2",0,120);
DivResizer.add("IDofDiv3",10,0);

// To resize your div on pageload, call following method once at end of document.
DivResizer.ResizeAll();

*/


// you can use this variables on your site for browser specific calculations
var ie = true;
var ie6 = false;
var moz = false;
var op = false;

if(navigator.userAgent.indexOf("MSIE 6.0") >= 0){
	ie = true;
	ie6 = true;
	moz = false;
	op = false;
}
else if(navigator.userAgent.indexOf("Firefox") >= 0){
	ie = false;
	moz = true;
}
else if(navigator.userAgent.indexOf("Opera") >= 0)
{
    ie = false;
    moz = false;
	op = true;
}

var DivResizer = {

    /* constructor */
    initialize: function() {
        this.arr = new Array();
        this.harr = new Array();
        this.warr = new Array();
        this.minwarr = new Array();
        this.minharr = new Array();
        this.scrollarr = new Array();
        this.windowHeight = 0;
        this.windowWidth = 0;
        this.calculateWindow();
        //Event.observe(window, 'resize', DivResizer.resizeAll, false);
    },

    /* add new div */
    add: function(divid, width, height, minw, minh, scrollOnSmallWindows) {

        if (scrollOnSmallWindows == null)
            scrollOnSmallWindows = true;

        this.arr[this.arr.length] = divid;
        this.warr[this.warr.length] = width;
        this.harr[this.harr.length] = height;
        this.scrollarr.push(scrollOnSmallWindows);

        if (minw == null)
            minw = 0;

        if (minh == null)
            minh = 0;

        this.minwarr.push(minw);
        this.minharr.push(minh);
    },

    /* remove existing div */
    remove: function(divid) {
        this.arr = this.arr.without(divid);
    },

    /* resize all added divs */
    resizeAll: function() {

        this.calculateWindow();

        for (var i = 0; i < this.arr.length; i++) {
            this.setDimensions(this.arr[i], this.warr[i], this.harr[i], this.minwarr[i], this.minharr[i], this.scrollarr[i]);
        }

        try { onResizeFinished(); } catch (ex) { }
    },

    /* resize a specific div with special width and height */
    setDimensions: function(divid, width, height, minw, minh, scrollOnSmallWindows) {

        var div = $(divid);

        if (div != null) {

            // div.style.overflow = "auto";

            /*
            $('debug').innerHTML = this.windowHeight;
            $('debug').style.display = 'block';
            $('debug').style.visibility = 'visible';
            */

            var noscrollheight = 777;

            // spezial 1
            // wenn nicht auf startseite, dann ist der header weniger hoch. Wir haben also mehr platz. 
            if ($('masterheadersmall') != null) {
                if (!scrollOnSmallWindows) {
                    height -= 59;
                    noscrollheight -= 59;
                }
            }

            // spezial 2
            // wenn jemand einen kleinen bildschirm hat wird ganz aussen gescrollt
            if (!scrollOnSmallWindows) {

                if (this.windowHeight <= noscrollheight) {
                    div.style.overflow = "visible";
                    return;
                }
            }
           

            // height	
            if (height > 0)
                if (this.windowHeight > 0 && this.windowHeight - height > minh) {
                div.style.height = (this.windowHeight - height) + "px";
                div.height = (this.windowHeight - height);
            }

            // width
            if (width > 0)
                if (this.windowWidth > 0 && this.windowWidth - width > minw) {
                div.style.width = (this.windowWidth - width) + "px";
                div.width = (this.windowWidth - width);
            }
        }
    },

    /* get dimensions of window */
    calculateWindow: function() {
        this.windowHeight = this.getWindowHeight();
        this.windowWidth = this.getWindowWidth();
    },

    /* get height of window */
    getWindowHeight: function() {
        var myWidth = 0, myHeight = 0;
        if (typeof (window.innerWidth) == 'number') {
            //Non-IE
            myHeight = window.innerHeight;
            ie = false;
        } else if (document.documentElement &&
			(document.documentElement.clientHeight)) {
            //IE 6+ in 'standards compliant mode'
            myHeight = document.documentElement.clientHeight;

        } else if (document.body && document.body.clientHeight) {
            //IE 4 compatible
            myHeight = document.body.clientHeight;
        }

        return myHeight;
    },

    /* get width of window */
    getWindowWidth: function() {
        var myWidth = 0, myHeight = 0;
        if (typeof (window.innerWidth) == 'number') {
            //Non-IE
            myWidth = window.innerWidth;
        } else if (document.documentElement &&
			(document.documentElement.clientWidth)) {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
        } else if (document.body && document.body.clientWidth) {
            //IE 4 compatible
            myWidth = document.body.clientWidth;
        }

        return myWidth;
    }

}


/* init */
DivResizer.initialize();

/* helper method */
function resize2()
{
	DivResizer.resizeAll();	  
}

/* register on windowresize */
if(Event)
    if(Event.observe)
        Event.observe(window, 'resize', resize2, false);
        
  
    
//window.addEvent('resize', function() {
//	DivResizer.resizeAll();
//});

