/*
This file is part of the business logic for

  Boeckerstiftung Witten 2009

Copyright 2009 by Diedrich Vorberg <diedrich@tux4web.de>
Copyright 2009 by JungePartner, Witten <info@jungepartner.de>

All Rights Reserved

The customer, JungePartner, Witten, is granted the right to use this
and all related sourcecode in running and maintaining above website
now and in the future. For this purpose it may be modified at
will. However, publication and commercial distribution is restricted
as for any other peace of proprietary software.


Changelog
---------
$Log: layout.js,v $
Revision 1.7  2011-08-29 11:11:44  cvs
*** empty log message ***

Revision 1.6  2010-09-06 08:47:08  t4w00-diedrich
Aenderungen auf dem Server

Revision 1.5  2010-01-14 20:58:14  t4w00-diedrich
Bugfix (2)

Revision 1.4  2010-01-14 20:49:21  t4w00-diedrich
Bugfix.

Revision 1.3  2009-10-08 16:14:24  t4w00-diedrich
Use prototype instead of t4lib

Revision 1.2  2009-10-04 21:57:47  t4w00-diedrich
Some layout improvement.

Revision 1.1.1.1  2009-09-11 21:22:18  t4w00-diedrich
Initial import

*/

/* Reload all images with the src= set to a value that contains the current
 * physical extends in pixels. If it's an RImage the server will provide a
 * nicely scaled version of the image. */

function windows_image_improver()
{
    // Get all the images
    var images = document.getElementsByTagName("img");

    // Traverse the images and find those with class= need-improvement
    for(var a = 0; a < images.length; a++)
    {
        var img = images[a];
        var cls = img.className;

        if ( cls.indexOf("no-improvement") == -1 ) {
			var scaleto = img.width + "x" + img.height;
			
			var url = img.src;
			var parts = url.split("?");
			var base = parts[0];
            var params = $H(url.toQueryParams());

            params.unset("size");
            params.unset("preview");
            params.unset("scaleto");
            
            if ( img.width > 0 && img.height > 0)
            {
                params.set("scaleto", scaleto);
            }
     
            // Images that are .png files or smaller than 200x200 pixels
            // in terms of area, are requested in .png format.
			if ( img.src.indexOf(".png") != -1 ||
                        img.width * img.height <= 200*200 ) {
				params.set("png", "1");
			}
			
			url = base + "?" + params.toQueryString();
		
			img.src = url;
		}
    }
}

document.observe('dom:loaded', windows_image_improver);


function max(a, b) {
    if (a > b) {
		return a;
    }
    else {
		return b;
    }
}

function recalc_sizes() {
    var menu = $("menu");
    var margin = $("margin");
    var content = $("content");
    
    var h = max(menu.offsetHeight, content.offsetHeight);

    if (margin != null)
    {
        h = max(h, margin.offsetHeight);
        margin.style.height = h + "px";
    }
    
    menu.style.height = h + "px";
    content.style.minHeight = h + "px";
}

document.observe('dom:loaded', recalc_sizes);

function fix_position(event)
{
    var zenith = document.getElementById("zenith");
    var ship = document.getElementById("ship");

    /* if (typeof console != "undefined") {
        console.log("ship.offsetWidth " + ship.offsetWidth);
        console.log("document.body.offsetWidth " + document.body.offsetWidth);
    } */
    
    if (ship.offsetWidth > document.body.offsetWidth) {
        var left = (ship.offsetWidth/2) + "px";
        zenith.style.left = left;
    } else {
        zenith.style.left = "50%";
    }            
}

document.observe("dom:loaded", fix_position);
window.onresize = fix_position;

