/*
 *************************************************************************
 * @source  : imgbutton.htc
 * @desc    : Included htc Page
 *------------------------------------------------------------------------
 * VER  DATE         AUTHOR      DESCRIPTION
 * ---  -----------  ----------  -----------------------------------------------
 * 1.0  2007.01.05   김학철               최초작성
 * ----------- ----------  -----------------------------------------------
 * Hi-Tech표준 Framework 구축
 * Copyright 2012 HiTech,  All rights reserved.
 *************************************************************************
 */

<PUBLIC:COMPONENT lightWeight=true >
<PUBLIC:ATTACH EVENT="oncontentready" ONEVENT="initialize()" />
<PUBLIC:ATTACH EVENT="onmousedown" ONEVENT="ib_mouse_down()" />
<PUBLIC:ATTACH EVENT="onmouseup" ONEVENT="ib_mouse_up()" />
<PUBLIC:ATTACH EVENT="onmouseover" ONEVENT="ib_mouse_over()" />
<PUBLIC:ATTACH EVENT="onmouseout" ONEVENT="ib_mouse_out()" />
<PUBLIC:ATTACH EVENT="onclick" ONEVENT="ib_click()" />

<SCRIPT LANGUAGE="JScript">

////////////////////////////////////////////////////////////////////////////////////////////////
///
///   htc (behavior) event handling
///
////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////
// : htc.initialize()
// �� �� Ʈ : htc.ondocumentready
// ���ü : htc ��ü(this)
// �Ķ���� : N/A
// �� �� �� : N/A
// ��    �� : htc�� �ʱ�ȭ�� �����Ѵ�.
// �� �� �� : TK Shin / Since xMenuFulldowno v1.0
//////////////////////////////////////////////////////////
function initialize() {
	if (element.tagName != "IMG" ) { return;	}
	if (this.getAttribute("src"))      this.normalImg  = getCachedImage(this.getAttribute("src"));
	if (this.getAttribute("src_over")) this.hilightImg = getCachedImage(this.getAttribute("src_over"));
	if (this.getAttribute("src_down")) this.downImg    = getCachedImage(this.getAttribute("src_down"));
  if (this.getAttribute("disable") != null) disable = true;
  element.setEnable = set_enable;
	this.toggleCss = toggleCss;
  this.toggleCss("xiButtonNormal");
}

//////////////////////////////////////////////////////////
// : htc.ib_mouse_over()
// �̺�Ʈ�� : htc.onmouseover
// ���ü : htc ��ü(this)
// �Ķ���� : N/A
// �� �� �� : N/A
// ��    �� : element�� onmouseover�ÿ� element�� CSS�� �����Ѵ�.
// �� �� �� : TK Shin / Since xImageButton v1.0 build 100
//////////////////////////////////////////////////////////
function ib_mouse_over() {
  if (element.disable) return;
  this.toggleCss("xiButtonHilite", "xiButtonNormal", "xiButtonDown");
  if (this.hilightImg) this.src = this.hilightImg.src;
}

//////////////////////////////////////////////////////////
// : htc.ib_mouse_out()
// �̺�Ʈ�� : htc.onmouseout
// ���ü : htc ��ü(this)
// �Ķ���� : N/A
// �� �� �� : N/A
// ��    �� : element�� onmouseover�ÿ� element�� CSS�� �����Ѵ�.
// �� �� �� : TK Shin / Since xImageButton v1.0 build 100
//////////////////////////////////////////////////////////
function ib_mouse_out() {
  if (element.disable) return;
  this.toggleCss("xiButtonNormal", "xiButtonHilite" , "xiButtonDown");
  if (this.hilightImg) this.src = this.normalImg.src;
}

//////////////////////////////////////////////////////////
// : htc.ib_mouse_down()
// �̺�Ʈ�� : htc.onmousedown
// ���ü : htc ��ü(this)
// �Ķ���� : N/A
// �� �� �� : N/A
// ��    �� : element�� onmouseover�ÿ� element�� CSS�� �����Ѵ�.
// �� �� �� : TK Shin / Since xImageButton v1.0 build 100
//////////////////////////////////////////////////////////
function ib_mouse_down() {
  if (element.disable) return;
  this.toggleCss("xiButtonDown", "xiButtonHilite", "xiButtonDown");
  if (this.downImg) this.src = this.downImg.src;
}

//////////////////////////////////////////////////////////
// : htc.ib_mouse_up()
// �̺�Ʈ�� : htc.onmouseup
// ���ü : htc ��ü(this)
// �Ķ���� : N/A
// �� �� �� : N/A
// ��    �� : element�� onmouseover�ÿ� element�� CSS�� �����Ѵ�.
// �� �� �� : TK Shin / Since xImageButton v1.0 build 100
//////////////////////////////////////////////////////////
function ib_mouse_up() {
  if (element.disable) return;
  this.toggleCss("xiButtonHilite", "xiButtonNormal", "xiButtonDown");
  if (this.hilightImg) this.src = this.hilightImg.src;
}

//////////////////////////////////////////////////////////
// : htc.ib_click()
// �̺�Ʈ�� : element.onclick
// ���ü : htc ��ü(this)
// �Ķ���� : N/A
// �� �� �� : N/A
// ��    �� : ������ �Լ�(doAction/doAnchor)�� ȣ���Ѵ�.
// �� �� �� : TK Shin / Since xImageButton v1.0 build 100
//////////////////////////////////////////////////////////
function ib_click() {
  var flag = true;
  if (element.disable) return;
  if (this.getAttribute("action")) flag = doAction(this.getAttribute("action"));
	if (flag && this.getAttribute("href") && (this.getAttribute("href") != this.getAttribute("src"))) doAnchor(this.getAttribute("href"), this.getAttribute("target"));
}

//////////////////////////////////////////////////////////
// : htc.doAction()
// �̺�Ʈ�� : N/A
// ���ü : htc ��ü(this)
// �Ķ���� : String - execCmd (������ javascript ����)
// �� �� �� : N/A
// ��    �� : Submenu�� �����ۿ��� Mouse ��ư�� ���� ��� ��� Submenu�� �����.
//            Submenu�� �����ȿ��� mouse ��ư�� ���� ��� ������ �Լ�(doAction/doAnchor)�� ȣ���Ѵ�.
// �� �� �� : TK Shin / Since xImageButton v1.0 build 100
//////////////////////////////////////////////////////////
function doAction(execCmd) { 
 execCmd = execCmd.replace(/document\./g, "element.document.");
 execCmd = execCmd.replace(/this\./g, "element.");
 var temp = new Function(execCmd);
 var flag = temp();
 delete temp;
 return flag;
}
//////////////////////////////////////////////////////////
// : htc.doAnchor()
// �̺�Ʈ�� : N/A
// ���ü : htc ��ü(this)
// �Ķ���� : String - href (anchor���� ����� href)
//            String - target (anchor���� ����� target)
// �� �� �� : N/A
// ��    �� : ��ο� Anchor Node�� ����� href�� target; ������ ��= �����Ѵ�.
// �� �� �� : TK Shin / Since xImageButton v1.0 build 100
//////////////////////////////////////////////////////////
function doAnchor(href, target) {
  var oAnchor = element.document.createElement("A");
  oAnchor.href = href;
  if (target) oAnchor.target = target;
  element.document.body.insertBefore(oAnchor);
  oAnchor.click();
  delete oAnchor;
}

////////////////////////////////////////////////////////////////////////////////////////////////
///
///   htc (behavior) service method
///
////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
// : element.setEnable(flag)
// �̺�Ʈ�� : N/A
// ���ü : element ��ü(this) 
// �Ķ���� : boolean - flag (true�̸� enable, false�̸� disable)
// �� �� �� : N/A
// ��    �� : 
// �� �� �� : TK Shin / Since xImageButton v1.0 build 100
//////////////////////////////////////////////////////////
function set_enable(flag) {
  element.disable = !flag;
}

////////////////////////////////////////////////////////////////////////////////////////////////
///
///   htc (behavior) utility function
///
////////////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////
// : htc.cachedImage()
// �̺�Ʈ�� : N/A
// ���ü : htc ��ü(this)
// �Ķ���� : String - imgSrc (ĳ���� Image ��ü�� src value)
// �� �� �� : Image ��ü
// ��    �� : �־��� imgSrc�� �ش��ϴ� Image ��ü�� ����� �����Ѵ�.
// �� �� �� : TK Shin / Since xImageButton v1.0 build 100
//////////////////////////////////////////////////////////
function getCachedImage(imgSrc) {
	var ci  = new Image;
	ci.src = imgSrc;
	return ci;
}

//////////////////////////////////////////////////////////
// : htc.toggleCss() / submenu.item.isAttribute()
// �̺�Ʈ�� : N/A
// ���ü : htc ��ü(this) /  submenu.item ��ü (this)
// �Ķ���� : String - insert (������ CSS Class Name)
//            String - remove1 (��f�� CSS Class Name)
//            String - remove2 (��f�� CSS Class Name)
// �� �� �� : Object ()
// ��    �� : ���ü�� insert�� ��d�� CSS class�� �����ϰ� remove�� ��d�� CSS�� f���Ѵ�.
// �� �� �� : TK Shin / Since xImageButton v1.0 build 100
//////////////////////////////////////////////////////////
function toggleCss(insert, remove1, remove2) {

  if (!this.getAttribute("className") ) {
    this.setAttribute("className", insert);
    return;
  }

  var classArr = this.getAttribute("className").split(" ");
  var newClassArr = new Array;

  for ( var idx=0; idx<classArr.length; idx++ ) {
    if ( classArr[idx] != remove1 && classArr[idx] != remove2 ) newClassArr[newClassArr.length] = classArr[idx];
  }

  newClassArr[newClassArr.length] = insert;

  this.setAttribute("className", newClassArr.join(" "));
  delete newClassArr;
}

</SCRIPT>
</PUBLIC:COMPONENT>