/*
 *  Inu Tokei JavaScript, version 1.0.0
 *
 *  (c)2010 ENTER the DEE
 *--------------------------------------*/

var _hh = '';
var _mm = '';
var _ss = '';
var _id = '';

function alertInuTokei()
{
    var _now = new Date();
    var _now_hh = _now.getHours();
    var _now_mm = _now.getMinutes();
    if (_now_hh < 10) {_now_hh = "0" + _now_hh; }
    if (_now_mm < 10) {_now_mm = "0" + _now_mm; }
    if (_hh+_mm == _now_hh+_now_mm)
    {
        return;
    }
    if (_ss != '')
    {
        if (_now.getSeconds() > 0)
        {
            return;
        }
    }
    _hh = _now.getHours();
    _mm = _now.getMinutes();
    _ss = _now.getSeconds();
    if (_hh < 10) {_hh = "0" + _hh; }
    if (_mm < 10) {_mm = "0" + _mm; }
    _time = _hh+":"+_mm;
    var pars = 'time=' + _time + '&id=' + _id;

    var a = new Ajax.Request(
        "/dogs/rest",
        {
            method: 'get',
            parameters: pars,
            onSuccess: function(request)
            {
                var json;
                eval("json="+request.responseText);
//                alert(request.responseText);
            },
            onComplete: function(request)
            {
//                alert(request.responseText);
                var item = $('photodogs');
                var text = '';
                var json;
                _pic1 = _time.substr(0,1)+'.png';
                _pic2 = _time.substr(1,1)+'.png';
                _pic3 = _time.substr(3,1)+'.png';
                _pic4 = _time.substr(4,1)+'.png';
                eval("json="+request.responseText);
                text += '<div id="inu"><img id="photo" src="\/'+json[0]['Photo']['file_path']+'" width="'+json[0]['Photo']['width_size']+'" height="'+json[0]['Photo']['height_size']+'" /></div>';
                text += '<div id="inu-protection"><img src="\/img\/inu-protection.png" width="590" height="450" /></div>';
                text += '<div id="tokei">';
                text += '<div class="time">';
                text += '<img src="\/img\/'+_pic1+'" width="27" height="38" />';
                text += '<img src="\/img\/'+_pic2+'" width="27" height="38" />';
                text += '<img src="\/img\/colon.png" width="27" height="38" />';
                text += '<img src="\/img\/'+_pic3+'" width="27" height="38" />';
                text += '<img src="\/img\/'+_pic4+'" width="27" height="38" />';
                text += '</div>';
                text += '</div>';
                text += '<div id="inu-profile">';
                text += '<span>名前：'+json['DogProfile']['name']+'</span><br />';
                text += '<span>犬種：'+json['Breed']['sub_breed']+'</span><br />';
                if (json['DogProfile']['sex'] == '0')
                {
                    text += '<span>性別：♀</span><br />';
                }
                else if (json['DogProfile']['sex'] == '1')
                {
                    text += '<span>性別：♂</span><br />';
                }
                else
                {
                    text += '<span>性別：不明</span><br />';
                }
                text += '<span>生年月日：'+json['DogProfile']['birthday'].substring(0,10)+'</span><br />';
                if (json['DogProfile']['charming_point'] != null)
                {
                    text += '<span>チャームポイント：<br />'+json['DogProfile']['charming_point']+'</span><br />';
                }
                text += '</div>';
                _id = json['DogProfile']['id'];

                Element.update(item, text);
                document.getElementById("photo").style.width = json[0]['Photo']['width_size']+"px";
                document.getElementById("photo").style.height = json[0]['Photo']['height_size']+"px";
                document.getElementById("photo").style.marginTop = ((450 - json[0]['Photo']['height_size'])/2)+"px";
                document.getElementById("photo").style.marginLeft = ((590 - json[0]['Photo']['width_size'])/2)+"px";
                document.getElementById("photo").style.marginRight = ((590 - json[0]['Photo']['width_size'])/2)+"px";
                document.getElementById("photo").style.marginBottom = ((450 - json[0]['Photo']['height_size'])/2)+"px";
                new Effect.Appear($("photo"),{ from:0.0, to:1.0 });
            },
            onFailure: function(request)
            {
                var item = $('photodogs');
                Element.update(item, request.responseText);
            },
            onException: function (request)
            {
                var item = $('photodogs');
                Element.update(item, request.responseText);
            }
        }
    );
}

/*--------------------------------------------------------------------------*/
