////
// 設定
//
// @syntax oj = dragableFloat("DIVのID名",初期位置X,初期位置Y)
//
// @sample              div1 = dragableFloat("aaa",100,200) //生成
// @sample              div1.innerHTML="あいうえお"         //HTMLを挿入
// @sample              div1.style.backgroundColor='orange' //CSSで修飾
// @sample              doDragableFloat()                   //開始
//

//読み込み時に実行
window.onload = function (){
	var br_width = getBrowserWidth()
	var flash_width = 900

	if((br_width - flash_width) >= 0){
		// ブラウザ枠よりFlash領域が広い場合
		window.bn_pos = ((br_width - flash_width) / 2)	//Flashの左上を始点
		//右初期値調整
		window.bn_pos = window.bn_pos + 650
	}else{
		// ブラウザ枠よりFlash領域が狭い場合
		window.bn_pos = br_width - 250
		if(window.bn_pos < 0){
			window.bn_pos = 0
		}
	}
	setDragableFloat() //設定
}

function setDragableFloat(){

	//ドラッガブルフロートDIVを生成
	div1 = dragableFloat("float_btn",bn_pos,148)
	
	//HTMLを挿入
	div1.innerHTML="<div style=\"background-image:url(" + img_path + "); width:230px;height:150px;\"><a class=\"siryo\" href=\"javascript:siryoWin();\"></a><a class=\"yoyaku\" href=\"javascript:raijyouWin();\"></a><a class=\"close\" href=\"javascript:CloseBtn();\"></a></div>"

	//CSSで修飾
	div1.style.width = "230px"
	div1.style.height = "150px"

	//開始
	setOpacity('float_btn',0)
	doDragableFloat()
	setTimeout('fadeOpacity(\'float_btn\',1)',100)
}
//====================================================
function siryoWin(){
	window.open("http://www.sumitomo-rd.co.jp/mansion/shuto/chigasaki/catalog.cgi","window1","resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,directories=no,status=no,location=yes,width=760");
}

function raijyouWin(){
	window.open("http://www.sumitomo-rd.co.jp/mansion/su-my_club/reservation_kiyaku.cgi?AREA_CD=shuto&PROP_CD=chigasaki","window2","resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,directories=no,status=no,location=yes,width=760");
}

function CloseBtn(){
	fadeOpacity('float_btn',-1)
	//0.5秒後にCloseMoveを再実行
	setTimeout('CloseMove()',500)
}
function CloseMove(){
	document.getElementById('float_btn').innerHTML = '';
}

//====================================================

  //--フェイド関数
  function fadeOpacity(layName,swt,stopOpacity){
    
    if(!window.fadeOpacity[layName]) //カウンター初期化
      fadeOpacity[layName] =0 

    //フェイドスイッチ引数省略時初期値(不透明から透明へ)
    if(!arguments[1]) swt = -1
  
    //引数swtが -1 なら不透明から透明へ
    //           1 なら透明から不透明へフェイドする
    if(swt==-1)        var f  = "9876543210"
    else if(swt==1)    var f  = "0123456789"
    else               var f  = "9876543210"
  
    //停止不透明度引数省略時初期値
    if(!arguments[2] && swt==-1)     stopOpacity = 0
    else if(!arguments[2] && swt==1) stopOpacity = 10

    //フェイド処理    
    if( fadeOpacity[layName] < f.length-1 ){
  
      //カウンター番目の文字列を取り出す
      var opa = f.charAt(fadeOpacity[layName])/10

      //終了時不透明度なら終了
      if( opa == stopOpacity ){
        setOpacity(layName,stopOpacity)  //終了
        fadeOpacity[layName] = 0     //リセット
        return
      }
      // 不透明度変更を実行する
      setOpacity(layName,opa)
      // カウンターを加算
      fadeOpacity[layName]++
      //--50/1000秒後にfadeOpacityを再実行
      setTimeout('fadeOpacity("'+layName+'","'+swt+'","'+stopOpacity+'")',50)
    } else {
      //終了
      setOpacity(layName,stopOpacity)
      //--リセット
      fadeOpacity[layName] = 0
    }
  }
  function setOpacity(layName,arg) {
    //arg は 0透明 1不透明
    //n4やmac-e4などopacity未対応は0以下で代替処理としてhiddenする
    var ua = navigator.userAgent

    if( window.opera ) return          //o6,o7
    if( document.layers )              //n4
           var oj = document.layers[layName]
    else if( document.all )            //e4,e5,e6
           var oj = document.all(layName).style
    else if( document.getElementById ) //n6,n7,m1,s1
           var oj =document.getElementById(layName).style

    if(document.layers ||
       ua.indexOf('Mac_PowerPC') !=-1 && document.all ||
       ua.indexOf('Safari') !=-1 ) {   //n4,mac-e4,mac-e5,s1
        //opacityの使えないブラウザ用代替処理
        if(arg>0)       oj.visibility='visible'
        else if(arg<=0) oj.visibility='hidden'
    } else if(document.all) {          //win-e4,win-e5,win-e6
        document.all(layName).style.filter="alpha(opacity=0)"
        document.all(layName).filters.alpha.Opacity  = (arg * 100)
    } else if(ua.indexOf('Gecko')!=-1) //n6,n7,m1
        document.getElementById(layName).style.MozOpacity = arg
  }

//---追加

function getBrowserWidth(){
	if(window.innerWidth){return window.innerWidth;}
	else if(document.documentElement && document.documentElement.clientWidth !=0){return document.documentElement.clientWidth;}
	else if(document.body){return document.body.clientWidth;}
	return 0;
}