/************************************************
  
    Site Name: 
	Description: common script
	Version: 
	Author: 
	Last Modified :

************************************************/
/*漢字*/
var gazo = new Array("img/f1.gif","img/f2.gif","img/f3.gif","img/f4.gif","img/f5.gif");

var ptvlm = 40;
vcty0=5;
limtt=40;
diffs=20;
inter=30;

mlocx=0;
mlocy=0;
incoherent = false;

particle=new Array();
velocitx=new Array();
velocity=new Array();

function particleinit(){
  for(i=0;i<ptvlm;i++) {
    particle[i].style.display="none";
    
    px = (vcty0 << 1)*Math.random();
    py = (vcty0 << 1)*Math.random();
    
    vx = px - vcty0;
    vy = py - vcty0;
    lm = Math.sqrt( (vcty0*vcty0) - (vx*vx));
    if(vy > lm) {
      vy = lm*Math.random();
    } else if (vy < -lm) {
      vy=- lm*Math.random();
    }
    
    particle[i].ilocx=px;
    particle[i].ilocy=vy+vcty0;
    velocitx[i]=vx;
    velocity[i]=vy;
  }
}

function fire(e) {
  itvlt = 0;
  particleinit();
  if(incoherent)  return; //clearinterval(incoherent); 
    if(document.all) {
    mlocx=document.body.scrollLeft+window.event.clientX;
    mlocy=document.body.scrollTop+window.event.clientY;
  } else {
    mlocx=window.pageXOffset +e.clientX;
    mlocy=window.pageYOffset +e.clientY;
  }
  incoherent=setInterval('itvlt=cracker(itvlt);',inter); 
}


function cracker(elptm){ 
  unitt = (diffs / (elptm + 1 ) ); 
  for(i=0;i<ptvlm;i++) {
    particle[i].style.display = "block";
//    particle[i].style.pixelTop = mlocy - particle[i].ilocy;
//    particle[i].style.pixelLeft = mlocx + particle[i].ilocx;
    particle[i].style.top = mlocy - particle[i].ilocy + "px";
    particle[i].style.left = mlocx + particle[i].ilocx + "px";
    particle[i].ilocx += velocitx[i]*unitt;
    particle[i].ilocy += velocity[i]*unitt - (0.098*(elptm*elptm)/2);

    if (document.all) {
      if(particle[i].filters[0]) {
        particle[i].filters[0].Opacity= 100- elptm*3;
      }
      if(particle[i].filters[1]) {
        if (elptm < 12) {
          if (Math.random()*unitt*5<1) {
            if(particle[i].filters[1].Rotation==3) {
              particle[i].filters[1].Rotation=0 //Math.random();
            } else {
              particle[i].filters[1].Rotation+=1 //Math.random();

            }
          }
        }
      }
    }else {
      if(particle[i].style.opacity) {
        particle[i].style.opacity = (100- elptm*3)/100;
      }
    }

  }
  if (elptm > limtt) {
    clearInterval(incoherent);
    particleinit();
    incoherent=false;
  }
  return ++elptm;
}

/* get div object by name */
function getDivFromName(nm){
  // IE5+, Mozilla, Opera
  if(document.getElementById) return document.getElementById(nm); 
  if(document.all) return document.all(nm); // IE4
  if(document.layers){ // NN4
    var s='';
    for(var i=1; i<arguments.length; i++)
      s+='document.layers.'+arguments[i]+'.';
    return eval(s+'document.layers.'+nm);
  }
  return null;
}

/* write htmle in DIV */
function writeDivHTML(div,html){
   if(document.layers){ // NN4
    div.document.open();
    div.document.write(html);
    div.document.close();
   }
   else if(typeof div.innerHTML!="undefined"){ // IE, Mozilla, Opera
    div.innerHTML=html;
   }
}

var text="自由が丘の住宅地に在る癒し空間　　それがFragrant Blossomsです";
type_num = 0; 
tid=null; 
interval = 200; // この値を小さくすると、文字が出現するスピードが速くなる。
reInterval = 2000; // いったん消えた文字列が再びタイプされ始めるまでの時間

function typeText(){
 var s='';
 var div=getDivFromName('catcharea');
 if(type_num<text.length){
   type_num++;
   s = '<span class="str">'+text.substr(0,type_num)+'<\/span>';
   writeDivHTML(div,s);
   tid=setTimeout('typeText();',interval);
 }else{
   writeDivHTML(div,'');
   type_num = 0;
   tid=setTimeout('typeText();',reInterval);
 }  
} 
function cancel(){
  if(tid) { clearTimeout(tid); tid=null; } 
}

var div=null;
spaces =2; // "文字列に含まれる空白（スペース）の数
function getCol(sr,sg,sb,er,eg,eb,i,n){
   // sr,sg,sb: 最初の色(RGB16進数値)   
   // er,eg,eb: 最後の色(RGB16進数値)  
  var steps = n-1; // 階調  
  var dr=er-sr,dg=eg-sg,db=eb-sb;
  var r=(Math.floor(dr*i/steps)+sr).toString(16); 
  var g=(Math.floor(dg*i/steps)+sg).toString(16);
  var b=(Math.floor(db*i/steps)+sb).toString(16);
  return '#'+(r.length==1?'0'+r:r)+(g.length==1?'0'+g:g)+(b.length==1?'0'+b:b);
}
 
function setCol(n){
 this.length = n;
 var len=this.length-spaces;
 var count = -1;
 var num=new Array(); 
 for(var i=0; i<len; i++){
  num[i]=getCol(0x66,0x33,0x66,0xFF,0x66,0x66,i,len);
 }
 while(count<this.length-1){
  count++;
  if(count==7||count==12) continue;
  /* "Dynamic Neon Title"の文字列において、0スタートの先頭から数えて      7番目と12番目の文字は空白（スペース）なので、処理を飛ばして色の値を代入しない。*/  var j=Math.floor(Math.random()*len);
  if(j==len) j=len-1;
  this[count]=num[j]; 
  delete num[j];
  for(var k=j; k<len-1; k++){
   num[k]=num[k+1];
  } 
  len--;
 } 
 return this;
} 
function neonText(){
 div=getDivFromName('neon');
 var col=new setCol(text.length);
 var s=''; 
 for (var i=0; i<text.length; i++){
   /* NN4でのインラインスタイルシートの使用は異常終了する可能性が高いので、場合分けをする。*/
  if(document.layers /* NN4 */){ 
   s+='<font class="str" color="'+col[i]+'">'+text.substr(i,1)+'<\/font>';
  }else{
   s+='<span class="str" style="color:'+col[i]+'">'+text.substr(i,1)+'<\/span>';
  }
 }
 writeDivHTML(div,s);
 tid=setTimeout('neonText();',interval);
}

