if(typeof brage == "undefined") var brage = new Object();
brage.magical = function(){
  this.bgImgName = {
    "morning" : "/common/images/bg_toppage.jpg",
    "noon"    : "/common/images/bg_toppage_2.jpg",
    "evening" : "/common/images/bg_toppage.jpg",
    "night"   : "/common/images/bg_toppage_3.jpg"
  };
};

brage.magical.prototype.getNow = function(){
  var date = new Date(),
  h = date.getHours(),
  n = (h>=5 && h<=8)?  "morning" :
      (h>=9 && h<=16)? "noon":
      (h>=17 && h<=20)?"evening":"night";
  return n;
};
brage.magical.prototype.changeBG = function(id){
  document.getElementById(id).style.cssText = 'background-image:url("'+this.bgImgName[this.getNow()]+'")';
};
brage.magical.prototype.bnrLoop = function(url,id){
  $.getJSON(url,function(data){
    var d = document,
    pId = 'bnrLoopWrap',
    list = data.banner,
    sec = data.sec,
    html = [];
    html.push('<div id="'+pId+'" style="width:'+data.width+'px; height:'+data.height+'px; overflow: hidden;">');
    for (var i=0; i<list.length; i++){
      html.push('<a href="'+list[i].url+'" target="'+list[i].target+'"><img src="'+list[i].src+'" /></a>');
    };
    html.push('</div>');
    d.getElementById(id).innerHTML = html.join('');
    if(list.length > 1){
      var pDiv = d.getElementById(pId),
      f = function(){
        pDiv.appendChild(pDiv.removeChild(pDiv.getElementsByTagName('a')[0]));
        setTimeout(arguments.callee,sec*1000);
      }();
    }
  });
}
var magical = brage.magical;