﻿/*
Author : BangMunJun 
date : 2011.04.09
Version : 1.1
*/ 
//IE Flicker Bug Fix
(function(){var ie6=document.uniqueID/*IE*/&&document.compatMode/*>=IE6*/&&!window.XMLHttpRequest/*<=IE6*/&& document.execCommand;	try{if(!!ie6){m("BackgroundImageCache", false, true)}}catch(oh){};})();

/* Image OnOf */
function imgOver(imgEl){if(imgEl){_imgtype=imgEl.src.substr(imgEl.src.length-3,imgEl.src.length-1);var where=imgEl.src.indexOf("_on."+_imgtype,0);if(where==-1)imgEl.src=imgEl.src.replace("."+_imgtype,"_on."+_imgtype);}}
function imgOut(imgEl){if(imgEl){_imgtype=imgEl.src.substr(imgEl.src.length-3,imgEl.src.length-1);var where=imgEl.src.indexOf("_on."+_imgtype,0);if(where!=-1)imgEl.src=imgEl.src.replace("_on."+_imgtype,"."+_imgtype);}}
function menuOver(){var imgEl=(this.src)?this:this.getElementsByTagName("img")[0];	if(imgEl){_imgtype=imgEl.src.substr(imgEl.src.length-3,imgEl.src.length-1);var where=imgEl.src.indexOf("_on."+_imgtype,0);if(where==-1)imgEl.src=imgEl.src.replace("."+_imgtype,"_on."+_imgtype);}}
function menuOut(){var imgEl=(this.src)?this:this.getElementsByTagName("img")[0];if(imgEl){_imgtype=imgEl.src.substr(imgEl.src.length-3,imgEl.src.length-1);var where=imgEl.src.indexOf("_on."+_imgtype,0);if(where!=-1)imgEl.src=imgEl.src.replace("_on."+_imgtype,"."+_imgtype);}}

/* 보이기감추기 */
function displayOn(){var i,j,a=displayOn.arguments;for(var i=0;i<a.length;i++){var obj=document.getElementById(a[i]);if(obj){obj.style.display="block";}}}
function displayOff(){var i,j,a=displayOff.arguments;for(var i=0;i<a.length;i++){var obj=document.getElementById(a[i]);if(obj){obj.style.display="none";}}}
/* 보이기감추기 토글 */
function displayToggle(id){var obj=document.getElementById(id);
	if(obj){if(obj.style.display=="block")obj.style.display="none";else obj.style.display="block";}
}


/* 이미지 롤오버아웃 */
function initImgRoll(containerId) { 
 	var imgEl = document.getElementById(containerId).getElementsByTagName("img");
	if(imgEl){
		for(var i=0; i<imgEl.length; i++){
			var objImg = imgEl[i];
			_imgtype = objImg.src.substr(objImg.src.length-3,objImg.src.length-1);
			var where = objImg.src.indexOf("_on."+_imgtype,0);
			if (where==-1){//함수필요(myshin.js)
				objImg.onmouseover = objImg.onfocus = menuOver;
				objImg.onmouseout = objImg.onblur = menuOut;
			}
		}
	}
}

/* 탭이미지콘텐츠보기
* ex) tabimgView("탭이미지그룹id","활성이미지탭id"); tabimgView("tab1",1);
*/
function tabOn(containerId,a) {
	var tabContainer = document.getElementById(containerId);
	var tabid = (tabContainer)? tabContainer.id : "tab"+containerId;//이전코드호환
	var tabTagAll = document.getElementById(tabid).getElementsByTagName("*");
	var tabSum = 0;//탭그룹안의 탭 개수 초기화
	for(var i=0;i<tabTagAll.length;i++){
		var where = tabTagAll[i].id.indexOf(containerId);
		if(where!=-1) tabSum++;
	}
	tabSum = tabSum/2;//루프로 찾은 수는 탭1개당 2개(메뉴와 콘텐츠)이므로 보정.
	for(var i=1;i<=tabSum;i++){//탭 개수만큼만 루트 돌린다.
		if(i<10){inn="0"+i;} else {inn=""+i;}
		tabMenu = document.getElementById(tabid+"m"+i);
		tabContent = document.getElementById(tabid+"c"+i);
		if (tabMenu){
			if (tabMenu.tagName=="IMG"){
				_imgtype = tabMenu.src.substr(tabMenu.src.length-3,tabMenu.src.length-1);
				tabMenu.src = tabMenu.src.replace("_on."+_imgtype, "."+_imgtype);
			}
			if (tabMenu.tagName=="A"){ tabMenu.className=""; }
		}
		if (tabContent) { tabContent.style.display="none"; }
	}
	if(a<10){ann="0"+a;} else {ann=""+a;}
	tabMenu = document.getElementById(tabid+"m"+a);
	tabContent = document.getElementById(tabid+"c"+a);
	if (tabMenu){
		if (tabMenu.tagName=="IMG"){
			_imgtype = tabMenu.src.substr(tabMenu.src.length-3,tabMenu.src.length-1);
			tabMenu.src = tabMenu.src.replace("."+_imgtype, "_on."+_imgtype);
		}
		if (tabMenu.tagName=="A"){ tabMenu.className="on"; }
	}
	if (tabContent) { tabContent.style.display="block"; }
	tabMore = document.getElementById(tabid+"more");
}

/* 주메뉴 */
function top2menuView(a){//2차메뉴보기
	if(this.id){
		eidStr=this.id;
		eidNum=eidStr.substring(eidStr.lastIndexOf("m",eidStr.length)+1,eidStr.length);
		a=parseInt(eidNum);
	}
	top2menuHideAll();
	top1Menu=document.getElementById("nav1m"+a);
	top2Menu=document.getElementById("nav2m"+a);
	ann=(a<10)?"0"+a:""+a;
	if(a==0){//메인은2차메뉴활성화안함
	}else{
		if(top1Menu){top1Menu.parentNode.className="on";
			var imgEl=top1Menu.childNodes[0]
			if(imgEl.src){
				_imgtype=imgEl.src.substr(imgEl.src.length-3,imgEl.src.length-1);
				var where=imgEl.src.indexOf("_on."+_imgtype,0);
				if(where==-1)imgEl.src=imgEl.src.replace("."+_imgtype,"_on."+_imgtype);
			}
			if(top2Menu){top2Menu.style.display="inline";}
		}
	}
}
function top2menuHide(a){//2차메뉴감추기
	if(this.id){
		eidStr=this.id;
		eidNum=eidStr.substring(eidStr.lastIndexOf("m",eidStr.length)+1,eidStr.length);
		a=parseInt(eidNum);
	}
	//top2menuHideAll();
	top1Menu=document.getElementById("nav1m"+a);
	top2Menu=document.getElementById("nav2m"+a);
	top1MenuCurr=document.getElementById("nav1m"+d1n);
	top2MenuCurr=document.getElementById("nav2m"+d1n);
	ann=(a<10)?"0"+a:""+a;
	if(top1Menu){	top1Menu.parentNode.className=""	;
		var imgEl=top1Menu.childNodes[0]
		if(imgEl.src){
			_imgtype=imgEl.src.substr(imgEl.src.length-3,imgEl.src.length-1);
			var where=imgEl.src.indexOf("_on."+_imgtype,0);
			if(where!=-1)imgEl.src=imgEl.src.replace("_on."+_imgtype,"."+_imgtype);
		}
		if(top2Menu){
			top2Menu.style.display="none";
		}
		if(top1MenuCurr){top1MenuCurr.parentNode.className="on";
			var imgEl=top1MenuCurr.childNodes[0]
			if(imgEl.src){
				_imgtype=imgEl.src.substr(imgEl.src.length-3,imgEl.src.length-1);
				var where=imgEl.src.indexOf("_on."+_imgtype,0);
				if(where==-1)imgEl.src=imgEl.src.replace("."+_imgtype,"_on."+_imgtype);
			}
		}
		if(top2MenuCurr){top2MenuCurr.style.display="inline";}
	}
}
function top2menuHideAll()//2차메뉴모두감추기
{
	top1menuEl=document.getElementById("nav1").childNodes;
	for(i=1;i<=11;i++){//1차메뉴수11이하
		top1Menu=document.getElementById("nav1m"+i);
		top2Menu=document.getElementById("nav2m"+i);
		inn=(i<10)?"0"+i:""+i;
		if(top1Menu){top1Menu.parentNode.className="";
			var imgEl=top1Menu.childNodes[0]
			if(imgEl.src){
				_imgtype=imgEl.src.substr(imgEl.src.length-3,imgEl.src.length-1);
				var where=imgEl.src.indexOf("on."+_imgtype,0);
				if(where!=-1)imgEl.src=imgEl.src.replace("_on."+_imgtype,"."+_imgtype);
			}
			if(top2Menu){top2Menu.style.display="none";}
		}
	}
}
function initTopMenu(d1,d2,imgPath){//1,2차메뉴초기화,이벤트할당
	d1n=d1;d2n=d2;//전역변수
	d1nn=(d1n<10)?"0"+d1n:""+d1n;
	d2nn=(d2n<10)?"0"+d2n:""+d2n;
 	top1menuEl=document.getElementById("nav1").childNodes;
	top2MenuCurrAct=document.getElementById("nav2m"+d1+"m"+d2);
	for(i=1;i<=11;i++){//1차메뉴수11이하
		top1Menu=document.getElementById("nav1m"+i);
		top2Menu=document.getElementById("nav2m"+i);
		if(top1Menu){
			inn=(i<10)?"0"+i:""+i;
			top1Menu.style.textIndent="0";//스타일원상태복구.
			top1Menu.onmouseover=top1Menu.onfocus=top2menuView;
			top1Menu.onmouseout=top2menuHide;//onblur하면 IE에서 2차메뉴선택불가
			if(top2Menu){
				for (a=1;a<=10;a++){//2차메뉴이미지로대체
					var ann = (a<10)? "0"+a : ""+a;
					top2MenuLi = document.getElementById("nav2m"+i+"m"+a); 
					if(top2MenuLi){
						top2MenuA = document.getElementById("nav2m"+i+"m"+a).getElementsByTagName('a')[0];
						if((top2MenuA) && (top2MenuLi!=top2MenuCurrAct)){//현재메뉴가아닐때
							top2MenuLi.onmouseover = menuOver
							top2MenuLi.onmouseout = menuOut;
						}
					}
				}
				top2Menu.style.display="none";
				var top2MenuLastChild=top2Menu.lastChild;//끝li
				if(top2MenuLastChild){
					while(top2MenuLastChild.nodeName!="LI")top2MenuLastChild=top2MenuLastChild.previousSibling;
					top2MenuLastChild.className="last";
				}
				var top2MenuFirstChild=top2Menu.firstChild;//첫li
				if(top2MenuFirstChild){
					while(top2MenuFirstChild.nodeName!="LI")top2MenuFirstChild=top2MenuFirstChild.nextSibling;
					top2MenuFirstChild.className="first";
				}
				top2Menu.onmouseover=top2Menu.onfocus=top2menuView;
				top2Menu.onmouseout=top2Menu.onblur=top2menuHide;
				top2MenuAs=top2Menu.getElementsByTagName("a");
				if(top2MenuAs){
					for(j=0;j<top2MenuAs.length;j++){
						//top2MenuAs[j].innerHTML='<span>'+top2MenuAs[j].innerHTML+'</span>';//장식용
					}
				}
			}
		}
	}
	//2차메뉴활성
	if(top2MenuCurrAct){
		top2MenuCurrAct.getElementsByTagName("a")[0].className="on";//텍스트용
		var imgEl = top2MenuCurrAct.getElementsByTagName("img")[0];
		if(imgEl.src){
			_imgtype = imgEl.src.substr(imgEl.src.length-3,imgEl.src.length-1);
			var where = imgEl.src.indexOf("_on."+_imgtype,0);
			if(where==-1) imgEl.src = imgEl.src.replace("."+_imgtype,"_on."+_imgtype);
		}
	}
	top2menuHide(d1);//메뉴활성초기화
}

/* 사내소식지 */
    function open_book(e_url) {
        //alert(e_url)
        //html/EBOOK/HD20100114/flashbook.html
        e_url = 'http://hyundaielevator.co.kr/html/EBOOK/HD' + e_url + '/flashbook.html';
        var vn_screenx = window.screen.width - 10; // 화면스크린 넓이
        var vn_screeny = window.screen.height - 58; // 화면스크린 높이
        window.open(e_url, 'catallog', 'width=' + vn_screenx + ',height=' + vn_screeny + ',status=no');
 
        //(url, winName, winW, winH, tools, menu, scroll, resize, status, directory, location)
    }
 

/* ==== slider nameSpace ==== */
	var slider = function() {
		/* ==== private methods ==== */
		function getElementsByClass(object, tag, className) {
			var o = object.getElementsByTagName(tag);
			for ( var i = 0, n = o.length, ret = []; i < n; i++) {
				if (o[i].className == className) ret.push(o[i]);
			}
			if (ret.length == 1) ret = ret[0];
			return ret;
		}
		function setOpacity (obj,o) {
			alert(obj);
			if (obilters) obj.filters.alpha.opacity = Math.round(o);
			else obj.style.opacity = o / 50;
		}
		
		
		/* ==== Slider Constructor ==== */
		function Slider(oCont, speed, iW, iH, oP) {
			this.slides = [];
			this.over   = true;//first over
			this.S      = this.S0 = speed;
			this.iW     = iW;
			this.iH     = iH;
			this.oP     = oP;
			this.oc     = document.getElementById(oCont);
			this.frm    = getElementsByClass(this.oc, 'div', 'slide');
			this.NF     = this.frm.length;
			this.resize();
			for (var i = 0; i < this.NF; i++) {
				this.slides[i] = new Slide(this, i);
			}
			this.oc.parent = this;
			this.view      = this.slides[0];
			this.Z         = this.mx;
			/* ==== on mouse out event ==== */
			/*
			this.oc.onmouseout = function () {
				this.parent.mouseout();
				return false;
			}
			*/
		}
		Slider.prototype = {
			/* ==== animation loop ==== */
			run : function () {
				this.Z += this.over ? (this.mn - this.Z) * .5 : (this.mx - this.Z) * .5;
				this.view.calc();
				var i = this.NF;
				while (i--) this.slides[i].move();
			},
			/* ==== resize  ==== */
			resize : function () {
				this.wh = this.oc.clientWidth;
				this.ht = this.oc.clientHeight;
				this.wr = this.wh * this.iW;
				this.r  = this.ht / this.wr;
				this.mx = this.wh / this.NF;
				this.mn = (this.wh * (1 - this.iW)) / (this.NF - 1);
			},
			/* ==== rest  ==== */
			mouseout : function () {
				this.over      = true;//false; 100503
				//setOpacity(this.view.img, this.oP);
				//setOpacity(this.view.img, 100);//100503
			}
		}
		/* ==== Slide Constructor ==== */
		Slide = function (parent, N) {
			this.parent = parent;
			this.N      = N;
			this.x0     = this.x1 = N * parent.mx;
			this.v      = 0;
			this.loaded = false;
			this.cpt    = 0;
			this.start  = new Date();
			this.obj    = parent.frm[N];
			this.txt    = getElementsByClass(this.obj, 'div', 'text');
			this.img    = getElementsByClass(this.obj, 'img', 'diapo');
			this.bkg    = document.createElement('div');
			this.bkg.className = 'backgroundText';
			this.obj.insertBefore(this.bkg, this.txt);
			if (N == 0) this.obj.style.borderLeft = 'none';
			this.obj.style.left = Math.floor(this.x0) + 'px';
			//setOpacity(this.img, parent.oP);
			//setOpacity(this.img, 100);
			/* ==== mouse events ==== */
			this.obj.parent = this;
			this.obj.onmouseover = function() {
				this.parent.over();
				return false;
			}
		}
		Slide.prototype = {
			/* ==== target positions ==== */
			calc : function() {
				var that = this.parent;
				// left slides
				for (var i = 0; i <= this.N; i++) {
					that.slides[i].x1 = i * that.Z;
				}
				// right slides
				for (var i = this.N + 1; i < that.NF; i++) {
					that.slides[i].x1 = that.wh - (that.NF - i) * that.Z;
				}
			},
			/* ==== HTML animation : move slides ==== */
			move : function() {
				var that = this.parent;
				var s = (this.x1 - this.x0) / that.S;
				/* ==== lateral slide ==== */
				if (this.N && Math.abs(s) > .5) {
					this.obj.style.left = Math.floor(this.x0 += s) + 'px';
				}
				/* ==== vertical text ==== */
				var v = (this.N < that.NF - 1) ? that.slides[this.N + 1].x0 - this.x0 : that.wh - this.x0;
				if (Math.abs(v - this.v) > .5) {
					this.bkg.style.top = this.txt.style.top = Math.floor(2 + that.ht - (v - that.Z) * that.iH * that.r) + 'px';
					this.v = v;
					this.cpt++;
				} else {
					if (!this.pro) {
						/* ==== adjust speed ==== */
						this.pro = true;
						var tps = new Date() - this.start;
						if(this.cpt > 1) {
							that.S = Math.max(2, (28 / (tps / this.cpt)) * that.S0);
						}
					}
				}
				if (!this.loaded) {
					if (this.img.complete) {
						this.img.style.visibility = 'visible';
						this.loaded = true;
					}
				}
			},
			/* ==== light ==== */
			over : function () {
				this.parent.resize();
				this.parent.over = true;
				//setOpacity(this.parent.view.img, this.parent.oP);
				//setOpacity(this.parent.view.img, 100); //100503
				this.parent.view = this;
				this.start = new Date();
				this.cpt = 0;
				this.pro = false;
				this.calc();
				//setOpacity(this.img, 100);
			}
		}
		/* ==== public method - script initialization ==== */
		return {
			init : function() {
				// create instances of sliders here
				// parameters : HTMLcontainer name, speed (2 fast - 20 slow), Horizontal ratio, vertical text ratio, opacity
				this.s1 = new Slider("slider", 12, 2.45/3, 1/3.2, 70);
				setInterval("slider.s1.run();", 14);
			}
		}
	}();

