<!--
/**
 * ÀÌ¹ÌÁöÀÇ ÆøÀ» º¯°æ½ÃÅ²´Ù.
 * oImage : image Object (required)
 * nWidth : ±âÁØ ³ÐÀÌ (required)
 * nHeight : ±âÁØ ³ôÀÌ (required)
 * bEnlarge : ÀÛÀºÀÌ¹ÌÁöµµ Å©°Ô ¸¸µå´Â ¿É¼Ç(optional : default false)
 *
 * [»ç¿ë¿¹] ¹Ýµå½Ã unique ÇÑ id ÁöÁ¤ÇÒ°Í..
 * <img id="myImage" onload="resizeImage(this, 120, 120, true)" style="visibility:hidden">
 *
 * [¼³¸í]
 *   virtualImage °´Ã¼ÀÇ width, height °ªÀ» Ã¼Å©ÇÏ¿© ·ÎµùÀ» È®ÀÎÇÑ´Ù.
 *   oImage ÀÇ virtualImage ¸¦ ÀÌ¿ëÇÏ¿© ¿ÜºÎ·Î ÀÎÀÚ¸¦ ³Ñ±ä´Ù
 *   (ÀÌ¹ÌÁö°¡ ¿©·¯°³ÀÌ¹Ç·Î Àü¿ªº¯¼ö »ç¿ë¾ÈÇÏ°í ÀÚ±âÁ¤º¸´Â ÀÚ±â°´Ã¼¿¡ ¼ÂÆÃ)
 *   oImage.virtualImage : ÀÚ±âÀÚ½ÅÀÇ º¹»çº» °¡»ó ÀÌ¹ÌÁö
 *   oImage.tracker : virtualImage ÀÇ ·Îµù»óÅÂ¸¦ Ã¼Å©ÇÏ´Â Thread
 */
function resizeImage(oImage, nWidth, nHeight, bEnlarge) {
    
    // checking parameter
    
    if (oImage.id == null) {
    	alert("Required unique image.id property !!");
    	return;
    }
    bEnlarge = (bEnlarge != null) ? bEnlarge : false;
	
	// create virtualImage
    var virtualImage = new Image();
    virtualImage.src = oImage.src;
    oImage.virtualImage = virtualImage;
    
    // wait loading time
    var interval = 1000;    // millisecond
    var timeout = 10000;  // millisecond
    var startTime = (new Date()).getTime();
	
	var sEval = "trackImageLoading('" + oImage.id + "', " + nWidth + ", " + 
					nHeight + ", " + bEnlarge + "," + startTime + ", " + timeout + ")";
    oImage.tracker = window.setTimeout(sEval, interval);
}


/**
 * ÀÌ¹ÌÁö°¡ ·ÎµùµÊÀ» ÀÏÁ¤°£°ÝÀ¸·Î Ã¼Å©ÇÑ´Ù.
 *
 * sImageId : image Object (required)
 * nWidth : ±âÁØ ³ÐÀÌ (required)
 * nHeight : ±âÁØ ³ôÀÌ (required)
 * bEnlarge : ÀÛÀºÀÌ¹ÌÁöµµ Å©°Ô ¸¸µå´Â ¿É¼Ç(optional)
 */
function trackImageLoading(sImageId, nWidth, nHeight, bEnlarge, startTime, timeout) {
	var oImage = document.getElementById(sImageId);
    var nowTime = (new Date()).getTime();
	
	if (oImage.tracker == null) {
		return;
	}
	
    if ((nowTime - startTime) >= timeout) { // timeout
        // set loading fail image
        oImage.virtualImage = null;
        oImage.style.visibility = "hidden";
        
        // stop thread
    	if (oImage.tracker != null) {
	    	window.clearTimeout(oImage.tracker);
	    	oImage.tracker = null;
	    }
    } else {
    	if (oImage.virtualImage.width > 0
    				&& oImage.virtualImage.height > 0) {
        	
        	// image resize
        	var x = oImage.virtualImage.width;
	        var y = oImage.virtualImage.height;
			
			if (nWidth > 0 && nHeight > 0) {
		        if ((nWidth / nHeight) >= (x / y)) {
		            if (oImage.virtualImage.height > nHeight || bEnlarge) {
		                x = Math.floor((nHeight * oImage.virtualImage.width / oImage.virtualImage.height));
		                y = nHeight;
		            }
		        } else {
		            if (oImage.virtualImage.width > nWidth || bEnlarge) { // to small by width base
		                x = nWidth;
		                y = Math.floor((nWidth * oImage.virtualImage.height / oImage.virtualImage.width));
		            }
		        }
			} else {
				if (nHeight > 0) { // width base
					if (oImage.virtualImage.height > nHeight || bEnlarge) {
						x = Math.floor((nHeight * oImage.virtualImage.width / oImage.virtualImage.height));
						y = nHeight;
					}
				} else if (nWidth > 0) { // height base
					if (oImage.virtualImage.width > nWidth || bEnlarge) {
						x = nWidth;
						y = Math.floor((nWidth * oImage.virtualImage.height / oImage.virtualImage.width));
					}
				}
			}
	        
	        oImage.width = x;
	        oImage.height = y;
	        oImage.style.visibility = "visible";

			// stop thread
			if (oImage.tracker != null) {
	        	window.clearTimeout(oImage.tracker);
	        	oImage.tracker = null;
	        }
        }
    }
}

/**
 * ¿øº» ÀÌ¹ÌÁö¸¦ ÆË¾÷À¸·Î º¸¿©ÁØ´Ù.
 * @param imageURL (required) ÀÌ¹ÌÁöURL
 * @param domain (required) document.domain°ª
 * @param width (optional) ³ÐÀÌ
 * @param height (optional) ³ôÀÌ
 */
function openImagePopup(imageURL, width, height) {
	
	var sFeatures = "toolbar=0,location=0,menubar=0,status=1";
	var popupURL = "http://www.miclub.com/common/image_popup.jsp";
	if (width != null && height != null) {
		
		if (width > window.screen.width || height > window.screen.height) {
			sFeatures += ",scrollbars=1,resizable=1";
			
			width = (width > window.screen.width) ? window.screen.width - 100 : width;
			height = (height > window.screen.height) ? window.screen.height - 100 : height;
			width += 16;
			height += 16;
		} else {
			sFeatures += ",scrollbars=0,resizable=0";
		}
		
		popupURL += "?image=" + imageURL + "&width=" + width + "&height=" + height;
		var top = Math.ceil((window.screen.height - height) / 2) - Math.ceil((27+20) / 2);
		var left= Math.ceil((window.screen.width  - width) / 2);
		sFeatures += ",width=" + width + ",height=" + height + "," +
				"top=" + top + ",left=" + left;
		window.open(popupURL, "openImagePopup", sFeatures);
	} else {
		popupURL += "?image=" + imageURL;
		sFeatures += ",width=20,height=20";
		window.open(popupURL, "openImagePopup", sFeatures);
	}
}

/**
 * ÀÌ¹ÌÁö ÆÄÀÏ ¿©ºÎ¸¦ Ã¼Å©ÇÑ´Ù.
 * @param fileName (required) ÀÌ¹ÌÁöURL
 * @return gif, jpg, jpeg, png ÆÄÀÏÀÌ¸é true
 */
function isImageFile(file) {
	if (file == null && file.length == 0) {
		return false;
	}
	return /\.gif$|\.jpg$|\.jpeg$|\.png$/i.test(file);
	//return /\.jpg$|\.jpeg$|\.png$/i.test(file);
}
//-->
