var General = {
        config: {
                container: {
                        node: null,
                        width: 0,
                        height: 0
                },

                heading: {
                        node: null,
                        width: 0,
                        height: 0
                },

                content: {
                        node: null,
                        width: 0,
                        height: 0
                },

                footer: {
                        node: null,
                        width: 0,
                        height: 0
                }
        },

        global: {
                submenu: [],
                iframe: [],
                selectedDealer: null,
                timer: null
        },

        page: {
                getWidth: function( )
                {
                        var wWidth = General.window.getWidth( );
                        var intWidth = 0;

                        if( self.innerHeight && self.scrollMaxX )
                        {
                                intWidth = self.innerHeight + self.scrollMaxX;
                        }else if ( document.documentElement.clientWidth > document.documentElement.scrollWidth )
                        {
                                intWidth = document.documentElement.clientWidth;
                        }else
                        {
                                intWidth = document.documentElement.scrollWidth;
                        }

                        return intWidth;//Math.max( intWidth , wWidth );
                } ,

                getHeight: function( )
                {
                        var wHeight = General.window.getHeight( );
                        var intHeight = 0;

                        if( self.innerHeight && self.scrollMaxY )
                        {
                                intHeight = self.innerHeight + self.scrollMaxY;
                        }else if ( document.documentElement.offsetHeight > document.documentElement.scrollHeight )
                        {
                                intHeight = document.documentElement.offsetHeight;
                        }else
                        {
                                intHeight = document.documentElement.scrollHeight;
                        }

                        if( intHeight  <= wHeight )
                        {
                                return wHeight;
                        }

                        /* Safari 2 has a bug due to our use of a negative top margin on the container */
                        var testSafari2 = navigator.userAgent.match( " AppleWebKit/([0-9]+)" );
                        if( testSafari2 && ( testSafari2.length && testSafari2[1] != undefined ) )
                        {
                                intHeight += 12;
                        }

                        return intHeight;
                }
        },

        window: {
                getWidth: function( )
                {
                        if( self.innerWidth )
                        {
                                return self.innerWidth;
                        }else if( document.documentElement && document.documentElement.clientWidth )
                        {
                                return document.documentElement.clientWidth;
                        }else if( document.body )
                        {
                                return document.body.clientWidth;
                        }

                        return 0;
                },

                getHeight: function( )
                {
                        if( self.innerHeight )
                        {
                                return self.innerHeight;
                        }else if( document.documentElement && document.documentElement.clientHeight )
                        {
                                return document.documentElement.clientHeight;
                        }else if( document.body )
                        {
                                return document.body.clientHeight;
                        }

                        return 0;
                }
        },

        event: {
                register: function( element , type , callback , capture )
                {
                        if( !element || !type || !callback ) return false;
                        if( !capture ) var capture = false;

                        if( element.attachEvent && capture == false )
                        {
                                return element.attachEvent( 'on' + type , this.returnHandler( callback ) );
                        }else if( element.addEventListener )
                        {
                                return element.addEventListener( type , this.returnHandler( callback ) , capture );
                        }else
                        {
                                element['on'+type] = this.returnHandler( callback );
                                return false;
                        }
                },

                returnHandler: function( callback )
                {
                        return function( e )
                                {
                                        if( !e ) var e = window.event;

                                        if( !e.cancelEvent )
                                        {
                                                e.cancelEvent = function( )
                                                {
                                                        if( !this ) return false;

                                                        if( this.stopPropagation ) this.stopPropagation();
                                                        if( this.preventDefault ) this.preventDefault( );
                                                        this.cancelBubble = true;
                                                        this.returnValue = false;

                                                        return false;
                                                };
                                        }

                                        if( !e.targetNode )
                                        {
                                                e.targetNode = ( e.target && !e.srcElement ? e.target : e.srcElement );

                                                if( ( e.targetNode && e.targetNode.nodeType == 3 ) && e.targetNode.parentNode )
                                                {
                                                        e.targetNode = e.targetNode.parentNode;
                                                }
                                        }

                                        if( !e.pointerX || !e.pointerY )
                                        {
                                                e.pointerX = 0;
                                                if( e.pageX && e.pageY )
                                                {
                                                        e.pointerX = e.pageX;
                                                        e.pointerY = e.pageY;
                                                }else if( e.clientX && e.clientY )
                                                {
                                                        e.pointerX = ( e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft );
                                                        e.pointerY = ( e.clientY + document.body.scrollTop + document.documentElement.scrollTop );
                                                }
                                        }

                                        if( e.targetNode && ( !e.targetNode.posX || !e.targetNode.posY ) )
                                        {
                                                var targetNode = e.targetNode;
                                                e.targetNode.posX = 0;
                                                e.targetNode.posY = 0;

                                                if ( targetNode.offsetParent )
                                                {
                                                        while( targetNode.offsetParent && targetNode.parentNode.nodeName != "FORM" )
                                                        {
                                                                e.targetNode.posX += targetNode.offsetLeft;
                                                                e.targetNode.posY += targetNode.offsetTop;
                                                                targetNode = targetNode.offsetParent;
                                                        }
                                                }else if( targetNode.x && targetNode.y )
                                                {
                                                        e.targetNode.posX = targetNode.x;
                                                        e.targetNode.posY = targetNode.y;
                                                }
                                        }

                                        callback( e );
                                };
                },

                cancelEvent: function( e )
                {
                        if( !e ) var e = window.event;
                        if( !e ) return false;

                        if( e.stopPropagation ) e.stopPropagation();
                        if( e.preventDefault ) e.preventDefault( );
                        e.cancelBubble = true;
                        e.returnValue = false;

                        return false;
                },

                ready: function( callback )
                {
                        /*@cc_on @*/
                                /*@if (@_win32)
                                document.write("<s" + "cript id=__ie_onready defer src=javascript:void(0)><\/script>");
                                var script = document.getElementById( "__ie_onready" );
                                script.onreadystatechange = function() {
                                        if (this.readyState == "complete") {
                                                callback(); // call the onload handler
                                        }
                                };
                                return;
                        /*@end @*/

                        if( document.addEventListener && !document.readyState )
                        {
                                return document.addEventListener( "DOMContentLoaded" , callback , false );
                        }else if( document.readyState )
                        {
                                General.global.timer = setInterval( function( )
                                {
                                        if( /loaded|complete/i.test( document.readyState ) )
                                        {
                                                callback( );
                                                clearInterval( General.global.timer );
                                        }

                                } , 1 );
                                return;
                        }

                        General.event.register( window , 'load' , callback );
                }
        },

        getCoordinates: function( element )
        {
                var posX = 0;
                var posY = 0;

                if( element.x && element.y )
                {
                        posX = element.x;
                        posY = element.y;
                }

                if( element.offsetParent )
                {
                        while( element.offsetParent && element.parentNode.nodeName != "FORM" )
                        {
                                posX += element.offsetLeft;
                                posY += element.offsetTop;
                                element = element.offsetParent;
                        }
                }

                return {
                        x: posX,
                        y: posY
                };
        },

        getElementByClassName: function( parentNode , nodeName , className )
        {
                if( !parentNode.getElementsByTagName ) return false;
                var childNodes = parentNode.getElementsByTagName( nodeName );
                if( !childNodes || childNodes.length <= 0 ) return false;

                for( var i = 0; i < childNodes.length; i++ )
                {
                        if( childNodes[i].className.indexOf( className ) != -1 )
                        {
                                return childNodes[i];
                        }
                }

                return false;
        }
};

General.event.register( window , 'load' , function( e ){
        General.config.container.node = document.getElementById( "body-container" );
                if( General.config.container.node )
                {
                        General.config.container.width = General.config.container.node.offsetWidth;
                        General.config.container.height = General.config.container.node.offsetHeight;
                }

        General.config.heading.node = document.getElementById( "body-heading" );
                if( General.config.heading.node )
                {
                        General.config.heading.width = General.config.heading.node.offsetWidth;
                        General.config.heading.height = General.config.heading.node.offsetHeight;
                }

        General.config.footer.node = document.getElementById( "footer" );
                if( General.config.footer.node )
                {
                        General.config.footer.width = General.config.footer.node.offsetWidth;
                        General.config.footer.height = General.config.footer.node.offsetHeight;
                }
} );





/* DEBUG SCRIPT REMOVE FROM FINAL! */
if( window.location.search.indexOf( 'debug' ) != -1 )
{
        General.event.register( window , 'load' , function( e )
        {
                        General.event.register( document , 'mousedown' , function( e )
                        {
                                alert( "Mouse position:\nx: " + e.pointerX + ", y: " + e.pointerY + "\n\n" +
                                        "Object relative position:\nx: " + e.targetNode.posX + ", y: " + e.targetNode.posY + "\n\n" +
                                        "Object dimensions:\nw: " + e.targetNode.offsetWidth + ", h: " + e.targetNode.offsetHeight + "\n\n" +
                                        "Target nodeName: " + e.targetNode.nodeName + "\n" +
                                        "Target className: " + e.targetNode.className + "\n" +
                                        "Target ID: " + ( e.targetNode.getAttribute( "id" ) == null ? " - geen - " : e.targetNode.getAttribute( "id" ) )
                                          );
                                e.cancelEvent( );
                        } );

                } );
}

/* @eof */