/********************************************************************************************************
	Å¸ÀÌÆ²¹Ù ÅØ½ºÆ® º¯°æ
********************************************************************************************************/



/********************************************************************************************************
	alt ÀÌ¹ÌÁö ¿Â/¿ÀÇÁ
********************************************************************************************************/
function setAlt(_id) {
	try { 

		if( document.getElementById(_id) != null ) {
			var altObj = document.getElementById(_id);
			var x = event.x;
			var y = event.y;
			var top;
			var left;
	/*
			var positionM = document.getElementById("positionMouse");
			var txt = "x : " + x + ", y :" + y;
			positionM.innerHTML = txt;
	*/
			if( 9 <= y && y <= 36 ) {
				// ¿ìÃø 5¹øÂ°
				if( 541 < x && x <= 568 ) {
					top = -20;
					left = 465;
				}
				// ¿ìÃø 4¹øÂ°
				if( 572 < x && x <= 599 ) {
					top = -20;
					left = 498;
				}
				// ¿ìÃø 3¹øÂ°
				if( 603 < x && x <= 630 ) {
					top = -20;
					left = 529;
				}
				// ¿ìÃø 2¹øÂ°
				if( 634 < x && x <= 661 ) {
					top = -20;
					left = 560;
				}
				// ¿ìÃø 1¹øÂ°
				if( 665 < x && x <= 692 ) {
					top = -20;
					left = 590;
				}
			}
	
			if ( window.navigator.userAgent.indexOf("MSIE 6") != -1 ) {
	//			left = left - 570;
			}
	
			if( altObj.style.display == "none" ) {
				altObj.style.display = "block";
				altObj.style.top = top + "px";
				altObj.style.left = left + "px";
				
			} else {
				altObj.style.display = "none";
			}
		} // if
		
	} catch (e) {
	}
	
}


/********************************************************************************************************
	ÀÌ¹ÌÁö ¿À¹ö/¾Æ¿ô
********************************************************************************************************/
function setIMG(thisImg, sMode) {
	var sPath = thisImg.src;
	var sCommonPath = sPath.substring(0, sPath.lastIndexOf("_") + 1);
	var sType = sPath.substring(sPath.lastIndexOf("."), sPath.length);
	//alert(sCommonPath + "on" + sType);
	thisImg.src = sCommonPath + sMode + sType;
}


/********************************************************************************************************
	ÀÌ¹ÌÁö ¸®»çÀÌÁî
********************************************************************************************************/
function resizeImg(_id, _sizeX, _sizeY) {
	var ul = document.getElementById(_id);
	var imgs = new Array();

	/* list page */
	if( ul.tagName == "UL" ) {
		
		var lis = ul.childNodes;
		
		for( var i=0; i < lis.length; i++ ) {
			var _div = lis[i].getElementsByTagName("div")[0];
			imgs[imgs.length] = _div.getElementsByTagName("img")[0];
		}
	
		for(var i = 0; i < imgs.length; i++) {
		    if(imgs[i].height <= _sizeY)
		        continue;
		
		    imgs[i].width = Math.round(imgs[i].width * _sizeY / imgs[i].height);
		    imgs[i].height = _sizeY;
		}

		for(var i = 0; i < imgs.length; i++) {
		    if(imgs[i].width <= _sizeX)
		        continue;
		
		    imgs[i].height = Math.round(imgs[i].height * _sizeX / imgs[i].width);
		    imgs[i].width = _sizeX;
		}
		
	} else {	/* view page */
		imgs = document.getElementById(_id).getElementsByTagName('img');

		for(var i = 0; i < imgs.length; i++) {
		    if(imgs[i].width <= _sizeX)
		        continue;
		
		    imgs[i].height = Math.round(imgs[i].height * _sizeX / imgs[i].width);
		    imgs[i].width = _sizeX;
		}
	}
	
	
}


/********************************************************************************************************
	µ¡±Û ¸®½ºÆ® ¿Â/¿ÀÇÁ
********************************************************************************************************/
function subComments(_id) {
	try {
		var list_id = "list_comments_" + _id;
		var selectedComment = document.getElementById(list_id);
		if( selectedComment.style.display != "none" ) {
			selectedComment.style.display = "none";
		} else {
			selectedComment.style.display = "block";
		}
	} catch(e) {
	}
}


/********************************************************************************************************
	ÆäÀÌÁö³» ÆË¾÷ Ã£±â
********************************************************************************************************/
function findPopUps() {
	var popups = document.getElementsByTagName("a");
	
	for( i=0; i<popups.length; i++ ) {
		popups[i].onfocus = function() {
			this.blur();
		}
		if( popups[i].rel.indexOf("popup") != -1 ) {
			// attach popup behavior
			popups[i].onclick = popups[i].onkeypress = doPopUp;
		}
	}
}

function doPopUp(e) {
	popupOpen(this.href);

	if( window.event ) {
		window.event.returnValue = false;
		window.event.cancelBubble = true;
	} else if( e ) {
		e.stopPropagation();
		e.preventDefault();
	}
}

/********************************************************************************************************
	rel="popup"À¸·Î ÀÌº¥Æ® Ãß°¡
********************************************************************************************************/
function addEvent(elm, evType, fn, useCapture) {   
    if( elm.addEventListener ) {   
        elm.addEventListener(evType, fn, useCapture);   
        return true;   
    } else if ( elm.attachEvent ) {   
        var r = elm.attachEvent('on' + evType, fn);   
        return r;   
    } else {   
        elm['on' + evType] = fn;   
    }   
}   


// ÆË¾÷Ã¢ Ã£±â ÀÌº¥Æ® Ãß°¡ **************************************
addEvent(window, 'load', findPopUps, false);


/********************************************************************************************************
	ÆË¾÷Ã¢ ¿ÀÇÂ
********************************************************************************************************/
function popupOpen(url) {
	var positionX = 0;
	var positionY = 0;
//	var positionX = (screen.width-450)/2;
//	var positionY = (screen.height-250)/2;
	// FireFoxÀÏ °æ¿ì
	if ( window.navigator.userAgent.indexOf("Firefox") != -1 ) {
		window.open(url,"","left="+positionX+",top="+positionY+",width=500,height=500,menubar=no,location=no,resizable=no,scrollbars=yes,status=no" );
	}
	
	// IE 6, 7 ÀÏ °æ¿ì
	if ( window.navigator.userAgent.indexOf("MSIE 6") != -1 || window.navigator.userAgent.indexOf("MSIE 7") != -1 ) {
		window.open(url,"","left="+positionX+",top="+positionY+",width=500,height=500,menubar=no,location=no,resizable=no,scrollbars=no,status=no" );
	}
}

// ÆË¾÷Ã¢ ¸®»çÀÌÁî **************************************
function popupResize() {
	// FireFoxÀÏ °æ¿ì
	if ( window.navigator.userAgent.indexOf("Firefox") != -1 ) {
		popFF();
	}
	
	// IE 6, 7 ÀÏ °æ¿ì
	if ( window.navigator.userAgent.indexOf("MSIE 6") != -1 || window.navigator.userAgent.indexOf("MSIE 7") != -1 ) {
		popIE();
	}
}

function popFF() {
	var thisX = document.getElementById("offsetPopup").offsetWidth;
	var thisY = document.getElementById("offsetPopup").offsetHeight;
	
	var maxThisX = screen.width - 50;
	var maxThisY = screen.height - 80;
	
	// Å¬¶óÀÌ¾ðÆ® width, height¸¦ Á¦¿ÜÇÑ FrameÀÇ °ªÀ» Ãß°¡ÇØÁà¾ß Á¦´ë·Î Ç¥ÇöµÊ.
	var marginY = 50;
	var marginX = 6;

/*	°¡·Î·Î ±æ¾îÁú °æ¿ì
	if( thisX > maxThisX ) {
		window.scrollbars.visible = true;
		thisX = maxThisX;
	} else {
		window.scrollbars.visible = false;
//		document.getElementsByTagName("body")[0].style.overflow = "hidden";
	}
*/
	
	if( thisY > maxThisY - marginY ) {
		window.scrollbars.visible = true;
		
		thisX += 16;
		thisY = maxThisY - marginY;
	} else {
		window.scrollbars.visible = false;
	}
	
	window.resizeTo( thisX+marginX, thisY+marginY );
}

function popIE() {
	var thisX = document.getElementById("offsetPopup").offsetWidth;
	var thisY = document.getElementById("offsetPopup").offsetHeight;
	
	var maxThisX = screen.width - 50;
	var maxThisY = screen.height - 80;

	if ( window.navigator.userAgent.indexOf("MSIE 6") != -1 ) { // 6.0
		var marginY = 49; //
		var marginX = 10;

	} else if ( window.navigator.userAgent.indexOf("MSIE 7") != -1 ) {	// 7.0
		var marginY = 71;	//
		var marginX = 10;
	}
	
/*	°¡·Î·Î ±æ¾îÁú °æ¿ì
	if( thisX > maxThisX ) {
		window.document.body.scroll = "yes";
		thisX = maxThisX;
	} else {
		window.document.body.scroll = "no";
	}
*/
	
	if( thisY > maxThisY - marginY ) {
		window.document.body.scroll = "yes";
		thisX += 16;
		thisY = maxThisY - marginY;
	} else {
		window.document.body.scroll = "no";
	}
	
	window.resizeTo( thisX+marginX, thisY+marginY );
}
