﻿var dk;
if (!dk) dk = {};
if (!dk.qbrix) dk.qbrix = {};

dk.qbrix.web =
{
    Initialize: function()
    {
        this.Tabs.Initialize();
        this.Letters.Initialize();

        this.Header.Maze.Initialize();


        //this.Clock.Initialize();
        //this.Daniel();
    },

    Daniel: function()
    {
        Number.prototype.rnd = function() { return Math.floor(Math.random() * this); };
        String.prototype.letter = function(vowel) { var a = (vowel ? 'aeiouy' : 'bcdfghjklmnpqrstvwxz'); return a[a.length.rnd()]; };
        (function()
        {
            var s, n;
            do
            {
                for (s = '', n = 0; n < 7; n++)
                    s += s.letter(n % 2);
            } while (!confirm('Suggestion: ' + s + '\n' + 'Decline for new suggestion'));
        })();

        /*
        javascript:Number.prototype.r=function(){return Math.floor(Math.random()*this);};String.prototype.l=function(v){var a=(v?'aeiouy':'bcdfghjklmnpqrstvwxz');return a[a.length.r()];};(function(){var s,n;do{for(s='',n=0;n<7;n++)s+=s.l(n%2);}while(!confirm('Suggestion: '+s+'\n' + 'Decline for new suggestion'));})();
        javascript:rc=function(c){return Math.floor(Math.random()*c)};do{for(s='',i=0;i<7;i++){s+='aeioubcdfghjklmnpqrstvwxyz'.split('')[i%2?5+rc(19):rc(5)]};} while(!confirm('Suggestion: '+s+'\n'+'Decline for new suggestion'))
        */
    },
    Daniels: function()
    {
        rc = function(c) { return Math.floor(Math.random() * c) };
        do
        {
            for (s = '', i = 0; i < 7; i++)
            {
                s += 'aeioubcdfghjklmnpqrstvwxyz'.split('')[i % 2 ? 5 + rc(19) : rc(5)]
            };
        } while (!confirm('Suggestion: ' + s + '\n' + 'Decline for new suggestion'))
    },

    Events:
    {
        dummy: function(evnt)
        {
        }
    },

    WriteEmail: function()
    {
        var a = '=tqbo?kpshfo=0tqbo?A=tqbo?rcsjy=0tqbo?/=tqbo?el=0tqbo?';
        for (var n = 0; n < a.length; n++)
            document.write(String.fromCharCode(a.charCodeAt(n) - 1));
    },

    Tabs:
    {
        Initialize: function()
        {
        },

        Events:
        {
            onclick: function(evnt)
            {
            }
        }
    },

    Header:
    {
        Maze:
        {
            Maze: null,

            Initialize: function()
            {
                this.Create();

                QB.Object.AttachEvent(window, 'resize', this.Events.onResize);
            },

            Create: function()
            {
                var fb = document.getElementById('divFacebook');
                if (fb == null) return;

                var pos = QB.Object.GetPosition(fb);
                dk.qbrix.web.Header.Maze.Maze = new dk.qbrix.Maze.Create(Math.floor((pos[0] - 210) / 12),/*width*/
                                                                         7, /*height*/
                                                                         12, /*cellSize*/
                                                                         196, /*left*/ 
                                                                         20); /*top*/
            },

            Events:
            {
                onResize: function()
                {
                    if (dk.qbrix.web.Header.Maze.Maze == null) return;
                    dk.qbrix.web.Header.Maze.Maze.Destroy();
                    dk.qbrix.web.Header.Maze.Maze = null;
                    dk.qbrix.web.Header.Maze.Create();
                }
            }
        },

        Checker:
        {
            Initialize: function()
            {
            },
            Regenerate: function()
            {
            }
        }
    },

    Letters:
    {
        Initialize: function()
        {
            var div = document.getElementById('divTopAlfabet');
            if (div == null) return;
            var n, m, found;

            var content = document.getElementById('divContent').getElementsByTagName('div')[0];
            var contentLetters = [];
            if (content != null)
            {
                var arr = content.getElementsByTagName('a');
                if (arr != null)
                {
                    for (n = 0; n < arr.length; n++)
                    {
                        if (arr[n].className.indexOf('qb-content-letter') >= 0)
                        {
                            contentLetters.push(arr[n]);
                        }
                    }
                }
            }

            var letters = div.getElementsByTagName('a');

            for (n = 0; n < letters.length; n++)
            {
                found = false;
                for (m = 0; m < contentLetters.length; m++)
                {
                    if (letters[n].innerText.toLowerCase() == contentLetters[m].innerText.toLowerCase())
                    {
                        found = true;
                        break;
                    }
                }
                QB.Object.AttachEvent(letters[n], 'click', this.Events.onClick);
                if (!found)
                {
                    letters[n].className += ' qb-letter-disabled';
                    letters[n].disabled = true;
                }
            }
        },

        Events:
        {
            onClick: function(evnt)
            {
                var elm = (evnt.target ? evnt.target : evnt.srcElement);
                if (elm != null)
                    elm.blur();
            },
            onMouseOver: function(evnt)
            {
            },
            onMouseOut: function(evnt)
            {
            }
        }
    },

    Clock:
    {
        Timer: null,
        Initialize: function()
        {
            this.Timer = setInterval(this.Events.onTimer, 500);
        },

        Events:
        {
            onTimer: function(evnt)
            {
                var div = document.getElementById('divClock');
                if (div == null) return;

                var d = new Date();
                var seperator = '<span style="visibility:';
                if (d.getMilliseconds() > 500)
                    seperator += 'hidden';
                else
                    seperator += 'visible';
                seperator += ';">:</span>';

                var hours = d.getHours().toString();
                while (hours.length < 2)
                    hours = '0' + hours;
                var minutes = d.getMinutes().toString();
                while (minutes.length < 2)
                    minutes = '0' + minutes;
                div.innerHTML = hours + seperator + minutes;
            }
        }
    }
};
