/*
(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;
}
else if(navigator.userAgent.indexOf("Firefox") >= 0){
	ie = false;
	moz = true;
}
else if(navigator.userAgent.indexOf("Opera") >= 0)
{
	ie = false;
	op = true;
}

var DivResizer = {

    /* constructor */
    initialize: function() {
        this.arr = new Array();
        this.harr = new Array();
        this.warr = 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) {
        this.arr[this.arr.length] = divid;
        this.warr[this.harr.length] = width;
        this.harr[this.harr.length] = height;

    },

    /* remove existing div */
    remove: function(divid) {
        this.arr = this.arr.without(divid);
    },

    /* exists a div in the array */
    exists: function(divid) {

        for (var i = 0; i < this.arr.length; i++) {
            if (this.arr[i] == divid)
                return true;
        }

        return false;
    },

    /* 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]);
        }
    },

    /* resize a specific div with special width and height */
    setDimensions: function(divid, width, height) {

        var div = $(divid);

        if (div != null) {

            //div.style.overflow = "auto";

            // height	
            if (height > 0)
                if (this.windowHeight > 0) {
                div.style.height = (this.windowHeight - height) + "px";
                div.height = (this.windowHeight - height);

                if (this.windowHeight < 600) {
                    div.style.height = "600px";
                    div.height = 600;
                }
            }

            // width
            if (width > 0) {
                if (this.windowWidth > 1000) {
                    div.style.width = (this.windowWidth - width) + "px";
                    div.width = (this.windowWidth - width);
                    div.style.overflow = "auto";
                }
            }
        }
    },

    /* 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();
	
    //	var div = $('contentdiv');
    //	div.getFirst().style.height = div.getSize().y + "px";
    //	scrollBox1.mooScrollAreas[0].refresh();
	//window.location.reload();
}

/* register on windowresize */
//Event.observe(window, 'resize', resize2, false);

window.addEvent("resize", function(){
    resize2();
});


