        var width=4;
        var height=3;
        var map;
        var spaceX;
        var spaceY;
        var vertical;
        var start;
        var end;
        var distance=0;
        var direction;
        var step=6;
        var interval=40;
        var wait=500;
        var tileSize=102;
        
        function initialise()
        {
            //size screen
            document.getElementById("leftStripe").style.height=(screen.height*0.75)+"px";

            //set up variables
            map=new Array(width);
            var leftX=screen.width/2-2*tileSize+95;
            var bottomY=screen.height/2-1.5*tileSize+34;
            var randomXOffset=Math.floor(Math.random()*width);
            for(i=0;i<width;i++)
            {
                var x=(i+randomXOffset)%width;
                map[x]=new Array(height);
                var randomYOffset=Math.floor(Math.random()*height);
                for (j=0;j<height;j++)
                {
                    var y=(j+randomYOffset)%height;
                    if (i+j<5)
                    {
                        //add tile to map
                        map[x][y]="tile"+(i*height+j);
                        //position tile
                        document.getElementById(map[x][y]).style.left=(leftX+x*tileSize)+"px";
                        document.getElementById(map[x][y]).style.top=(bottomY+(y-1)*tileSize)+"px";
                        document.getElementById(map[x][y]).style.width=tileSize+"px";
                        document.getElementById(map[x][y]).style.height=tileSize+"px";
                        document.getElementById(map[x][y]).style.display="block";
                    }
                }
            }
            
            vertical=(Math.random()<0.5);
            for(i=0;i<width;i++)
            {
                for (j=0;j<height;j++)
                {
                    if(map[i][j]==null)
                    {
                        spaceX=i;
                        spaceY=j;
                    }
                }
            }
            
            startMotion();
        }
        function startMotion()
        {
            
            vertical=(vertical==false);
            var length=(vertical==true) ? height : width;
            var position=(vertical==true) ? spaceY : spaceX;
            if(position==0)
            {
                start=1;
                end=Math.floor(Math.random()*(length-1))+1;
                direction=-1;
            }
            else if (position==length-1)
            {
                start=Math.floor(Math.random()*(length-1));
                end=length-2;
                direction=1;
            }
            
            else
            {
                direction=(Math.random()<0.5) ? -1 : 1;
                if(direction>0)
                {
                    start=Math.floor(Math.random()*position);
                    end=position-1;
                }
                else
                {
                    start=position+1;
                    end=Math.floor(Math.random()*(length-position-1))+position+1;
                }
            }
            distance=0;
            
            moveTiles();
        }
        function moveTiles()
        {
            distance+=step;
            for(i=start; i<=end; i++)
            {
                var position;
                if(vertical==true)
                {
                    position=(parseInt(document.getElementById(map[spaceX][i]).style.top,10));
                }
                else
                {
                    position=(parseInt(document.getElementById(map[i][spaceY]).style.left,10));
                }
                //prevent overshoot
                if(distance>tileSize)
                {
                    position-=direction*(distance-tileSize);
                }
                //move tile
                if(vertical==true)
                {
                    document.getElementById(map[spaceX][i]).style.top=(position+direction*step)+"px";
                }
                else
                {
                    document.getElementById(map[i][spaceY]).style.left=(position+direction*step)+"px";
                }
            }
            
            if(distance>tileSize)
            {
                endMotion();
            }
            else
            {
                setTimeout("moveTiles()",interval);
            }
        }
        function endMotion()
        {
            if(direction>0)
            {
                //swap start and end
                var temp=start;
                start=end;
                end=temp;
            }
            //start is now next to space; update space coordinates
            if(vertical==true)
                spaceY=end;
            else
                spaceX=end;
            //update map
            for(i=start;i!=end-direction;i-=direction)
            {
                if(vertical==true)
                    map[spaceX][i+direction]=map[spaceX][i];
                else
                    map[i+direction][spaceY]=map[i][spaceY];
            }
            map[spaceX][spaceY]="";

            //restart
            setTimeout("startMotion()",wait);
        }