function searchQueryAddressGugun(xml) {

   $('#gugun')[0].innerHTML=''; 
   $('#gugun')[0].options.add(new Option((typeof(gugunTitle)!='undefined' ? gugunTitle : '2차 지역'), ''));
   $(xml).find('address').each(function(i) { 
	$('#gugun')[0].options.add(new Option($(this).attr('gugun'), $(this).attr('gugun')));
	if(gugun&&(gugun==$(this).attr('gugun'))) $('#gugun')[0].options[i+1].selected = 'selected';
   }); 

}

function searchQueryAddressGugun2(xml) {

   $('#gugun2')[0].innerHTML=''; 
   $('#gugun2')[0].options.add(new Option((typeof(gugun2Title)!='undefined' ? gugun2Title : '2차 지역'), ''));
   $(xml).find('address').each(function(i) { 
	$('#gugun2')[0].options.add(new Option($(this).attr('gugun'), $(this).attr('gugun')));
	if(gugun2&&(gugun2==$(this).attr('gugun'))) $('#gugun2')[0].options[i+1].selected = 'selected';
   }); 

}

// 롤링 시작
function changeLayer(obj, length, moveLength, direction, setTime) {

   var This = this;

   this.obj = obj;
   this.length = length;
   this.moveLength = moveLength;
   this.direction = direction;
   this.setTime = setTime;
   this.timer = null;

   this.obj.onmouseover = function () {

      if (This.setTime) window.clearInterval(This.timer);

   }

   this.obj.onmouseout = function () {

      if (This.setTime) This.timer = window.setInterval(function () { eval("This.move" + ((This.direction=="prev")?"Prev":"Next") + "();"); } , This.setTime);

   }

   if ((direction=="prev")&&moveLength&&setTime) this.movePrev();
   if ((direction=="next")&&moveLength&&setTime) this.moveNext();

}


changeLayer.prototype.getFirstChild = function(obj) {   

   var fObj = obj.firstChild;   

   while (fObj.nodeType!=1) fObj = fObj.nextSibling;     

   return fObj;   

}


changeLayer.prototype.getLastChild = function(obj) {   

   var lObj = obj.lastChild;   

   while (lObj.nodeType!=1) lObj = lObj.previousSibling;   
  
   return lObj;   

}


changeLayer.prototype.movePrev = function() {   
   
   var This = this;

   if (this.length>this.moveLength) {   

    if ((this.setTime&&this.timer)||(!this.setTime&&!this.timer)) {

     var saveObj = this.getLastChild(this.obj);   
     this.obj.removeChild(this.getLastChild(this.obj));   
     this.obj.insertBefore(saveObj, this.getFirstChild(this.obj));   

	}

   }  
   
   if (this.setTime&&(this.timer==null)) this.timer = window.setInterval(function () { This.movePrev(); } , this.setTime);

}   


changeLayer.prototype.moveNext = function() {   
     
   var This = this;

   if (this.length>this.moveLength) {   

    if ((this.setTime&&this.timer)||(!this.setTime&&!this.timer)) {

     var saveObj = this.getFirstChild(this.obj);   
     this.obj.removeChild(this.getFirstChild(this.obj));   
     this.obj.appendChild(saveObj);   

	}

   }

   if (this.setTime&&(this.timer==null)) this.timer = window.setInterval(function () { This.moveNext(); } , this.setTime);
   
}  

// 롤링 끝





// 탭 레이어를 만든다.
function changeTabLayer(layerId, viewNo, maxNo, opacityType) {

	for (var i=1; i<=maxNo; i++) {

	 var obj = document.getElementById(layerId + "Tab" +  i);
	 var obj2 = document.getElementById(layerId + "Contents" +  i);

     var arrImgFileExtName = obj.src.split(".");
	 var imgFileExtName = arrImgFileExtName[arrImgFileExtName.length-1];

     if (i==viewNo) {

      if (obj2.style.display=="none") {

 	   obj.src = obj.src.replace("." + imgFileExtName, "_over." + imgFileExtName);
 	   obj2.style.display = "block";

	   if (opacityType) initOpacity(layerId + "Contents" +  i, 0, 100, 300);

	  }

	 } else {

	  obj.src = obj.src.replace("_over." + imgFileExtName, "." + imgFileExtName);
	  obj2.style.display = "none";

     }
	
	}

}


// 레이어에 투명 효과를 준다. <시작>
function initOpacity(layerId, opacityStart, opacityEnd, sec) {

   var speed = Math.round(sec/100);
   var timer = 0;

   if (opacityStart>opacityEnd) {

	for (var i=opacityStart; i>=opacityEnd; i--) {

 	 setTimeout("setOpacity('" + layerId + "', " + i + ")", timer*speed);
	 timer ++;

	}

   } else if (opacityStart<opacityEnd) {

	for (var i=opacityStart; i<=opacityEnd; i++) {

  	 setTimeout("setOpacity('" + layerId + "', " + i + ")" , timer*speed);
	 timer ++;

	}

   }

}


function setOpacity(layerId, opacity) {

   var obj = document.getElementById(layerId); 

   if (agent.IE7) obj.style.filter = "alpha(opacity=" + opacity + ")"; else obj.style.opacity = opacity / 100;

}
// 레이어에 투명 효과를 준다. <끝>






// 움직이는 롤링



function rolling(obj, direction, value, value2, speed, movePx, delay, isStop) { 

  var This = this; 

  this.direction = direction;
  if (direction=="horizon") this.height = value; else this.width = value;
  this.speed = speed; 
  this.movePx = movePx; 
  this.delay = delay; 
  this.countMovePx = 0; 
  this.timerDelay = null;
  this.timerSpeed = null;
  this.isStop = isStop;

  this.obj = obj; 
  this.obj.isRolling = false; 
  this.obj.scrollTop = 0; 
  this.obj.style.marginLeft = "0px"; 
  this.obj.horizonWidth = value2 * 2; 
  this.obj.innerHTML= this.obj.innerHTML + this.obj.innerHTML; 
  this.obj.onmouseover = function() { this.isRolling = true; } 
  this.obj.onmouseout = function() { this.isRolling = false; } 

  if (!isStop) window.setTimeout(function() { This.start(); }, this.delay); 

} 


rolling.prototype.start = function() { 

   var This = this; 

   if (!this.obj.isRolling) { 

    if (this.direction=="horizon") {

     this.obj.scrollTop += this.movePx; 

     if (this.obj.scrollTop>(this.obj.scrollHeight/2)) this.obj.scrollTop = 0; 
     else { 

      this.countMovePx += this.movePx; 

      if (this.countMovePx>=this.height) { 

       if ((this.countMovePx>this.height)||((this.obj.scrollTop%this.height)!=0)) this.obj.scrollTop -= this.countMovePx%this.height;      
       this.countMovePx = 0; 
       this.timerDelay = window.setTimeout(function() { This.start(); }, this.delay); 
       return; 

      }
	 
     }

	} else { 

     this.obj.style.marginLeft = (parseInt(this.obj.style.marginLeft)-this.movePx) + "px"; 

     if ((parseInt(this.obj.style.marginLeft)*-1)>(this.obj.horizonWidth/2)) this.obj.style.marginLeft = 0 + "px"; 
     else { 

      this.countMovePx += this.movePx; 

      if (this.countMovePx>=this.width) { 

       if ((this.countMovePx>this.width)||((parseInt(this.obj.style.marginLeft)%this.width)!=0)) this.obj.style.marginLeft = (this.obj.style.marginLeft-(this.countMovePx%this.width)) + "px";      
       this.countMovePx = 0; 
       this.timerDelay = window.setTimeout(function() { This.start(); }, this.delay); 
       return; 

      }
	 
     }

    }
	
   }

   this.timerSpeed = window.setTimeout(function() { This.start(); }, this.speed); 

}


rolling.prototype.movePrev = function() { 
  
   var This = this;

   if (this.timerDelay) clearTimeout(this.timerDelay);
   if (this.timerSpeed) clearTimeout(this.timerSpeed);
   
   if (this.direction=="vertical") {

    this.obj.scrollTop -= this.countMovePx%this.height;  
    if (this.obj.scrollTop==0) this.obj.scrollTop = this.obj.scrollHeight/2; 
    this.obj.scrollTop -= this.height; 
    this.countMovePx = 0; 

   } else {

    this.obj.style.marginLeft = (parseInt(this.obj.style.marginLeft)+(this.countMovePx%this.width)) + "px"; 
    if (parseInt(this.obj.style.marginLeft)==0) this.obj.style.marginLeft = ((this.obj.horizonWidth/2)*-1) + "px"; 
    this.obj.style.marginLeft = (parseInt(this.obj.style.marginLeft)+this.width) + "px"; 
    this.countMovePx = 0; 

   }

   if (!this.isStop) this.timerDelay = window.setTimeout(function() { This.start(); }, this.delay); 

}


rolling.prototype.moveNext = function() { 

   var This = this;

   if (this.timerDelay) clearTimeout(this.timerDelay);
   if (this.timerSpeed) clearTimeout(this.timerSpeed);

   if (this.direction=="vertical") {

    this.obj.scrollTop -= this.countMovePx%this.height;  
    if (this.obj.scrollTop==(this.obj.scrollHeight/2)) this.obj.scrollTop = 0; 
    this.obj.scrollTop += this.height; 
    this.countMovePx = 0; 

   } else {

    this.obj.style.marginLeft = (parseInt(this.obj.style.marginLeft)+(this.countMovePx%this.width)) + "px"; 
    if ((parseInt(this.obj.style.marginLeft)*-1)>(this.obj.horizonWidth/2)) this.obj.style.marginLeft = 0 + "px"; 
    this.obj.style.marginLeft = (parseInt(this.obj.style.marginLeft)-this.width) + "px"; 	
    this.countMovePx = 0; 

   }

   if (!this.isStop) this.timerDelay = window.setTimeout(function() { This.start(); }, this.delay); 

}  



