//■■共通的な関数

function DVEX_calcScreen() {
 DVEX_screenWidth  = DVEX_canvas.clientWidth;
 DVEX_screenHeight = DVEX_canvas.clientHeight;
 DVEX_screenLeft   = DVEX_canvas.scrollLeft;
 DVEX_screenTop    = DVEX_canvas.scrollTop;
 DVEX_screenRight  = DVEX_screenLeft + DVEX_screenWidth;
 DVEX_screenBottom = DVEX_screenTop + DVEX_screenHeight;
}

function DVEX_checkArgInt(_arg,_df) {
 if (typeof(_arg)=="number") {
  var r=parseInt(_arg);
  if ((r<0)||(9<r)) r=_df;
 } else {
  r=_df;
 }
 return r;
}

function DVEX_start(_uid,_url) {

 //共通的な部分
 DVEX_shareLayer.style.position="absolute";
 DVEX_shareLayer.style.visibility="hidden";
 DVEX_shareLayer.style.margin="0px";
 DVEX_shareLayer.style.padding="0px";
 DVEX_shareLayer.style.width="auto";
 DVEX_shareLayer.style.height="auto";
 DVEX_shareLayer.style.whiteSpace="nowrap";
 DVEX_shareLayer.style.left="-100px";
 DVEX_shareLayer.style.top="-100px";
 document.body.appendChild(DVEX_shareLayer);
 DVEX_calcScreen();

 var tmp=document.getElementById('DVEX_0');
 if (tmp.getAttribute('href')!="http://dekirujan.sakura.ne.jp/dekiru/") {
  alert("_"+tmp);
 } else {
  for (var i=0;i<_url.length;i++) {
   DVEX_image[i]=new Image();
   DVEX_image[i].src=_url[i];
  }
  DVEX_loadImage(_uid);
 }
}

function DVEX_loadImage(_uid) {
 var flag=false;
 for (var i=0;i<DVEX_image.length;i++) {
  if ( DVEX_image[i].complete==false ) {
   flag=true;
   break;
  }
 }
 if (flag) {
  setTimeout('DVEX_loadImage('+_uid+');',100);
 } else {
  DVEX_base[_uid].initActor();
  setTimeout('DVEX_base['+_uid+'].main();',1);
 }
}


//■■共通的な変数
var DVEX_root="http://dekirujan.sakura.ne.jp/dekiru/dvex/";
//var DVEX_root="./";
var DVEX_screenLeft;
var DVEX_screenTop;
var DVEX_screenRight;
var DVEX_screenBottom;
var DVEX_screenWidth;
var DVEX_screenHeight;
var DVEX_base=new Array();//本体
var DVEX_image=new Array();//画像のロードに使う一時的なもの
var DVEX_shareLayer=document.createElement('div');//getSizeに使う
var DVEX_ImageUrl=new Array(DVEX_root+"_share/baloon_up.gif", DVEX_root+"_share/baloon_lo.gif", DVEX_root+"_share/shadow.gif");
var DVEX_canvas;
if  (document.compatMode == 'CSS1Compat') {
 DVEX_canvas=document.documentElement;
} else {
 DVEX_canvas=document.body;
}

//■■■Thingクラス
function DVEX_Thing(_parent) {
 this.parent=_parent;
 this.layer=document.createElement('div');
 this.layer.style.position="absolute";
 this.layer.style.overflow="hidden";
 this.layer.style.margin="0px";
 this.layer.style.padding="0px";
 this.layer.style.width="auto";
 this.layer.style.height="auto";
 this.layer.style.whiteSpace="nowrap";
 this.layer.parent=this;
 this.image;
 this.orgWidth;
 this.orgHeight;
 this.color="";
 this.opacity=100;
 this.width;
 this.height;
 this.orgWidth;
 this.orgHeight;
 this.fontSize="";
 this.type;//text または image
 this.animationType=new Array();
 this.animationItem=new Array();
 this.animationThreshold=new Array();
 this.animationIndex=0;
 this.animationValue=0;
 this.isChanged=false;
 this.isOnscreen;

 this.hide=function()
 {
  try {
   document.body.removeChild(this.layer);
  } catch(e) {}
 }

 this.clearLayer=function()
 {
  this.hide();
  if (this.type=="image") {//Body or Shadow
   delete this.image;
  }
  this.layer.innerHTML="";
 }

 this.locate=function(_x,_y,_zIndex,_bottom)
 {
  var zIndex= _zIndex || this.parent.parent.zIndexBase;
  var bottom= _bottom || DVEX_screenBottom;
  if (bottom > DVEX_screenBottom) bottom=DVEX_screenBottom;
  var cl=DVEX_screenRight -_x;
  var ct=bottom -_y;
  this.hide();
  if ((cl>0)&&(ct>0)&&(_x>DVEX_screenLeft-this.width)&&(_y>DVEX_screenTop-this.height)) {
   if (cl<this.width) {
    this.layer.style.width=cl+"px";
   } else {
    this.layer.style.width=this.width+"px";
   }
   if (ct<this.height) {
    this.layer.style.height=ct+"px";
   } else {
    this.layer.style.height=this.height+"px";
   }
   this.layer.style.left=_x+"px";
   this.layer.style.top=_y+"px";
   this.layer.style.zIndex=zIndex;

   document.body.appendChild(this.layer);
   this.isOnScreen=true;
  } else {
   this.isOnScreen=false;
  }
  this.isChanged=false;
  return this.isOnScreen;
 }

 this.getSize=function()
 {
  this.layer.style.width="auto";
  this.layer.style.height="auto";
  this.layer.style.position="static";
  DVEX_shareLayer.appendChild(this.layer);
  this.width=DVEX_shareLayer.offsetWidth;
  this.height=DVEX_shareLayer.offsetHeight;
  this.orgWidth=this.width;
  this.orgHeight=this.height;
  DVEX_shareLayer.removeChild(this.layer);
  this.layer.style.position="absolute";
 }

 this.setText=function(_str)
 {
  this.clearLayer();
  this.layer.innerHTML=_str;
  this.getSize();
  this.type="text";
  this.isChanged=true;
 }

 this.setImage=function(_url)
 {
  this.clearLayer();
  this.image=document.createElement("img");
  this.image.src=_url;
  this.layer.appendChild(this.image);
  this.getSize(this.layer);
  this.type="image";
  this.isChanged=true;
 }

 this.setSize=function(_width,_height) {
  this.hide();
  if (this.type=="image") {
   this.image.style.width=_width+"px";
   this.image.style.height=_height+"px";
   this.width=_width;
   this.height=_height;
  } else {
   this.fontSize=_width;
   this.layer.style.fontSize=this.fontSize+"pt";
   this.getSize(this.layer);
  }
  this.isChanged=true;
 }

 this.setColor=function(_col) {
  this.layer.style.color=_col;
//  this.isChanged=true;
 }

 this.setOpacity=function(_opa) {
  if (_opa<=0) {
   this.layer.style.visibility="hidden";
  } else {
   this.layer.style.visibility="visible";
  }
  if (navigator.userAgent.indexOf('Safari') !=-1 ) {
   //safariは何もしない
  } else if (document.all) {  //IE
   if (_opa==100) {
    this.layer.style.filter='';
   } else {
    this.layer.style.filter='alpha(opacity='+_opa+')';
   }
  } else if(navigator.userAgent.indexOf('Gecko')!=-1) { //FF
   if (_opa==100) {
    this.layer.style.MozOpacity = "";
   } else {
    this.layer.style.MozOpacity = _opa/100;
   }
  }
  this.opacity=_opa;
 }

 this.action=function(arg)
 {
  //サブクラスで記述必須
 }

 this.setAnimation=function(_array)
 {
  for (var i=0;i<_array.length;i++) {
   this.animationType.push(_array[i][0]);
   this.animationItem.push(_array[i][1]);
   this.animationThreshold.push(_array[i][2]);
  }
 }

 this.initAnimation=function()
 {
  this.animationIndex=0;
  if (this.animationType[this.animationIndex]=="image") {
   this.setImage(this.animationItem[this.animationIndex]);
  } else {
   this.setText(this.animationItem[this.animationIndex]);
  }
 }

 this.clearAnimation=function()
 {
  this.animationType.length=0;
  this.animationItem.length=0;
  this.animationThreshold.length=0;
 }

 this.animation=function(_value) {
  if (this.animationType.length>0) {
   this.animationValue+=_value;
   if (this.animationValue > this.animationThreshold[this.animationIndex]) {
    while (this.animationValue > this.animationThreshold[this.animationIndex]) {
     this.animationValue-=this.animationThreshold[this.animationIndex];
     this.animationIndex++;
     if (this.animationIndex>=this.animationItem.length) {
      this.animationIndex=0;
     }
    }
    if (this.animationType[this.animationIndex]=="image") {
     var w=this.width;
     var h=this.height;
     this.setImage(this.animationItem[this.animationIndex]);
//     this.setSize(w,h);
    } else {
     this.setText(this.animationItem[this.animationIndex]);
    }
   }
  }
 }
}
//■■Bodyクラス　Thingのサブクラス
function DVEX_Body(_parent) {
 this.base=DVEX_Thing;
 this.base(_parent);
}
DVEX_Body.prototype=new DVEX_Thing;

//■■Shadowクラス　Thingのサブクラス
function DVEX_Shadow(_parent) {
 this.base=DVEX_Thing;
 this.base(_parent);

 this.rate=0.5;//影の縦横比
 this.setImage(DVEX_root+"_share/shadow.gif");//影のデフォルト
 this.setSize=function(_size1,_size2)//オーバーライド
 {
  var size2= _size2 || _size1*this.rate;
  this.base=DVEX_Shadow.prototype.setSize;
  this.base(_size1,size2);
 }
}
DVEX_Shadow.prototype=new DVEX_Thing;

//■■Baloonクラス　Thingのサブクラス
function DVEX_Baloon(_parent) {
 this.base=DVEX_Thing;
 this.base(_parent);
 this.baloonHtmlUpper;
 this.baloonHtmlLower;

 this.setImage=function(_url) //オーバーライド
 {
  //何もしない
 }

 this.setText=function(_str,_size) //オーバーライド
 {
  if (typeof(_size)=="number") {
   this.fontSize=_size+"px";
  } else {
   this.fontSize="12px";
  }
  //文字のサイズを計測
  var str='<div style="background:#FFFFFF;padding:2px 6px 2px 6px;color:#000000;font-size:'+this.fontSize+';">'+_str+'</div>';

  this.baloonHtmlUpper=
   '<table border="0" cellpadding="0" cellspacing="0">'+
   '<tr bgcolor="#FFFFFF">'+
   '<td>'+str+'</td>'+
   '</tr><tr>'+
   '<td align="center"><img src="'+DVEX_root+'_share/baloon_up.gif"></td>'+
   '</tr>'+
   '</table>';
  this.baloonHtmlLower=
   '<table border="0" cellpadding="0" cellspacing="0">'+
   '<tr>'+
   '<td align="center"><img src="'+DVEX_root+'_share/baloon_lo.gif"></td>'+
   '</tr><tr bgcolor="#FFFFFF">'+
   '<td>'+str+'</td>'+
   '</tr>'+
   '</table>';

  DVEX_shareLayer.innerHTML=this.baloonHtmlUpper;
  this.width=DVEX_shareLayer.offsetWidth;
  this.height=DVEX_shareLayer.offsetHeight;
  DVEX_shareLayer.innerHTML="";
  this.clearLayer();
  this.type="text";
  this.isChanged=true;
 }
}
DVEX_Baloon.prototype=new DVEX_Thing;
//■■■Baseクラス
function DVEX_Base(_uid) {
 this.uid=_uid;
 this.interval=100;//msec
 this.zIndexBase=1000;//zIndexの基底。ここから上積みされていく
 this.ADactor;
 
 this.hideAllLayers=function(_actors)
 {
  //サブクラスにて記述必須
 }

 this.showAllLayers=function(_actors)
 {
  //サブクラスにて記述必須
 }

 this.hideActorLayers=function(_actors)
 {
  for (var i in _actors) {
   if (!(isNaN(Number(i)))) {
    _actors[i].hide();
   }
  }
 }

 this.showActorLayers=function(_actors)
 {
  for (var i in _actors) {
   if (!(isNaN(Number(i)))) {
    _actors[i].locate(_actors[i].x,_actors[i].y);
   }
  }
 }

 this.main=function() {
  //サブクラスにて記述必須
 }

 this.initActor=function()
 {
  //最初に1回だけ呼ばれる。
//【初期呼び出し】
  //広告枠だけは先に作っておく（ロードを1回にするため）
  DVEX_calcScreen();
  var id=0;
  this.ADactor=new DVEX2_ActorFW2D_AD(id,this);
 }

}
//■■■Actorクラス
function DVEX_Actor(_uid,_parent) {
 this.uid=_uid;
 this.parent=_parent;
 this.x=-100;//bodyの中央
 this.y=-100;//2Dならbodyの中央、3Dならbodyの下
 this.isChanged;
 this.isOnScreen;
 this.status;

 this.locate=function(_x,_y) {
  //サブクラスに記述あり
 }

 this.hide=function(_x,_y) {
  //サブクラスに記述あり
 }

 this.action=function(arg)
 {
  //サブクラスに記述あり
 }

 this.finalize=function()
 {
  //サブクラスに記述あり
 }
}

//■■■Actor2Dクラス Actorのサブクラス
function DVEX_Actor2D(_uid,_parent) {
 this.base=DVEX_Actor;
 this.base(_uid,_parent);

 this.body=new DVEX_Body(this);
 this.baloon=new DVEX_Baloon(this);
 this.baloonVisible=false;
 this.baloonPositionUpper;

 this.locate=function(_x,_y)
 {
  this.x=_x;
  this.y=_y;
  this.body.isChanged=true;
 }

 this.refresh=function()
 {
  if (this.body.isChanged) {
   this.baloon.isChanged=this.baloonVisible;
   var bodyL=Math.floor(this.x-this.body.width/2);
   var bodyT=Math.floor(this.y-this.body.height/2);
   this.isOnScreen=this.body.locate(bodyL,bodyT);
  }

  if (this.baloon.isChanged) {
   var baloonL=this.x-Math.floor(this.baloon.width/2);
   var baloonT=bodyT-this.baloon.height;
   if ((baloonL+this.baloon.width) > DVEX_screenRight) {
    baloonL=DVEX_screenRight-this.baloon.width;
   } else if (baloonL < DVEX_screenLeft ) {
    baloonL=DVEX_screenLeft;
   }

   if (baloonT < DVEX_screenTop ) {//下にバルーン
    baloonT=bodyT+this.body.height;
    if (this.baloonPositionUpper) {//反転
     this.baloon.layer.innerHTML=this.baloon.baloonHtmlLower;
     this.baloonPositionUpper=false;
    }
   } else {
    if (! this.baloonPositionUpper) {//反転
     this.baloon.layer.innerHTML=this.baloon.baloonHtmlUpper;
     this.baloonPositionUpper=true;
    }
   }
   //このorは順番逆にすると動かないので注意！
   this.isOnScreen=this.baloon.locate(baloonL,baloonT) || this.isOnScreen;
  }
 }

 this.hide=function()
 {
  this.body.hide();
  this.baloon.hide();
 }

 this.setText=function(_txt)
 {
  this.body.setText(_txt);
 }

 this.setBaloonText=function(_txt,_size)
 {
  this.baloon.setText(_txt,_size);
  this.baloonPositionUpper=true;
  this.baloon.layer.innerHTML=this.baloon.baloonHtmlUpper;
 }

 this.showBaloon=function()
 {
  this.baloonVisible=true;
  this.baloon.isChanged=true;
 }

 this.hideBaloon=function()
 {
  this.baloonVisible=false;
  this.baloon.hide();
 }

 this.setImage=function(_url)
 {
  this.body.setImage(_url);
 }

 this.setSize=function(_size1,_siez2)
 {
  this.body.setSize(_size1,_siez2);
 }

 this.setColor=function(_col)
 {
  this.body.setColor(_col);
 }

 this.setOpacity=function(_opa)
 {
  this.body.setOpacity(_opa);
  this.baloon.setOpacity(_opa);
 }

 this.finalize=function()
 {
  this.body.clearLayer();
  delete this.body.layer;
  delete this.body;
  if (this.baloon) {
   this.baloon.clearLayer();
   delete this.baloon.layer;
   delete this.baloon;
  }
 }

}
DVEX_Actor2D.prototype=new DVEX_Actor;


function computeDate(year, month, day, addDays) {
    var dt = new Date(year, month - 1, day);
    var baseSec = dt.getTime();
    var addSec = addDays * 86400000;//日数 * 1日のミリ秒数
    var targetSec = baseSec + addSec;
    dt.setTime(targetSec);
    return dt;
}

//■■■2D型の基本クラス 広告表示版
function DVEX2_ActorFW2D_AD(_uid,_parent) {

 this.onMouseOver=function()
 {
  if (this.status="go") {
   this.status="wait";
//   if (this.message!=null) {
//    this.setBaloonText(this.message);
//    this.showBaloon();
//    this.refreshBaloon();
//   }
  }
 }

 this.onMouseOut=function()
 {
  this.status="go";
//  this.hideBaloon();
//  this.refreshBaloon();
 }
 
 this.onClick=function()
 {}

 this.appendEvent=function(ev)
 {
  var ev=new Array();
  ev[0]=new Array("onmouseover",
                 "onMouseOver()");
  ev[1]=new Array("onmouseout",
                 "onMouseOut()");
//  ev[2]=new Array("onclick",
//                 "onClick()");
  var func;
  if (document.all) {
   for (var i=0;i<ev.length;i++) {
    func="DVEX_base["+this.parent.uid+"].ADactor."+ev[i][1];
    this.body.layer.setAttribute( ev[i][0] , new Function( func ));
   }
  } else {
   for (var i=0;i<ev.length;i++) {
    func="DVEX_base["+this.parent.uid+"].ADactor."+ev[i][1];
    this.body.layer.setAttribute( ev[i][0] , func );
   }
  }
 }
/* var tmp=(Math.random()<0.7) ? " " : 
          "<iframe src=\"http://rcm-jp.amazon.co.jp/e/cm?t="
         +"dankajr08-22&o=9&p=6&l=ez&f=ifr&f=ifr\" "
         +"width=\"120\" height=\"150\" scrolling=\"no\" "
         +"marginwidth=\"0\" marginheight=\"0\" border=\"0\" "
         +"frameborder=\"0\" style=\"border:none;\"></iframe>";
*/

 this.base=DVEX_Actor2D;
 this.base(_uid,_parent);
 this.message=null;//バルーンなし

var tmp="";
switch (Math.floor(Math.random()*1000) % 4) {
 case 0:
 case 1:
tmp="<iframe src=\"http://rcm-jp.amazon.co.jp/e/cm?t=dankajr08-22&o=9&p=6&l=ez&f=ifr&f=ifr\" width=\"120\" height=\"150\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" border=\"0\" frameborder=\"0\" style=\"border:none;\"></iframe>";
DVEX2_Ad_height=150;
break;
 default:
tmp="<div id=\"DVEX2_AD\"> </div>";
DVEX2_Ad_height=1;
break;
}

 this.body.layer=document.createElement('div');
 this.body.layer.parent=this.body;
 this.body.width=120;
 this.body.height=DVEX2_Ad_height || 240;
 this.body.type="text";
 this.body.layer.style.position="absolute";
 this.body.layer.style.visibility="visible";
 this.body.layer.style.margin="0px";
 this.body.layer.style.padding="0px";
 this.body.layer.style.width=this.body.width+"px";
 this.body.layer.style.height=this.body.height+"px";
 this.body.layer.style.whiteSpace="nowrap";
 this.body.layer.style.left=(DVEX_screenRight-this.body.width)+"px";
 this.body.layer.style.top=(DVEX_screenBottom-this.body.height)+"px";
 document.body.appendChild(this.body.layer);
 this.body.layer.innerHTML=tmp;
 this.body.isChanged=false;
 this.animationFlag=false;

//初期位置とx,yの移動
 this.direction=new Array(2,6);//方向はテンキーの4682
 this.directionIndex=0;
 this.velocity=20;
 this.x=DVEX_screenRight-this.body.width;
 this.y=DVEX_screenBottom-this.body.height;
 this.locate(this.x,this.y);
 this.status="go";
 this.appendEvent(this.ev);
 this.refresh();

 this.action=function(_interval)
 {//intervalはミリ秒
  var interval=_interval/1000;
  //通常の移動
  if (this.status=="go") {
   if (this.animationFlag==true) {
    this.body.animation(interval);
   }
   switch (this.direction[this.directionIndex]) {
    case 4:
     this.x-=this.velocity*interval;
    break;
    case 6:
     this.x+=this.velocity*interval;
    break;
    case 8:
     this.y-=this.velocity*interval;
    break;
    case 2:
     this.y+=this.velocity*interval;
    break;
    default:
    break;
   }
   //位置補正
   if (this.x<DVEX_screenLeft) {
    this.x=DVEX_screenLeft;
    this.directionIndex++;
   } else if (this.x>(DVEX_screenRight-this.body.width)) {
    this.x=DVEX_screenRight-this.body.width;
    this.directionIndex++;
   }
   if (this.y<DVEX_screenTop) {
    this.y=DVEX_screenTop;
    this.directionIndex++;
   } else if (this.y>(DVEX_screenBottom-this.body.height)) {
    this.y=DVEX_screenBottom-this.body.height;
    this.directionIndex++;
   }
   if (this.directionIndex >= this.direction.length) {
    this.directionIndex=0;
   }
//   this.locate(this.x, this.y);
//   this.refresh();refreshをかけるとiframe内リロードになるので使わない
   this.body.layer.style.left=this.x+"px";
   this.body.layer.style.top=this.y+"px";
  }
 }
}
DVEX2_ActorFW2D_AD.prototype=new DVEX_Actor2D;

//■■■Actor3Dクラス Actorのサブクラス
function DVEX_Actor3D(_uid,_parent) {
 this.base=DVEX_Actor;
 this.base(_uid,_parent);

 this.body=new DVEX_Body(this);
 this.shadow=new DVEX_Shadow(this);
 this.shadowVisible=false;
 this.baloon=new DVEX_Baloon(this);
 this.baloonVisible=false;
 this.baloonPositionUpper;
 this.z=0;//高さ

 this.locate=function(_x,_y,_z) {
  this.x=_x;
  this.y=_y;
  this.z=_z;
  this.body.isChanged=true;
 }

 this.refresh=function()
 {
  var ZIndex=this.parent.zIndexBase+Math.floor(this.y)+1;
  if (this.body.isChanged) {
   this.shadow.isChanged=this.shadowVisible;
   this.baloon.isChanged=this.baloonVisible;
   var bodyL=Math.floor(this.x-this.body.width/2);
   var bodyB=Math.floor(this.y);
   var bodyT=bodyB-this.body.height-Math.floor(this.z);
   this.isOnScreen=this.body.locate(bodyL,bodyT,ZIndex,bodyB);
  }

  if (this.shadow.isChanged) {
   var shadowL=Math.floor(this.x-this.shadow.width/2);
   var shadowT=Math.floor(this.y-this.shadow.height/2);
   //このorは順番逆にすると動かないので注意！
   this.isOnScreen=this.shadow.locate(shadowL,shadowT,this.parent.zIndexBase) || this.isOnScreen;
  }

  if (this.baloon.isChanged) {
   var baloonL=this.x-Math.floor(this.baloon.width/2);
   var baloonT=bodyT-this.baloon.height;
   if ((baloonL+this.baloon.width) > DVEX_screenRight) {
    baloonL=DVEX_screenRight-this.baloon.width;
   } else if (baloonL < DVEX_screenLeft ) {
    baloonL=DVEX_screenLeft;
   }

   if (baloonT < DVEX_screenTop ) {//下にバルーン
    baloonT=bodyT+this.body.height;
    if (this.baloonPositionUpper) {//反転
     this.baloon.layer.innerHTML=this.baloon.baloonHtmlLower;
     this.baloonPositionUpper=false;
    }
   } else {
    if (! this.baloonPositionUpper) {//反転
     this.baloon.layer.innerHTML=this.baloon.baloonHtmlUpper;
     this.baloonPositionUpper=true;
    }
   }
   //このorは順番逆にすると動かないので注意！
   //this.isOnScreen=this.baloon.locate(baloonL,baloonT,ZIndex) || this.isOnScreen;
   this.baloon.locate(baloonL,baloonT,ZIndex);
  }
 }

 this.hide=function() {
  //この関数は一時的に隠すために使用。
  //shadow,baloonを消す場合は別途hideShadow,hideBaloonを呼ぶこと
  this.body.hide();
  this.shadow.hide();
  this.baloon.hide();
 }

 this.setText=function(_txt)
 {
  this.body.setText(_txt);
 }

 this.showShadow=function()
 {
  this.shadowVisible=true;
  this.shadow.isChanged=true;
 }

 this.hideShadow=function()
 {
  this.shadowVisible=false;
  this.shadow.hide();
 }

 this.setBaloonText=function(_txt,_size)
 {
  this.baloon.setText(_txt,_size);
  this.baloonPositionUpper=true;
  this.baloon.layer.innerHTML=this.baloon.baloonHtmlUpper;
 }

 this.showBaloon=function()
 {
  this.baloonVisible=true;
  this.baloon.isChanged=true;
 }

 this.hideBaloon=function()
 {
  this.baloonVisible=false;
  this.baloon.hide();
 }

 this.setImage=function(_url)
 {
  this.body.setImage(_url);
 }

 this.setSize=function(_size1,_siez2)
 {
  this.body.setSize(_size1,_siez2);
  this.shadow.setSize(_size1);
 }

 this.setColor=function(_col)
 {
  this.body.setColor(_col);
 }

 this.setOpacity=function(_opa)
 {
  this.body.setOpacity(_opa);
  this.shadow.setOpacity(_opa);
  this.baloon.setOpacity(_opa);
 }

 this.finalize=function()
 {
  this.body.clearLayer();
  delete this.body.layer;
  delete this.body;
  if (this.shadow) {
   this.shadow.clearLayer();
   delete this.shadow.layer;
   delete this.shadow;
  }
  if (this.baloon) {
   this.baloon.clearLayer();
   delete this.baloon.layer;
   delete this.baloon;
  }
 }

}
DVEX_Actor3D.prototype=new DVEX_Actor;
//■■Heartクラス　Baseクラスのサブクラス
function DVEX_BaseHeart(_uid) {
 this.base=DVEX_Base;
 this.base(_uid);

 //★Actorとローカル変数の定義
 this.heartCount=0;
 this.timer=0;
 this.actorHeart=new Array();

 //★カスタマイズ用変数
 //this.interval;
 this.heartUp;
 this.newHeartInterval;

 //★自分ところで使っているActorを定義すること
 this.hideAllLayers=function() {
  this.hideActorLayers(this.actorHeart);
 }

 //★自分ところで使っているActorを定義すること
 this.showAllLayers=function() {
  this.showActorLayers(this.actorHeart);
 }
 this.main=function() {
   var sleepTimeBegin=new Date();
   var err=false;
   DVEX_calcScreen();
  try {

//★ここからメインループの処理を記述する

   //すべてのハートを動かす
   this.ADactor.action(this.interval);
   for (var i in this.actorHeart) {
if (typeof(this.actorHeart[i].action)!="undefined") {
    this.actorHeart[i].action(this.interval);
    //終了なら消す
    if (this.actorHeart[i].status=="dead") {
     this.actorHeart[i].finalize();
     delete this.actorHeart[i];
     this.heartCount--;
    }
}
   }
   //新規のハート
   this.timer+=this.newHeartInterval*this.interval;
   var th=2000000/DVEX_screenWidth;
   if (this.timer>th) {
    this.timer=0;
    var id=this.actorHeart.length;
    this.actorHeart[id]=new DVEX_ActorHeart(id,this);
   }

//★メインループの処理ここまで

  } catch(e) {
   alert(e.description);
   err=true;
  }
  var sleepTimeEnd=new Date();
  var sleepTime=this.interval-(sleepTimeEnd.getTime()-sleepTimeBegin.getTime());
  if ( sleepTime < 10 ) {
   sleepTime=10;
  }
  if (err==false) {
   setTimeout('DVEX_base['+this.uid+'].main();',sleepTime);
  }
 }
}
function DVEX_ActorHeart(_uid,_parent) {//Actorクラスのサブクラス
 this.base=DVEX_Actor3D;
 this.base(_uid,_parent);
 this.status="up";
 this.count0=1000;//ハートが消える時間をミリ秒で（初期値）
 this.count=this.count0;//ハートが消える時間をミリ秒で（カウントダウン）

 var rate=0.1+this.parent.heartSize/10;
 this.bodywidth0=Math.floor(rate*45);//ハートの横幅のデフォルト
 this.bodyheight0=Math.floor(rate*45);

 this.setImage(DVEX_root+"heart/heartR40b.gif");
 this.setSize(1,this.bodyheight0);
 this.x=Math.random()*DVEX_screenWidth+DVEX_screenLeft;
 this.y=Math.random()*DVEX_screenHeight+DVEX_screenTop;
 this.z=-this.body.height;
 this.vz=this.parent.heartUp*30+100;//鉛直方向の速度
 this.vx=2*this.bodywidth0*(-0.5+Math.random());
 this.vy=2*this.bodywidth0*(-0.5+Math.random());
 this.g=-100;//重力係数
 this.locate(this.x,this.y,this.z);
 this.shadow.setSize(0.8*this.body.width*(DVEX_screenHeight-Math.abs(this.z))/DVEX_screenHeight);
 this.shadow.setOpacity(50);
 this.showShadow();

 this.action=function(_interval) {

  var w=(this.z+this.body.height)*0.4;
  if (w>this.bodywidth0) {
   w=this.bodywidth0;
  } else if (w<1) {
   w=1;
  }
  if (w != this.body.width) {
   this.setSize(w,this.bodyheight0);
  }

  this.vz+=this.g *_interval/1000;
  this.z+=this.vz *_interval/1000;
  this.x+=this.vx *_interval/1000;
  this.y+=this.vy *_interval/1000;
  if (this.status=="up") {
   if (this.vz<0) {
    this.status="down";
   }
  } else { // (this.status=="down")
   this.count -= _interval;
   if (this.count<0) {
    this.status="dead";
   } else {
    this.body.setOpacity(this.count/this.count0*100);
    this.shadow.setOpacity(this.count/this.count0*50);
   }
  }
  if (this.isOnScreen==false) {
   this.status="dead";
  }
  var jh=DVEX_screenHeight-Math.abs(this.z)*2;
  if (jh<0) {
   jh=0;
  }
  this.shadow.setSize(0.8*this.body.width*jh/DVEX_screenHeight);
  this.locate(this.x,this.y,this.z);
  this.refresh();
 }
}
DVEX_ActorHeart.prototype=new DVEX_Actor3D;
function DVEX_Heart_init() {

 var id=DVEX_base.length;
 DVEX_base[id]=new DVEX_BaseHeart(id);
 //使用する画像の登録
 DVEX_ImageUrl.push(DVEX_root+"heart/heartR40b.gif");
 //カスタマイズ変数の登録
 var DVEX_tmp;

 if (typeof(DVEX_Heart_smooth)!="number") DVEX_Heart_smooth="";
 DVEX_tmp=DVEX_checkArgInt(DVEX_Heart_smooth,4);
 DVEX_base[id].interval= Math.round(1000 / (3+DVEX_tmp*3) );

 if (typeof(DVEX_Heart_amount)!="number") DVEX_Heart_amount="";
 DVEX_tmp=DVEX_checkArgInt(DVEX_Heart_amount,4);
 DVEX_base[id].newHeartInterval= DVEX_tmp;

 if (typeof(DVEX_Heart_size)!="number") DVEX_Heart_size="";
 DVEX_tmp=DVEX_checkArgInt(DVEX_Heart_size,9);
 DVEX_base[id].heartSize= DVEX_tmp;

 if (typeof(DVEX_Heart_up)!="number") DVEX_Heart_up="";
 DVEX_tmp=DVEX_checkArgInt(DVEX_Heart_up,4);
 DVEX_base[id].heartUp = DVEX_tmp;

 try {
  document.getElementById('DVEX_1').innerHTML="dekiruハート";
 } catch(e) {}
 DVEX_start(id,DVEX_ImageUrl);
}

if (document.all) {
 window.attachEvent('onload',DVEX_Heart_init);
} else {
 window.addEventListener('load',DVEX_Heart_init, false);
}


