﻿function randcolor() {
    var num = 8;
    var time = new Date();
    var color = new Array(num);
    color[0] = "#09c";
    color[1] = "#0c9";
    color[2] = "#90c";
    color[3] = "#9f3";
    color[4] = "#c09";
    color[5] = "#fc0";
    color[6] = "#c03"
    color[7] = "white"
    document.getElementById('wrap').style.backgroundColor = color[(time.getHours() % num)];
}

Array.prototype.shuffle = function() {
    var i, j, tmp;
    for (i = this.length - 1; i >= 0; i--) {
        j = Math.floor(Math.random() * (i + 1))
        tmp = this[i];
        this[i] = this[j];
        this[j] = tmp;
    }
}

function shuffle(id, size, line) {
    var obj = document.getElementById(id); //idで指定した要素を取得
    var member = obj.getElementsByTagName("a"); //idで指定した要素の中の<a>タグ要素を取得
    var n = member.length; //取得した<a>タグ要素の数を取得
    var arr = new Array(n);
    for (i = 0; i < n; i++) arr[i] = i + 1;
    arr.shuffle();
    arr.shuffle();
    for (i = 0; i < n; i++) {
        if ((x = arr[i] % line - 1) == -1) x = 4;
        y = Math.ceil(arr[i] / line) - 1;
        member[i].style.display = "block";
        member[i].style.top = (y * size).toString() + "px";
        member[i].style.left = (x * size).toString() + "px";
    }
    obj.style.height = (size * (Math.ceil(n / line))).toString() + "px"; //親ノードのheightを調整
}

window.onload = function() {
    shuffle("thumbnails", 170, 5);
    randcolor();
}
