/* balloon.js v1.1 */
/* (C)t.hira ( http://thira.plavox.info/ ) */
/* Licensed under Creative Commons Attribution 2.1 Japan ( http://creativecommons.org/licenses/by/2.1/jp/ ) */
/* Licensed under MIT License http://www.opensource.org/licenses/mit-license.php */


// Constructor
function Balloon(){
 this.initMousePosition();
 this.mouseX=0;
 this.mouseY=0;
 this.clear();
 return false;
}
//Clear BalloonStyle
Balloon.prototype.clear=function(s){
 this.setBalloonRound(20);
 this.setBalloonWidth(240);
 this.setBalloonHeight(120);
 this.setBalloonLadder(35);
 this.setBalloonLadderStyle(0);
 this.setFontSize(12);
}
//Set BallonRound
Balloon.prototype.setBalloonRound=function(s){
 Balloon.round=s;
}
//Set BalloonWidth
Balloon.prototype.setBalloonWidth=function(s){
 Balloon.width=s;
}
//Set BalloonHeight
Balloon.prototype.setBalloonHeight=function(s){
 Balloon.height=s;
}
//Set BalloonLadder
Balloon.prototype.setBalloonLadder=function(s){
 Balloon.ladder=s;
}
//Set BalloonLadderStyle
Balloon.prototype.setBalloonLadderStyle=function(s){
 if(s==1){
  Balloon.ladderStyle=90-Math.ceil(Balloon.ladder/3);
  Balloon.ladderWidth=Math.ceil(Balloon.ladder/3*1.7);
  Balloon.ladderOffsetX=Math.ceil(Balloon.ladder/3);
  Balloon.ladderSpacerX=Math.ceil(Balloon.ladder/3)-2;
 }
 else if(s==2){
  Balloon.ladderStyle=120;
  Balloon.ladderWidth=120;
  Balloon.ladderOffsetX=Math.ceil(Balloon.ladder/1.4);
  Balloon.ladderSpacerX=0;
 }
 else{
  Balloon.ladderStyle=10;
  Balloon.ladderWidth=60;
  Balloon.ladderOffsetX=Math.ceil(Balloon.ladder/8);
  Balloon.ladderSpacerX=0;
 }
}
//Set BalloonLadder
Balloon.prototype.setFontSize=function(s){
 Balloon.fontSize=s;
}
//Balloon PopUp
Balloon.prototype.popup=function(id,msg){
 var objBalloon = document.createElement("div");
 var balloonHTML;
 balloonHTML="<div class=\"bl_t\" style=\"margin:0px "+Balloon.round+"px; width:"+(Balloon.width-Balloon.round*2)+"px; border-top:1px solid #d0d0d0; background-color:#fff;\">\n";
 balloonHTML+="<div class=\"bl_tl\" style=\"margin-top:-2px; margin-left:-"+Balloon.round+"px; width:"+Balloon.round+"px; height:"+Balloon.round+"px; background:transparent url('./balloon.gif') no-repeat scroll -10px -10px; display:block; float:left; left:"+Balloon.round+"px; position:absolute; text-align:right;\"></div>\n";
 balloonHTML+="<div class=\"bl_tr\" style=\"margin-top:-2px; margin-right:-"+Balloon.round+"px; width:"+Balloon.round+"px; height:"+Balloon.round+"px; background:transparent url('./balloon.gif') no-repeat scroll -"+(10+Balloon.round)+"px -10px; display:block; float:right; right:"+Balloon.round+"px; position:absolute;\"></div>\n";
 balloonHTML+="<div class=\"bl_closer\" style=\"margin-top:3px; text-align:right\"><a href=\"#\" onclick=\"javascript:balloon.close('"+id+"');return false;\" style=\"margin:0px 1px 0px auto; width:14px; height:14px; background:transparent url('./balloon.gif') no-repeat scroll -200px -10px; display:block;\"></a></div>\n";
 balloonHTML+="</div>\n";
 balloonHTML+="<div class=\"bl_c\" style=\"margin:0px "+Balloon.round+"px; width:"+(Balloon.width-Balloon.round*2)+"px; height:"+(Balloon.height-Balloon.round*2)+"px; background-color:#fff;\">\n";
 balloonHTML+="<div class=\"bl_cl\" style=\"margin-top:-2px; margin-left:-"+Balloon.round+"px; width:"+Balloon.round+"px; height:"+(Balloon.height-Balloon.round*2)+"px; display:block; border-left:1px solid #d0d0d0; background-color:#fff; float:left; left:"+Balloon.round+"px; position:absolute;\" ></div>\n";
 balloonHTML+="<div class=\"bl_cr\" style=\"margin-top:-2px; margin-right:-"+Balloon.round+"px; width:"+Balloon.round+"px; height:"+(Balloon.height-Balloon.round*2)+"px; display:block; border-right:1px solid #d0d0d0; background-color:#fff; float:right; right:"+Balloon.round+"px; position:absolute;\"></div>\n";
 balloonHTML+="<p style=\"margin:0px;\">"+msg+"</p></div>\n";
 balloonHTML+="<div class=\"bl_b\" style=\"margin:0px "+Balloon.round+"px; width:"+(Balloon.width-Balloon.round*2)+"px; height:"+(Balloon.round-2)+"px; border-bottom:1px solid #d0d0d0; background-color:#fff;\">\n";
 balloonHTML+="<div class=\"bl_bl\" style=\"margin-top:-2px; margin-left:-"+Balloon.round+"px; width:"+Balloon.round+"px; height:"+Balloon.round+"px; background:transparent url('./balloon.gif') no-repeat scroll -10px -"+(10+Balloon.round)+"px; display:block; float:left; position:relative;\" ></div>\n";
 balloonHTML+="<div class=\"bl_br\" style=\"margin-top:-2px; margin-right:-"+Balloon.round+"px; width:"+Balloon.round+"px; height:"+Balloon.round+"px; background:transparent url('./balloon.gif') no-repeat scroll -"+(10+Balloon.round)+"px -"+(10+Balloon.round)+"px; display:block; float:right; position:relative;\"></div>\n";
 balloonHTML+="</div>\n";
 balloonHTML+="<div class=\"bl_ldr\" style=\"margin-top:-1px; left:"+(Balloon.width/2-Balloon.ladderOffsetX)+"px; width:"+Balloon.ladderWidth+"px; height:"+(Balloon.ladder)+"px; background:transparent url('./balloon.gif') no-repeat scroll -"+Balloon.ladderStyle+"px -"+(180-Balloon.ladder)+"px; position:absolute;\">&nbsp;</div>\n";
 objBalloon.setAttribute('id','Balloon_'+id);
 document.body.appendChild(objBalloon);
 document.getElementById('Balloon_'+id).style.position="absolute";
 document.getElementById('Balloon_'+id).style.left=Math.ceil(Balloon.mouseX-Balloon.width/2+Balloon.ladderOffsetX-Balloon.ladderSpacerX)+"px";
 document.getElementById('Balloon_'+id).style.top=Balloon.mouseY-Balloon.height-Balloon.ladder+"px";
 document.getElementById('Balloon_'+id).style.fontSize=Balloon.fontSize+"px";
 document.getElementById('Balloon_'+id).innerHTML=balloonHTML;
}
//Balloon Close
Balloon.prototype.close=function(id){
 document.getElementById('Balloon_'+id).innerHTML="";
}
//Bark
Balloon.prototype.bark=function(){
 this.popup('__bark','Wan!Wan!');
}
//Init Mouse Position
Balloon.prototype.initMousePosition=function(){
 window.document.onmousedown = function(e){
  Balloon.mouseX = balloon.getMousePosition(e).x;
  Balloon.mouseY = balloon.getMousePosition(e).y;
 }
}
//Get Mouse Position
Balloon.prototype.getMousePosition=function(e){
 var obj = new Object();
 if(e){
  obj.x = e.pageX;
  obj.y = e.pageY;
 }
 else{
  obj.x = event.x + document.body.scrollLeft;
  obj.y = event.y + document.body.scrollTop;
 }
 return obj;
}

balloon=new Balloon();


