﻿//
// バナー表示コントロール
//
function Effect(emID,et,k){
  this.element = document.getElementById(emID);
  this.endtime = et;
  this.kind = k;
  this.starttime = 0;
}

Effect.prototype.LOOP = function(){
  this.starttime++;
  this.MAIN();
  if(this.starttime >= this.endtime) clearInterval(this.settimer);
}

Effect.prototype.START = function(){
  var myObj = this;
  this.settimer = setInterval(function(){myObj.LOOP()},myObj.fps);
}

Effect.prototype.fps = 1000/30;

Effect.prototype.NORMAL = function(v,f,sv,nowf){
  return sv+( v/f * nowf );
}

Effect.prototype.UP = function(v,f,sv,nowf){
  return sv+( v/Math.sqrt(f) * Math.sqrt(nowf) );
}

Effect.prototype.DOWN = function(v,f,sv,nowf){
  return sv+( v/(f*f) * (nowf*nowf) );
}

Effect.prototype.CHANGE = function(k,v,f,sv,nowf){
  switch(k){
    case "up":
      return this.UP(v,f,sv,nowf);
      break;
    case "down":
      return this.DOWN(v,f,sv,nowf);
      break;
    case "normal":
      return this.NORMAL(v,f,sv,nowf);
      break;
  }
}

function move(emID,x,y,t,alp,k){
  var obj = new Effect(emID,t,k);
  obj.elementXY_Init();
  obj.ealp = 100-alp;
  obj.alp = alp;
//  obj.ex = this.x + x;
//  obj.ey = this.y + y;
  obj.MAIN  = function(){
    var X = this.CHANGE(this.kind,x,this.endtime,this.x,this.starttime);
    var Y = this.CHANGE(this.kind,y,this.endtime,this.y,this.starttime);
    var ALP = this.CHANGE(this.kind,this.ealp,this.endtime,this.alp,this.starttime);
    this.elementXY_Set(X,Y);
    this.alpha_Set(ALP);
  }
  obj.START();
  return;
}

Effect.prototype.elementXY_Init = function(){
  this.x = this.element.offsetLeft;
  this.y = this.element.offsetTop;
}

Effect.prototype.elementXY_Set = function(x,y){
  this.element.style.left = x+"px";
  this.element.style.top = y+"px";
}

Effect.prototype.alpha_Init = function(){
  if(this.Browser_find() == "MSIE")this.alp = parseInt((this.element.currentStyle.filter).match(/\d+/));
  else this.alp = parseInt(document.defaultView.getComputedStyle(this.element, null).getPropertyValue('opacity'))*100;
}

Effect.prototype.alpha_Set = function(alp){
  if(this.Browser_find() == "MSIE") this.element.style.filter = 'alpha(opacity='+alp+')';
  else this.element.style.opacity = alp/100;
}

Effect.prototype.Browser_find = function(){
  if((navigator.userAgent.indexOf('MSIE') != -1))return "MSIE";
  if((navigator.userAgent.indexOf('Gecko') != -1))return "Gecko";
  if((navigator.userAgent.indexOf('Safari') != -1))return "Safari";
}


//
var bnum=4;
var intrl1 = 2500;
var intrl2 = 5000;
var ct = 6;

function bnrSelect(sp){
  var cta=0,el,sc,sci;
  var strhtml="";
  var rdnum = new Array();
  var bnrs = document.getElementById("banner_btn");

  psreset(bnrs);

  sc = sp
  while(cta < bnum){
    rdnum.push(sc);
    cta++;
    sc++;
    if(sc == ct){sc = 0;}
  }

  cta = 0;

  while(cta < bnum){
    sci = rdnum[cta];
    strhtml += '<div class="bnr">' + bnrhtml(sci) + '</div>';
    cta++;
  }

  bnrs.innerHTML = strhtml;
  return;
}

function psreset(bnrs){
  bnrs.style.left = 0+"px";
  bnrs.style.top = 0+"px";
}


function bnrhtml(sci){
  switch(sci){
  
  case 0:
    inh = '<a href="printing/propose/index.html"><img src="img/bnr_design.jpg" alt="企画・制作・編集" width="595" height="70" /></a>';
    return inh;
    break;
  case 1:
    inh = '<a href="web/promotion/index.html"><img src="img/bnr_webpromo.jpg" alt="WEBプロモーション" width="595" height="70" /></a>';
    return inh;
    break;
  case 2:
    inh = "<a href=\"d_book/index.html\"><img src=\"img/bnr_webbook.jpg\" width=\"476\" height=\"70\" alt=\"digital catalog\" /></a><a href=\"javascript:void(0);\" onclick=\"javascript:window.open('d_book/shukosha_panf/top.html','ebook','width=1045,height=760,left=0,top=0')\"><img src=\"img/btn_booksample.jpg\" width=\"119\" height=\"70\" id=\"samplebook\" alt=\"CLICKサンプルはこちら\" /></a>";
    return inh;
    break;
  case 3:
    inh = '<a href="d_print/index.html"><img src="img/bnr_digiprint.gif" alt="デジタル印刷" width="595" height="70" /></a>';
    return inh;
    break;
  case 4:
    inh = '<a href="selfpublish/index.html"><img src="img/bnr_selfpublish.jpg" alt="秀巧社印刷の自費出版" width="595" height="70" /></a>';
    return inh;
    break;
  case 5:
    inh = '<a href="sugoroku/index.html"><img src="img/bnr_sugoroku.gif" alt="ストップ温暖化すごろく" width="595" height="70" /></a>';
    return inh;
    break;
  
  }
}

var sp = 2;

function bnrChange(){
  bnrSelect(sp);
  sp++;
  if(sp == ct){sp = 0;}
  move('banner_btn',0,-78,20,40,'normal');
  setTimeout("bnrChange()", intrl2);
}
