/*javascript for Bubble Tooltips by Alessandro Fulciniti
- http://pro.html.it - http://web-graphics.com */

var hideTooltipTimeout = 0;
if( window.jQuery )$(function(){enableTooltips();});

function enableTooltips(className){

  if(className==null) {
    className='caution_link';
  }

  AddCss();
  AddToolTip();

  $("."+className+" a").each(function(i) {
    Prepare(this);
  });

  $("."+className+" map area").each(function(i) {
    Prepare(this);
  });

}

function Prepare(el){
  el.onclick=showTooltip;
}

function showTooltip(e){
  var link=$("#btc a.link");
  var btc=$("#btc");
  
  if((link.attr("href") == this.href) && 
  (btc.css("display") == "block")){
    return true;
  }

  window.clearTimeout(hideTooltipTimeout);
  hideTooltip();
  
  link.attr("href",this.href);
  link.attr("target",this.target);

  Locate(e);
  btc.show("fast");

  hideTooltipTimeout = window.setTimeout(hideTooltip, 5000); 
  return false;
}

function hideTooltip(e){
  $("#btc").hide();
}

function setOpacity(el){
  var opacity = 80;
  el.css("filter","alpha(opacity:"+opacity+")");
  el.css("KHTMLOpacity","0."+opacity);
  el.css("MozOpacity","0."+opacity);
  el.css("opacity","0."+opacity);
}

function CreateEl(t,c,d){
  var x=$(document.createElement(t));
  if(c!=null && c.length != 0){
    x.addClass(c);
  }
  if(d!=null && d.length != 0){
    x.css("display",d);
  }
  return(x);
}

function AddCss(){
	var l=document.createElement("link");
	l.setAttribute("type","text/css");
	l.setAttribute("rel","stylesheet");
	l.setAttribute("href","https://www.chobirich.com/css/bt.css");
	l.setAttribute("media","screen");
	document.getElementsByTagName("head")[0].appendChild(l);
}

function Locate(e){
  var posx=0,posy=0;
  if(e==null) {
    e=window.event;
  }
  if(e.pageX || e.pageY){
	  posx=e.pageX; posy=e.pageY;
  }
  else if(e.clientX || e.clientY){
	  if(document.documentElement.scrollTop){
		  posx=e.clientX+document.documentElement.scrollLeft;
		  posy=e.clientY+document.documentElement.scrollTop;
	  }
	  else{
		  posx=e.clientX+document.body.scrollLeft;
		  posy=e.clientY+document.body.scrollTop;
	  }
  }
  $("#btc").css("top",(posy+10)+"px");
  $("#btc").css("left",(posx-20)+"px");
}

function AddToolTip(){
  var tooltip,bottom,top,regist,login,link,base;

  base=CreateEl("span","base","none");
  base.attr("id","btc");
  base.css("position","absolute");
  $(document.body).append(base);

  top=CreateEl("span","top","block");
  top.text("ログイン状態で広告を見ないと、ポイントは貯まりません。");

  tooltip=CreateEl("span","tooltip","block");
  tooltip.append(top);

  regist=CreateEl("a","regist","block");
  regist.attr("href","https://www.chobirich.com/regist/");
  regist.text("［今すぐ無料会員登録をしよう！］");

  login=CreateEl("a","login","block");
  login.attr("href","https://www.chobirich.com/member/");
  login.text("［ログインする］");

  link=CreateEl("a","link","block");
  link.text("何もせずに広告を見る");

  bottom=CreateEl("b","bottom","block");
  bottom.append(regist);
  bottom.append(login);
  bottom.append(link);
  tooltip.append(bottom);
  setOpacity(tooltip);

  base.append(tooltip);

}
