﻿
// gnbMenu
function initNavigation(nbID, seq) {
	nav = document.getElementById(nbID);
	nav.menu = new Array();
	nav.current = null;
	nav.menuseq = 0;
	navLen = nav.childNodes.length;
	
	allA = nav.getElementsByTagName("a")
	for(k = 0; k < allA.length; k++) {
		allA.item(k).onmouseover = allA.item(k).onfocus = function () {
			nav.isOver = true;
		}
		allA.item(k).onmouseout = allA.item(k).onblur = function () {
			nav.isOver = false;
			setTimeout(function () {
				if (nav.isOver == false) {
					if (nav.menu[seq])
						nav.menu[seq].onmouseover();
					else if(nav.current) {
						menuImg = nav.current.childNodes.item(0);
						menuImg.src = menuImg.src.replace("_on.gif", "_off.gif");
						if (nav.current.submenu){
							nav.current.submenu.style.display = "none";
							if ($.browser.msie) {
								if(parseInt($.browser.version) == 6){
									/*if(typeof LOGINID != undefined){
										if(LOGINID == "sigih22"){
											alert(LOGINID);*/
											$("p.location:eq(1)").hide();
											$("p.location:eq(0)").show();
										/*}
									}*/
								}
							}
						}
						nav.current = null;
					}
				}
			}, 500);
		}
	}

	for (i = 0; i < navLen; i++) {
		navItem = nav.childNodes.item(i);
		if (navItem.tagName != "LI")
			continue;

		navAnchor = navItem.getElementsByTagName("a").item(0);
		navAnchor.submenu = navItem.getElementsByTagName("ul").item(0);
		
		navAnchor.onmouseover = navAnchor.onfocus = function () {
			if (nav.current) {
				menuImg = nav.current.childNodes.item(0);
				menuImg.src = menuImg.src.replace("_on.gif", "_off.gif");
				if (nav.current.submenu){
					nav.current.submenu.style.display = "none";
					if ($.browser.msie) {
						if(parseInt($.browser.version) == 6){
							/*if(typeof LOGINID != undefined){
								if(LOGINID == "sigih22"){
									alert(LOGINID);*/
									$("p.location:eq(1)").hide();
									$("p.location:eq(0)").show();
								/*}
							}*/
						}
					}
				}
				nav.current = null;
			}
			if (nav.current != this) {
				menuImg = this.childNodes.item(0);
				menuImg.src = menuImg.src.replace("_off.gif", "_on.gif");
				if (this.submenu){
					this.submenu.style.display = "block";
					var dep1 = "";
					var dep2 = "";
					if(document.location.href.indexOf("new.aspx") > -1){
						dep1 = "<span>신제품</span>";
					}else if(document.location.href.indexOf("first_list.aspx") > -1){
						dep1 = "<span>제품 원료별</span>";
						dep2 = "";
					}else if(document.location.href.indexOf("first_pro.aspx") > -1){
						dep1 = "<span>전제품 카테고리</span>";
						dep2 = "";
					}else if(document.location.href.indexOf("event.aspx") > -1){
						dep1 = "<span>쇼핑기획전</span>";
						dep2 = "";
					}else{
					    try {

						dep1 = "<span>" + $('p.location:eq(0)>select:eq(0)>option:selected').text() + "</span>";
						dep2 = "&nbsp;&gt;&nbsp;<span>" + $('p.location:eq(0)>select:eq(1)>option:selected').text() + "</span>";
					    } catch(e) { }
					}
					
					if ($.browser.msie) {
						if(parseInt($.browser.version) == 6){
							if($("p.location:eq(0) select").length > 0){
							/*if(typeof LOGINID != undefined){
								if(LOGINID == "sigih22"){
									alert(LOGINID);*/
									//if($("#ctl00_cphContents_ucShop_Location1_ddlNavi").length > 0){
										//alert(dep1);
										$("p.location:eq(1)").html('<div style="padding-top:3px;"><a>쇼핑홈</a>' + dep1 + dep2 + "</div>");
									//}
									//$('p.location>select>option:selected').text()
									$("p.location:eq(1)").show().css("height","17px");
									$("p.location:eq(0)").hide();
								/*}
							}*/
							}
						}
					}
					
				}
				nav.current = this;
			}
			nav.isOver = true;
		}
		nav.menuseq++;
		nav.menu[nav.menuseq] = navAnchor;
	}
	if (nav.menu[seq])
		nav.menu[seq].onmouseover();
}


/* 팝업 뛰우기 */
function openWin(url,win,s)
{	
	var win1=null;
	win1 = window.open(url, win ,'resizable=no, toolbar=no, scrollbars='+s+', menubar=no, top=30, left=30').focus();
}

function PopupAutoResize() {
    window.resizeTo(100, 100);
    var thisX = parseInt(document.body.clientWidth);
    var thisY = parseInt(document.body.clientHeight);
    var maxThisX = screen.width - 50;
    var maxThisY = screen.height - 50;
    var marginY = 0;
    //alert(thisX + "===" + thisY);
    //alert("임시 브라우저 확인 : " + navigator.userAgent);
    // 브라우저별 높이 조절. 
    if (navigator.userAgent.indexOf("MSIE 6") > 0) marginY = 35;        // IE 6.x
    else if(navigator.userAgent.indexOf("MSIE 7") > 0) marginY = 80;    // IE 7.x
    else if(navigator.userAgent.indexOf("Firefox") > 0) marginY = 83;   // FF
    else if(navigator.userAgent.indexOf("Opera") > 0) marginY = 30;     // Opera
    else if(navigator.userAgent.indexOf("Netscape") > 0) marginY = -2;  // Netscape

    if (thisX > maxThisX) {
        window.document.body.scroll = "yes";
        thisX = maxThisX;
    }
    if (thisY > maxThisY - marginY) {
        window.document.body.scroll = "yes";
        thisX += 19;
        thisY = maxThisY - marginY;
    }
    window.resizeTo(thisX+10, thisY+marginY);
	 // 센터 정렬
    // var windowX = (screen.width - (thisX+10))/2;
    // var windowY = (screen.height - (thisY+marginY))/2 - 20;
    // window.moveTo(windowX,windowY);

}


/* img over */
function imgMenuOver(containderID) {
	var objwrap = document.getElementById(containderID);
	var imgMenu = objwrap.getElementsByTagName("a");

	for (i=0; i<imgMenu.length; i++) {
		if(imgMenu[i].getElementsByTagName("img").length == 0) continue;

		if (imgMenu[i].getElementsByTagName("img")[0].src.indexOf("_on.gif") != -1 ) {
			continue;
		}
		imgMenu[i].onmouseover = function() {
			subImage = this.getElementsByTagName("img")[0];
			if (subImage.src.indexOf("_on.gif") != -1) return false;
			subImage.src = subImage.src.replace("_off.gif","_on.gif");
		}
		imgMenu[i].onfocus = function() {
			subImage = this.getElementsByTagName("img")[0];
			if (subImage.src.indexOf("_over.gif") != -1) return false;
			subImage.src = subImage.src.replace("_off.gif","_on.gif");
		}
		imgMenu[i].onmouseout = function() {
			subImage = this.getElementsByTagName("img")[0];
			subImage.src = subImage.src.replace("_on.gif", "_off.gif");
		}
		imgMenu[i].onblur = function() {
			subImage = this.getElementsByTagName("img")[0];
			subImage.src = subImage.src.replace("_on.gif", "_off.gif");
		}
	}
}

/* 토글 */
function initToggle(tabContainer) {
	triggers = tabContainer.getElementsByTagName("a");

	for(i = 0; i < triggers.length; i++) {
		if (triggers.item(i).href.split("#")[1])
			triggers.item(i).targetEl = document.getElementById(triggers.item(i).href.split("#")[1]);

		if (!triggers.item(i).targetEl)
			continue;

		triggers.item(i).targetEl.style.display = "none";
		triggers.item(i).className = "";
		triggers.item(i).imgEl = triggers.item(i).getElementsByTagName("img").item(0);
		triggers.item(i).onclick = function () {
			if (tabContainer.current == this) {
				this.targetEl.style.display = "none";
				this.className = "";
				tabContainer.current = null;
				//if (this.imgEl) { 이미지 업다운 이미지 추가될때 사용
					//this.imgEl.src = this.imgEl.src.replace("_over.gif", ".gif");
				//}
				
			} else {
				if (tabContainer.current) {
					tabContainer.current.targetEl.style.display = "none";
					tabContainer.current.className =""
					//if (this.imgEl) {
					//tabContainer.current.imgEl.src = tabContainer.current.imgEl.src.replace("_over.gif", ".gif");
					//}
					
				}
				//if (this.imgEl) {
					//this.imgEl.src = this.imgEl.src.replace(".gif", "_over.gif");
				//}
				//triggers.item(0).targetEl.style.display = "none"; 첫번째 페이지 항상 열려있게
				this.targetEl.style.display = "";
				this.className ="on"
				tabContainer.current = this;
			}
			return false;
		}
	}
	triggers.item(0).targetEl.style.display = "none"; 
}



function setPNG24(obj) {
	obj.width=obj.height=1;
	obj.className=obj.className.replace(/\bPNG24\b/i,'');
	obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
	obj.src='';
	return '';
	}

// Message Window
function openMessageWindow(href) {
	var windowEl = document.createElement("iframe");
	windowEl.src = href;
	windowEl.frameBorder = 0;
	windowEl.scrolling = "no";
	windowEl.allowTransparency = "true";
	windowEl.style.zIndex = 1001;
	windowEl.style.position = 'absolute';
	document.getElementsByTagName("body").item(0).appendChild(windowEl);
	document.getElementsByTagName("body").item(0).popup = windowEl;

	//var selects = document.getElementsByTagName("select");
	//for (i = 0; i < selects.length; i++) {
		//selects.item(i).hided = true;
		//selects.item(i).style.visibility = "hidden";
	//}

	var mask = document.createElement("div");
	mask.onclick = closeMessageWindow;
	mask.style.width = document.documentElement.clientWidth + "px";
	mask.style.height = document.documentElement.scrollHeight + "px";
	mask.style.position = 'absolute';
	mask.style.top = "0";
	mask.style.left = "0";
	mask.style.zIndex = 1000;
	mask.style.backgroundColor = "#fff";
	mask.style.opacity = "0.2";
	mask.style.filter = "alpha(opacity = 0)";
	document.getElementsByTagName("body").item(0).appendChild(mask);
	windowEl.mask = mask;
}

function closeMessageWindow() {
	var windowEl = parent.document.getElementsByTagName("body").item(0).popup;
	if (!windowEl)
		return false;

	var selects = parent.document.getElementsByTagName("select");
	for (i = 0; i < selects.length; i++) {
		if (selects.item(i).hided == true) {
			selects.item(i).style.visibility = "visible";
		}
	}

	windowEl.style.display = "none";
	windowEl.mask.parentNode.removeChild(windowEl.mask);
	windowEl.mask = null;
	
	//return true;
}
function positionMessageWindow() {
	if (!parent.document.getElementsByTagName("body").item(0).popup)
		return;

	var windowEl = parent.document.getElementsByTagName("body").item(0).popup;
	windowEl.style.height = "auto";
	windowEl.style.width = "auto";
	var windowElHeight = document.documentElement.scrollHeight;
	var windowElWidth = document.documentElement.scrollWidth;
	windowEl.style.height = windowElHeight + 5 + "px";
	windowEl.style.width = windowElWidth + "px";
	windowEl.style.top = parent.document.documentElement.scrollTop + (parent.document.documentElement.clientHeight - windowElHeight) / 2 + "px";
	windowEl.style.left = (parent.document.documentElement.clientWidth - windowElWidth) / 2 + "px";
}
// Message Popup Layer
function openMessagePopup(elId) {
	var windowEl = document.getElementById(elId.split("#")[1]);
	if (!windowEl)
		return true;

	windowEl.style.display = 'block';
	windowEl.style.zIndex = 1001;
	windowEl.style.position = 'absolute';
	windowEl.style.top = document.documentElement.scrollTop + (document.documentElement.clientHeight - windowEl.offsetHeight) / 2 + "px";
	windowEl.style.left = (document.documentElement.clientWidth - windowEl.offsetWidth) / 2 + "px";

	var selects = document.getElementsByTagName("select");
	for (i = 0; i < selects.length; i++) {
		selects.item(i).hided = true;
		selects.item(i).style.visibility = "hidden";
	}

	var mask = document.createElement("div");
	mask.onclick = function () {
		closeMessagePopup(elId);
	}
	mask.style.width = document.documentElement.clientWidth + "px";
	mask.style.height = document.documentElement.scrollHeight + "px";
	mask.style.position = 'absolute';
	mask.style.top = "0";
	mask.style.left = "0";
	mask.style.zIndex = 1000;
	mask.style.backgroundColor = "#000";
	mask.style.opacity = "0.2";
	mask.style.filter = "alpha(opacity = 0)";
	document.getElementsByTagName("body").item(0).appendChild(mask);
	windowEl.mask = mask;
}
function closeMessagePopup(elId) {
	var windowEl = document.getElementById(elId.split("#")[1]);
	if (!windowEl)
		return true;

	var selects = parent.document.getElementsByTagName("select");
	for (i = 0; i < selects.length; i++) {
		if (selects.item(i).hided == true) {
			selects.item(i).style.visibility = "visible";
		}
	}

	windowEl.style.display = "none";
	windowEl.mask.parentNode.removeChild(windowEl.mask);
	windowEl.mask = null;
}


function embedFlash(id, flashFile, w, h, code){
	var linkInfo = "";
	var objInfo = "";
	var flashVars = "";

 	linkInfo = flashFile;

	objInfo+="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='" + w + "' height='" + h + "' id='" + id + "' name='" + id + "'>";
	objInfo+="<param name='movie' value='" + linkInfo + "'>";
	objInfo+="<param name='FlashVars' value='" + flashVars + "'>";
	objInfo+="<param name='allowScriptAccess' value='always'>";
	objInfo+="<param name='quality' value='high'>";
	objInfo+="<param name='wmode' value='transparent' />";
	objInfo+="<param name='menu' value='false' />";
	objInfo+="<embed menu='false' src='" + linkInfo + "' wmode='transparent'  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + w + "' height='" + h + "' FlashVars='" + flashVars + "' allowScriptAccess='always' swLiveConnect=true id='" + id + "' name='" + id + "'></embed></object>";
	document.write(objInfo);
}

function insertFlash(swf, width, height, bgcolor, transparent, id, flashvars)
{
	var strFlashTag = new String();

	if (navigator.appName.indexOf("Microsoft") != -1)
	{
		strFlashTag += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
		strFlashTag += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=version=8,0,0,0" ';
		strFlashTag += 'id="' + id + '" width="' + width + '" height="' + height + '">';
		strFlashTag += '<param name="movie" value="' + swf + '"/>';

		if(flashvars != null) {strFlashTag += '<param name="flashvars" value="' + flashvars + '"/>'};
		strFlashTag += '<param name="quality" value="best"/>';
		strFlashTag += '<param name="bgcolor" value="' + bgcolor + '"/>';
		strFlashTag += '<param name="menu" value="false"/>';
		strFlashTag += '<param name="salign" value="LT"/>';
		strFlashTag += '<param name="scale" value="noscale"/>';
		strFlashTag += '<param name="wmode" value="' + transparent + '"/>';
		strFlashTag += '<param name="allowScriptAccess" value="always"/>';
		strFlashTag += '</object>';
	}
	else
	{
		strFlashTag += '<embed src="' + swf + '" ';
		strFlashTag += 'quality="best" ';
		strFlashTag += 'bgcolor="' + bgcolor + '" ';
		strFlashTag += 'width="' + width + '" ';
		strFlashTag += 'height="' + height + '" ';
		strFlashTag += 'menu="false" ';
		strFlashTag += 'scale="noscale" ';
		strFlashTag += 'id="' + id + '" ';
		strFlashTag += 'salign="LT" ';
		strFlashTag += 'wmode="' + transparent + '" ';
		strFlashTag += 'allowScriptAccess="always" ';
		if(flashvars != null) {strFlashTag += 'flashvars="' + flashvars + '" '};
		strFlashTag += 'type="application/x-shockwave-flash" ';
		strFlashTag += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
		strFlashTag += '</embed>';
	}

	document.write(strFlashTag);
}