var anticheat = {

        init: function( url )
        {
                this.url = url;
                this.req = new Object();

                this.mouse_x = 0;
                this.mouse_y = 0;
                this.mouse_time = 0;
                this.time_start = this.getUTC();
                this.timeout = 5 * 100;
                this.timer = '';

                //mouse start coordinates
                $( document ).mousemove( function(e)
                {  
                        anticheat.getMouseXY( e );
                });
        },

        //---------------------------------------------------------------------------------------------------------------

        getUTC: function()
        {
                var date = new Date();
                return Date.UTC( date.getFullYear(), date.getMonth(), date.getDate() ,date.getHours() ,date.getMinutes() ,date.getSeconds() );
        },

        //---------------------------------------------------------------------------------------------------------------

        getScrollXY: function () 
        {
                var scrOfX = 0, scrOfY = 0;
                if( typeof( window.pageYOffset ) == 'number' ) 
                {
                        //Netscape compliant
                        scrOfY = window.pageYOffset;
                        scrOfX = window.pageXOffset;
                } 
                else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
                {
                        //DOM compliant
                        scrOfY = document.body.scrollTop;
                        scrOfX = document.body.scrollLeft;
                } 
                else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
                {
                        //IE6 Strict
                        scrOfY = document.documentElement.scrollTop;
                        scrOfX = document.documentElement.scrollLeft;
                }
                return { x: scrOfX, y: scrOfY };
        },

        //---------------------------------------------------------------------------------------------------------------

        getScreenSize: function() 
        {
                var de = document.documentElement;
                var width  = self.innerWidth || ( de && de.clientWidth ) || document.body.clientWidth;
                var height = self.innerHeight || ( de && de.clientHeight ) || document.body.clientHeight;
                return {width: width, height: height};
        },

        //---------------------------------------------------------------------------------------------------------------

        getWindowSize: function ()
        {
                var xScroll, yScroll;
                var windowWidth, windowHeight;

                if (window.innerHeight && window.scrollMaxY) 
                {
                        xScroll = document.body.scrollWidth;
                        yScroll = window.innerHeight + window.scrollMaxY;
                } 
                else if (document.body.scrollHeight > document.body.offsetHeight)
                {
                        xScroll = document.body.scrollWidth;
                        yScroll = document.body.scrollHeight;
                } 
                else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight)
                {
                        xScroll = document.documentElement.scrollWidth;
                        yScroll = document.documentElement.scrollHeight;
                } 
                else 
                {
                        xScroll = document.body.offsetWidth;
                        yScroll = document.body.offsetHeight;
                }

                if (self.innerHeight) 
                {
                        windowWidth = self.innerWidth;
                        windowHeight = self.innerHeight;
                }
                else if (document.documentElement && document.documentElement.clientHeight) 
                {
                        windowWidth = document.documentElement.clientWidth;
                        windowHeight = document.documentElement.clientHeight;
                } 
                else if (document.body) 
                {
                        windowWidth = document.body.clientWidth;
                        windowHeight = document.body.clientHeight;
                }

                if(yScroll < windowHeight) pageHeight = windowHeight;
                else pageHeight = yScroll;

                if(xScroll < windowWidth) pageWidth = windowWidth;
                else pageWidth = xScroll;

                return { page:   {width: pageWidth, height: pageHeight}, window: {width: windowWidth, height: windowHeight} };
        },

        //---------------------------------------------------------------------------------------------------------------

        getMouseXY: function( e )
        {
                var x = 0, y = 0;
                if (!e) e = window.event;
                if (e.pageX || e.pageY)
                {
                        x = e.pageX;
                        y = e.pageY;
                }
                else if (e.clientX || e.clientY)
                {
                        x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
                        y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
                }
                this.mouse_x = x;
                this.mouse_y = y;
                this.mouse_time = parseInt( ( this.getUTC() - this.time_start ) / 1000 );
                return {x: x, y: y, time: this.mouse_time};
        },

        //---------------------------------------------------------------------------------------------------------------

        start: function()
        {
                //start waiting
                setTimeout(function(){
                        anticheat.send( anticheat.getBrowserParam() );
                }, this.timeout);
        },

        //---------------------------------------------------------------------------------------------------------------

        getBrowserParam: function()
        {
                var data = [];
                //browser size
                sizes = this.getWindowSize();
                data[ 'WINDOW_SIZE' ] = sizes[ 'page' ][ 'width' ] + 'x' + sizes[ 'page' ][ 'height' ];
                //data[ 'WINDOW_SIZE' ] = sizes[ 'window' ][ 'width' ] + 'x' + sizes[ 'window' ][ 'height' ];

                //display size
                sizes = this.getScreenSize();
                data[ 'PAGE_SIZE' ] = sizes[ 'width' ] + 'x' + sizes[ 'height' ];

                //left top position
                position = this.getScrollXY();
                data[ 'LEFT_TOP_POSITION' ] = position[ 'x' ] + 'x' + position[ 'y' ];

                //mouse moving
                data[ 'MOUSE_POSITION' ] = this.mouse_x + 'x' + this.mouse_y;

                //mouse time
                data[ 'MOUSE_TIME' ] = this.mouse_time;
                return data;
        },

        //---------------------------------------------------------------------------------------------------------------

        send: function( data )
        {
                if( !data ) return false;
                sendRequest( this.req,
                             this.url,
                             {data: data},
                             function() {}, function( data ) {}, function( data ) {});
        }
}