var __scrollBarControl = null;
var __divinnerHTML=null;
var __firstTime=true;
var __interval_id=null;
var __user_stop=false;
var __scrollBarControl2 = null;
var __divinnerHTML2=null;
var __firstTime2=true;
var __interval_id2=null;
var __user_stop2=false;
function innerBarProp(barID, width, height, interval, direction)
{
 this.barID = barID;
 this.width = width;
 this.height = height;
 this.interval = interval;
 this.direction = direction;
 this.stopScroll = false;
 this.maxValue = 0;
 this.preValue = 0;
 this.step=2;
}
function innerBarProp2(barID, width, height, interval, direction)
{
 this.barID = barID;
 this.width = width;
 this.height = height;
 this.interval = interval;
 this.direction = direction;
 this.stopScroll = false;
 this.maxValue = 0;
 this.preValue = 0;
 this.step=2;
}
function scrollBar()
{
 this.barsArray = new Array();
  //save current object
 __scrollBarControl = this;
}
function scrollBar2()
{
 this.barsArray = new Array();
  //save current object
 __scrollBarControl2 = this;
}
//////////////////////////////////////////////////////////////////
// add scrollbar to bar list and set properties
// parameters:
//     barID: HTML's tag <DIV>'s id property 
//              (for js access the DIV object)
//     width: define the scrollbar's width
//     height: define the scrollbar's height
//     interval: define the scroll speed 
//               ( scroll up/down per XX millinSecond )
//     direction: scroll direction's defined
//               "up"
//               "down"
//               "left"
//               "right"
//////////////////////////////////////////////////////////////////
scrollBar.prototype.addBar = function(barID, width, height, interval, direction)
{
 //check parameters
 var paraCount = arguments.length;
 if ( paraCount < 1 )
 {
  alert("parameters count incorect!");
  return;
  //throw "parameters count inccorect!";
 }
 
 //width's default value
 if ( typeof( width ) == "undefined" )
 {
  var width = 200;
 }
 
 //height's default value
 if ( typeof( height ) == "undefined" )
 {
  var height = 100;
 }
 
 //interval's default value
 if ( typeof( interval ) == "undefined" )
 {
  var interval = 1000;
 }
 
 //direction's default value
 if ( typeof( direction ) == "undefined" )
 {
  var direction = "up";
 }
 
 //create scrollbar's inner properties
 var barProp = new innerBarProp(barID, width, height, interval, direction);
 
 var objBar = document.getElementById(barID);
 if(__divinnerHTML!=null)
 objBar.innerHTML=__divinnerHTML;
else
 __divinnerHTML=objBar.innerHTML;
 var barCount = this.barsArray.length;
 this.barsArray[barCount] = barProp;
}
scrollBar2.prototype.addBar = function(barID, width, height, interval, direction)
{
 //check parameters
 var paraCount = arguments.length;
 if ( paraCount < 1 )
 {
  alert("parameters count incorect!");
  return;
  //throw "parameters count inccorect!";
 }
 
 //width's default value
 if ( typeof( width ) == "undefined" )
 {
  var width = 200;
 }
 
 //height's default value
 if ( typeof( height ) == "undefined" )
 {
  var height = 100;
 }
 
 //interval's default value
 if ( typeof( interval ) == "undefined" )
 {
  var interval = 1000;
 }
 
 //direction's default value
 if ( typeof( direction ) == "undefined" )
 {
  var direction = "up";
 }
 
 //create scrollbar's inner properties
 var barProp = new innerBarProp(barID, width, height, interval, direction);
 
 var objBar = document.getElementById(barID);
 if(__divinnerHTML2!=null)
 objBar.innerHTML=__divinnerHTML2;
else
 __divinnerHTML2=objBar.innerHTML;
 var barCount = this.barsArray.length;
 this.barsArray[barCount] = barProp;
}
scrollBar.prototype.clear = function()
{
 for(i=0;i<this.barsArray.length;i++)
  this.barsArray.pop();
}
scrollBar2.prototype.clear = function()
{
 for(i=0;i<this.barsArray.length;i++)
  this.barsArray.pop();
}
scrollBar.prototype.createScrollBars = function()
{
 //get bar's count
  var barCount = this.barsArray.length;
 //if no bar add to scrollControl do nothing
 if ( barCount == 0 )
 {
  return;
 }
 
 //init scroll bars
 for ( var i=0; i<barCount; i++ )
 {
  var objBarID = this.barsArray[i].barID;
  //if typeof objBarID is object
  // that's meaning it inited
  //if typeof objBarID is string
  // init that scroll bar
  if ( typeof( objBarID ) == "string" )
  {
   //get scroll <DIV> object
   var objBar = document.getElementById( objBarID );
   
   if (objBar == null)
   {
    //objBarID is not exist
    if ( document.readyState == "complete" || document.readyState == "loaded" )
    {
     //the objBarID not exists in current document
     //throw "the objBarID is not exists.";
     alert("ScrollBar[" + objBarID + "]: not exist!");
     return;
    }
    else
    {
     //wait for document to load objBarID
     window.setTimeout("__scrollBarControl.createScrollBars()",50);
     //exit processing..........
     //and wait next time callbak
     return;
    }
   }
   
   //update barID
   this.barsArray[i].barID = objBar;
  }
 }
 
 for ( var i=0; i<barCount; i++ )
 {
  this.innerInitBar(i);
 }
}
scrollBar2.prototype.createScrollBars = function()
{
 //get bar's count
  var barCount = this.barsArray.length;
 //if no bar add to scrollControl do nothing
 if ( barCount == 0 )
 {
  return;
 }
 
 //init scroll bars
 for ( var i=0; i<barCount; i++ )
 {
  var objBarID = this.barsArray[i].barID;
  //if typeof objBarID is object
  // that's meaning it inited
  //if typeof objBarID is string
  // init that scroll bar
  if ( typeof( objBarID ) == "string" )
  {
   //get scroll <DIV> object
   var objBar = document.getElementById( objBarID );
   
   if (objBar == null)
   {
    //objBarID is not exist
    if ( document.readyState == "complete" || document.readyState == "loaded" )
    {
     //the objBarID not exists in current document
     //throw "the objBarID is not exists.";
     alert("ScrollBar[" + objBarID + "]: not exist!");
     return;
    }
    else
    {
     //wait for document to load objBarID
     window.setTimeout("__scrollBarControl2.createScrollBars()",50);
     //exit processing..........
     //and wait next time callbak
     return;
    }
   }
   
   //update barID
   this.barsArray[i].barID = objBar;
  }
 }
 
 for ( var i=0; i<barCount; i++ )
 {
  this.innerInitBar(i);
 }
}
scrollBar.prototype.innerInitBar = function (index)
{ 
 //get properties
 var barID = this.barsArray[index].barID;
 var width = this.barsArray[index].width;
 var height = this.barsArray[index].height;
 var interval = this.barsArray[index].interval;
 var direction = this.barsArray[index].direction;
 var maxValue = 0;
 
 //set scrollBar's properties
 with(barID)
 {
  style.width = width;
  style.height = height;
  noWrap=true;
  switch( direction )
  {
   case "up":
    maxValue = Math.max(scrollHeight, height);
    style.overflowX = "visible";
    style.overflowY = "hidden";
    var barHtml = innerHTML;
    /*
    var newHtml = "<table border='0' cellspacing='0' cellpadding='0'>\n";
    newHtml += "  <tr>\n";
    newHtml += "    <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += "    </td>\n";
    newHtml += "  </tr>\n";
    newHtml += "  <tr>\n";
    newHtml += "    <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += "    </td>\n";
    newHtml += "  </tr>\n";
    newHtml += "</table>\n";
    */
    innerHTML = barHtml+barHtml;
    break;
   case "down":
    maxValue = Math.max(scrollHeight, height);
    style.overflowX = "visible";
    style.overflowY = "hidden";
    var barHtml = innerHTML;
    /*
    var newHtml = "<table border='0' cellspacing='0' cellpadding='0'>\n";
    newHtml += "  <tr>\n";
    newHtml += "    <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += "    </td>\n";
    newHtml += "  </tr>\n";
    newHtml += "  <tr>\n";
    newHtml += "    <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += "    </td>\n";
    newHtml += "  </tr>\n";
    newHtml += "</table>\n";
    */
    innerHTML = barHtml+barHtml;
    scrollTop = maxValue;
    break;
   case "left":
    maxValue = Math.max(scrollWidth, width);
    style.overflowX = "hidden";
    style.overflowY = "visible";
    var barHtml = barID.innerHTML;
    /*
    var newHtml = "<table border='0' cellspacing='0' cellpadding='0' width='" + (maxValue * 2 ) + "'>\n";
    newHtml += "  <tr>\n";
    newHtml += "    <td width='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += "    </td>\n";
    newHtml += "    <td width='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += "    </td>\n";
    newHtml += "  </tr>\n";
    newHtml += "</table>\n";
    */
    innerHTML = barHtml+barHtml;
    break;
   case "right":
    maxValue = Math.max(scrollWidth, width);
    style.overflowX = "hidden";
    style.overflowY = "visible";
    var barHtml = innerHTML;
    /*
    var newHtml = "<table border='0' cellspacing='0' cellpadding='0' width='" + (maxValue * 2 ) + "'>\n";
    newHtml += "  <tr>\n";
    newHtml += "    <td width='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += "    </td>\n";
    newHtml += "    <td width='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += "    </td>\n";
    newHtml += "  </tr>\n";
    newHtml += "</table>\n";
    */
    innerHTML = barHtml+barHtml;
    scrollLeft = maxValue;
    break;
   default:
    //throw "direction is inccorect!";
    alert("ScrollBar[" + id + "]: direction is incorect!");
    return;
  }
  
  //set mouse events
	  barID.onmouseover = new Function("__scrollBarControl.mouseEvt(" + index + ",true);");
	  barID.onmouseout = new Function("__scrollBarControl.mouseEvt(" + index + ",false);");
  if(__firstTime)
  {
 	__firstTime=false;
  __interval_id=window.setInterval("__scrollBarControl.scroll(" + index + ");",interval);
  }
  //save maxValue
  this.barsArray[index].maxValue = maxValue;
 }
}
scrollBar2.prototype.innerInitBar = function (index)
{ 
 //get properties
 var barID = this.barsArray[index].barID;
 var width = this.barsArray[index].width;
 var height = this.barsArray[index].height;
 var interval = this.barsArray[index].interval;
 var direction = this.barsArray[index].direction;
 var maxValue = 0;
 
 //set scrollBar's properties
 with(barID)
 {
  style.width = width;
  style.height = height;
  noWrap=true;
  switch( direction )
  {
   case "up":
    maxValue = Math.max(scrollHeight, height);
    style.overflowX = "visible";
    style.overflowY = "hidden";
    var barHtml = innerHTML;
    /*
    var newHtml = "<table border='0' cellspacing='0' cellpadding='0'>\n";
    newHtml += "  <tr>\n";
    newHtml += "    <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += "    </td>\n";
    newHtml += "  </tr>\n";
    newHtml += "  <tr>\n";
    newHtml += "    <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += "    </td>\n";
    newHtml += "  </tr>\n";
    newHtml += "</table>\n";
    */
    innerHTML = barHtml+barHtml;
    break;
   case "down":
    maxValue = Math.max(scrollHeight, height);
    style.overflowX = "visible";
    style.overflowY = "hidden";
    var barHtml = innerHTML;
    /*
    var newHtml = "<table border='0' cellspacing='0' cellpadding='0'>\n";
    newHtml += "  <tr>\n";
    newHtml += "    <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += "    </td>\n";
    newHtml += "  </tr>\n";
    newHtml += "  <tr>\n";
    newHtml += "    <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += "    </td>\n";
    newHtml += "  </tr>\n";
    newHtml += "</table>\n";
    */
    innerHTML = barHtml+barHtml;
    scrollTop = maxValue;
    break;
   case "left":
    maxValue = Math.max(scrollWidth, width);
    style.overflowX = "hidden";
    style.overflowY = "visible";
    var barHtml = barID.innerHTML;
    /*
    var newHtml = "<table border='0' cellspacing='0' cellpadding='0' width='" + (maxValue * 2 ) + "'>\n";
    newHtml += "  <tr>\n";
    newHtml += "    <td width='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += "    </td>\n";
    newHtml += "    <td width='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += "    </td>\n";
    newHtml += "  </tr>\n";
    newHtml += "</table>\n";
    */
    innerHTML = barHtml+barHtml;
    break;
   case "right":
    maxValue = Math.max(scrollWidth, width);
    style.overflowX = "hidden";
    style.overflowY = "visible";
    var barHtml = innerHTML;
    /*
    var newHtml = "<table border='0' cellspacing='0' cellpadding='0' width='" + (maxValue * 2 ) + "'>\n";
    newHtml += "  <tr>\n";
    newHtml += "    <td width='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += "    </td>\n";
    newHtml += "    <td width='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += "    </td>\n";
    newHtml += "  </tr>\n";
    newHtml += "</table>\n";
    */
    innerHTML = barHtml+barHtml;
    scrollLeft = maxValue;
    break;
   default:
    //throw "direction is inccorect!";
    alert("ScrollBar[" + id + "]: direction is incorect!");
    return;
  }
  
  //set mouse events
	  barID.onmouseover = new Function("__scrollBarControl2.mouseEvt(" + index + ",true);");
	  barID.onmouseout = new Function("__scrollBarControl2.mouseEvt(" + index + ",false);");
  if(__firstTime2)
  {
 	__firstTime2=false;
  __interval_id2=window.setInterval("__scrollBarControl2.scroll(" + index + ");",interval);
  }
  //save maxValue
  this.barsArray[index].maxValue = maxValue;
 }
}
scrollBar.prototype.mouseEvt = function(index, stop)
{
 this.barsArray[index].stopScroll = stop;
}
scrollBar2.prototype.mouseEvt = function(index, stop)
{
 this.barsArray[index].stopScroll = stop;
}
scrollBar.prototype.scroll = function(index)
{
 //get properties
 var barID = this.barsArray[index].barID;
 var width = this.barsArray[index].width;
 var height = this.barsArray[index].height;
 var interval = this.barsArray[index].interval;
 var direction = this.barsArray[index].direction;
 var stopScroll = this.barsArray[index].stopScroll;
 var preValue = this.barsArray[index].preValue;
 var maxValue = this.barsArray[index].maxValue;
 var astep = this.barsArray[index].step;
 
 if ( stopScroll == true || __user_stop == true) return;
 
 switch(direction)
 {
  case "up":
    preValue+=astep;
    if ( preValue >= maxValue )
    {
     preValue = 0;
    }
    barID.scrollTop = preValue;
    break;
  case "down":
    preValue-=astep;
    if ( preValue <= 0 )
    {
     preValue = maxValue;
    }
    barID.scrollTop = preValue;
    break;
  case "left":
    preValue++;
    if ( preValue >= maxValue )
    {
     preValue = 0;
    }
    barID.scrollLeft = preValue;
    break;
  case "right":
    preValue--;
    if ( preValue <=0 )
    {
     preValue = maxValue;
    }
    barID.scrollLeft = preValue;
    break;
 }
 this.barsArray[index].preValue = preValue;
}
scrollBar2.prototype.scroll = function(index)
{
 //get properties
 var barID = this.barsArray[index].barID;
 var width = this.barsArray[index].width;
 var height = this.barsArray[index].height;
 var interval = this.barsArray[index].interval;
 var direction = this.barsArray[index].direction;
 var stopScroll = this.barsArray[index].stopScroll;
 var preValue = this.barsArray[index].preValue;
 var maxValue = this.barsArray[index].maxValue;
 var astep = this.barsArray[index].step;
 
 if ( stopScroll == true || __user_stop2 == true) return;
 
 switch(direction)
 {
  case "up":
    preValue+=astep;
    if ( preValue >= maxValue )
    {
     preValue = 0;
    }
    barID.scrollTop = preValue;
    break;
  case "down":
    preValue-=astep;
    if ( preValue <= 0 )
    {
     preValue = maxValue;
    }
    barID.scrollTop = preValue;
    break;
  case "left":
    preValue++;
    if ( preValue >= maxValue )
    {
     preValue = 0;
    }
    barID.scrollLeft = preValue;
    break;
  case "right":
    preValue--;
    if ( preValue <=0 )
    {
     preValue = maxValue;
    }
    barID.scrollLeft = preValue;
    break;
 }
 this.barsArray[index].preValue = preValue;
}
function show_cloudpic(type,no,pic_num,eventObject){
	if(pic_num>0){
		var cf=document.getElementById("cloud_frame");
		var showpic = document.getElementById("showpic");
		cf.src='http://www.e-rent.com.tw/cloud_pic.php?object_type='+type+'&object_no='+no;
		showpic.style.left=eventObject.screenX-100;
		showpic.style.top=eventObject.screenY-280;
		showpic.style.visibility="visible";
	}
}

function hid_cloudpic()
{
	var showpic = document.getElementById("showpic");
  showpic.style.visibility="hidden";
}

function show_cloudpic2(type,no,pic_num,eventObject) {
	if(pic_num>0) {
		var cf=document.getElementById("cloud_frame");
		var showpic = document.getElementById("showpic");
		cf.src='http://www.e-rent.com.tw/cloud_pic.php?object_type='+type+'&object_no='+no;
		showpic.style.left=eventObject.screenX-100;
		showpic.style.top=eventObject.screenY-280;
		showpic.style.visibility="visible";
	}
}
function open_room_3D(num,arg)
{
	if(num==0) return true;
	if(num==1) {var x=360;var y=240;}
	if(num==2) {var x=540;var y=240;}
	if(num==3) {var x=760;var y=240;}
	window.open('http://www.e-rent.com.tw/frame4/Query_handle_3D.php3?room_num='+arg,'_blank','location=0,menubar=0,toolbar=0,scrollbars=1,personalbar=0,status=0,width='+x+',height='+y);
}
function open_building_3D(num,arg)
{
	if(num==0) return true;
	if(num==1) {var x=360;var y=240;}
	if(num==2) {var x=540;var y=240;}
	if(num==3) {var x=760;var y=240;}
	window.open('http://www.e-rent.com.tw/frame4/Query_handle_1_3D.php3?building_num='+arg,'_blank','location=0,menubar=0,toolbar=0,scrollbars=1,personalbar=0,status=0,width='+x+',height='+y);
}
function open_store_3D(num,arg)
{
	if(num==0) return true;
	if(num==1) {var x=360;var y=240;}
	if(num==2) {var x=540;var y=240;}
	if(num==3) {var x=760;var y=240;}
	window.open('http://www.e-rent.com.tw/frame4/store_3D.php3?no='+arg,'_blank','location=0,menubar=0,toolbar=0,scrollbars=1,personalbar=0,status=0,width='+x+',height='+y);
}
function open_park_3D(num,arg)
{
	if(num==0) return true;
	var x=360;
	var y=240;
	window.open('http://www.e-rent.com.tw/frame4/Park_Query_handle_3D.php3?no='+arg,'_blank','location=0,menubar=0,toolbar=0,scrollbars=1,personalbar=0,status=0,width='+x+',height='+y);
}
//=================end of file===========================
