/*
(c) 2006 Klaus Meusburger, http://www.gmg.biz

This script needs library mootools.

// 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.marr = new Array();
        this.mharr = new Array();
        this.scrollarr = new Array();
        this.windowHeight = 0;
        this.windowWidth = 0;
        this.minDocumentHeight = 777;
        this.offsetY = 0;
        this.calculateWindow();
        //Event.observe(window, 'resize', DivResizer.resizeAll, false);
    },

    /* add new div */
    add: function(divid, width, height, minwidth, minheight, scrollOnSmallWindows) {
        this.arr[this.arr.length] = divid;
        this.warr[this.warr.length] = width;
        this.harr[this.harr.length] = height;

        if (minwidth == null)
            minwidth = 0;

        if (minheight == null)
            minheight = 0;

        this.marr.push(minwidth);
        this.mharr.push(minheight);

        if (scrollOnSmallWindows == null)
            scrollOnSmallWindows = true;

        this.scrollarr.push(scrollOnSmallWindows);
    },

    /* remove existing div */
    remove: function(divid) {
        this.arr = this.arr.erase(divid);
    },

    /* resize all added divs */
    resizeAll: function() {

        this.calculateWindow();

        this.ybody = $(document.body).getSize().y;

        for (var i = 0; i < this.arr.length; i++) {
            this.setDimensions(this.arr[i], this.warr[i], this.harr[i], this.marr[i], this.mharr[i], this.scrollarr[i]);
        }
    },

    /* resize a specific div with special width and height */
    setDimensions: function(divid, width, height, minwidth, minheight, scrollOnSmallWindows) {

        var div = $(divid);

        if (div != null) {



            if (!scrollOnSmallWindows) {

                if (this.windowHeight <= this.minDocumentHeight) {

                    if (div.id == "mastersub")
                        div.setStyle("height", "100%");

                    //$('newsticker').setStyle("top", "30px");


                    div.style.overflow = "visible";
                    return;
                } else {
                    div.style.overflow = "auto";
                }
            }

            if (div.style.overflow == "visible") {
                return;
            }



            // height
            if (height > 0) {
                //height -= 155;
                if (this.windowHeight > 0) {
                    var newheight = this.windowHeight - height;
                    if (newheight > minheight) {
                        div.style.height = newheight + "px";
                        div.height = newheight;
                    }
                }
            }

            // width
            if (width > 0)
                if (this.windowWidth > 0) {
                var oldwidth = div.offsetWidth;
                var newwidth = this.windowWidth - width;

                if (newwidth > minwidth) {
                    div.style.width = newwidth + "px";
                    div.width = newwidth;
                }
            }
        }
    },

    /* does id already exist */
    exists: function(id) {
        for (var i = 0; i < this.arr.length; i++)
            if (this.arr[i] == id)
            return true;

        return false;
    },

    /* entfernt alle einträge aus den arrays */
    clearAll: function() {
        this.arr = new Array();
        this.harr = new Array();
        this.warr = new Array();
        this.marr = new Array();
        this.mharr = new Array();
    },

    /* 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() {
    //checkResize();
    DivResizer.resizeAll();
});
