/* Use BackgroundImageCache For IE */
try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

//index check
var isindex=false;

//page code array
var pagecode;

//document scroll target
var scrolltarget;

//top nav length (tmp)
var topNavLength;

//make input(check|raio) to image
var imageroot = '..';
var isie = (/msie/i).test(navigator.userAgent); //ie

//swf object default setting
swfobject.defaultSet={
	ver : '10.0.0',
	install : "/flash/expressInstall.swf",
	params : {
		allowScriptAccess	:	'always',
		allowFullScreen		:	'true',
		quality				:	'high',
		wmode				:	'transparent'
	}
}

function makeinputtoimage() {
    var ip = document.getElementsByTagName('input');
    var _src, root = imageroot + '/images/icon/ip_';
    for (var i = 0, tmp, max = ip.length; i < max; i++) {
        if (ip[i].type == 'radio' || ip[i].type == 'checkbox') {
            if (!ip[i].setting) {
                ip[i].relimg = document.createElement('img');
                ip[i]._src = (tmp = ip[i].className.match(/src_([a-z0-9_]+)/)) ? tmp[1] : null;
                if (ip[i]._src) ip[i].relimg.src = root + ip[i]._src + ((ip[i].checked) ? '_on' : '') + '.gif';
                else ip[i].relimg.src = root + ((ip[i].type == 'radio') ? 'radio' : 'check') + ((ip[i].checked) ? '_on' : '') + '.gif';
				ip[i].relimg.className = 'fake-checkradio';
                ip[i].relimg.style.verticalAlign = (isie) ? 'middle' : '-2px';
                ip[i].relimg.style.cursor = 'pointer';
                ip[i].style.display = 'none';
                ip[i].relimg.tg = ip[i];
                ip[i].relimg.onclick = function() {
                    inputclick(this.tg);
                    return false;
                }
                ip[i].parentNode.insertBefore(ip[i].relimg, ip[i]);
                ip[i].setting = true;
            } else {
                if (ip[i]._src) ip[i].relimg.src = root + ip[i]._src + ((ip[i].checked) ? '_on' : '') + '.gif';
                else ip[i].relimg.src = root + ((ip[i].type == 'radio') ? 'radio' : 'check') + ((ip[i].checked) ? '_on' : '') + '.gif';
            }
        }
    }
    var lb = document.getElementsByTagName('label');
    for (var i = 0, max = lb.length; i < max; i++) {
        if (lb[i].htmlFor) {
            lb[i].tg = document.getElementById(lb[i].htmlFor);
            if (lb[i].tg) {
                lb[i].style.cursor = 'pointer';
                if (lb[i].tg.type == 'radio' || lb[i].tg.type == 'checkbox') {
                    lb[i].onclick = function() {
                        inputclick(this.tg);
                        return false;
                    }
                } else if (lb[i].tg.type == 'text' || lb[i].tg.type == 'password') {
                    lb[i].onclick = function() {
                        this.tg.focus();
                    }
                }
            }
        }
    }
    function inputclick(tg) {
        tg.click();
        if (tg.type == 'checkbox') {
            tg.relimg.src = root + ((tg._src) ? tg._src : 'check') + ((tg.checked) ? '_on' : '') + '.gif';
        } else if (tg.type == 'radio') {
            if (tg.form) {
                var fd = tg.form[tg.name];
                for (var i = 0, max = fd.length; i < max; i++) fd[i].relimg.src = root + ((tg.src) ? tg.src : 'radio') + ((fd[i].checked) ? '_on' : '') + '.gif';
            }
        }
    }
}

// Image Rollover
function imgOver(imgEl) {
	imgEl.onmouseout = function() {
		imgEl.src = imgEl.src.replace("_on.gif", "_off.gif");
	}
	imgEl.src = imgEl.src.replace("_off.gif", "_on.gif");
}

// header util Hover Class
function utilLinkHover(){
	var $utilLink = $('#header ul.utilLink li').not('.gnb');
	var ActiveCssName = 'active';
	$utilLink.bind({
		mouseenter : function(){
			$(this).addClass(ActiveCssName);
		}
		,mouseleave : function(){
			$(this).removeClass(ActiveCssName);
		}
	});
}

// open stylish gallery flash
function openStylishGalleryFlash(url){
	var w=(jQuery.ua.ie6 || jQuery.ua.webkit)? screen.availWidth-10 : 10000;
	var h=(jQuery.ua.ie6)? screen.availHeight-30 : (jQuery.ua.webkit)? screen.availHeight-60 : 10000;
	//window.open(url, 'stylishgallery', 'left=0, top=0, width='+w+', height='+h+', toolbar=no, scrollbars=no, resizable=no');
	window.open(url, 'stylishgallery', 'left=0, top=0, width='+w+', height='+h+', toolbar=no, scrollbars=yes, resizable=yes');
}

// jQuery ready
$(function(){

	scrolltarget=((/applewebkit/i).test(navigator.userAgent))? document.body : document.documentElement;

	// header util Hover Class
	if(document.getElementById('header')){
		utilLinkHover();
	}

	// make top navigation
	if(document.getElementById('topNav')){
		makeTopNavi();
	}

	// make side navigation
	if(document.getElementById('sideNav')){
		makeSideNavi();
	}

	// add tupperware brands flash
	if(document.getElementById('tupperwareFlash')){
		swfobject.embedSWF("/flash/04_brands/GlobalNetwork.swf?configXML=/flash/xml/configBrands.xml", "tupperwareFlash", "720", "497",
			swfobject.defaultSet.ver,
			swfobject.defaultSet.install,
			'',
			swfobject.defaultSet.params
		);
	}

	// add tupperware brands flash
	if(document.getElementById('stylishgallerywrap')){
		swfobject.embedSWF("/flash/02_product/StylishGallery.swf?configXML=/flash/xml/configStylishGallery.xml", "stylishgalleryflash", "100%", "100%",
			swfobject.defaultSet.ver,
			swfobject.defaultSet.install,
			'',
			swfobject.defaultSet.params
		);
	}

	// view page image slider
	if(document.getElementById('viewPageImageSlider')){
		imageSlider('viewPageImageSlider');
	}

	// fun event image slider
	if(document.getElementById('funEventSlider')){
		imageSlider('funEventSlider');
	}

	// view page image slider
	if(document.getElementById('histories')){
		makehistories();
	}

	// hide link dot line in ie
	if(jQuery.ua.ie){
		var i, max, tags, tgs=[];
		tags=document.getElementsByTagName('a');
		for(i=-1, max=tags.length; ++i<max;) tgs.push(tags[i]);
		tags=document.getElementsByTagName('button');
		for(i=-1, max=tags.length; ++i<max;) tgs.push(tags[i]);
		tags=document.getElementsByTagName('input');
		for(i=-1, max=tags.length; ++i<max;) if((/(image|button)/i).test(tags[i].type)) tgs.push(tags[i]);
		for(i=-1, max=tgs.length; ++i<max;) tgs[i].hideFocus=true;
	}

	// make input to image
	makeinputtoimage();

});


//make tab 
function maketab(id){

	var obj=document.getElementById(id);
	var atag=obj.getElementsByTagName('a');
	var i, max=atag.length;
	for(i=0; i<max; i++){
		atag[i].no=i;
		atag[i].show=false;
		atag[i].img=atag[i].getElementsByTagName('img')[0];
		atag[i].img.onmouseover=function(){
			if(!this.parentNode.show) this.src=this.src.replace('_off.gif', '_on.gif');
		}
		atag[i].img.onmouseout=function(){
			if(!this.parentNode.show) this.src=this.src.replace('_on.gif', '_off.gif');
		}
		atag[i].onclick=function(){
			change(this.no);
			return false;
		}
		atag[i].content=document.getElementById(atag[i].href.split('#')[1]);
	}

	function change(no){
		for(i=0; i<max; i++){
			if(i==no){
				atag[i].show=true;
				atag[i].img.src=atag[i].img.src.replace('_off.gif', '_on.gif');
				atag[i].content.style.display='block';
			}else{
				atag[i].show=false;
				atag[i].img.src=atag[i].img.src.replace('_on.gif', '_off.gif');
				atag[i].content.style.display='none';
			}
		}
		menu.resize();
	}

	change(0);

}


//view page image slider
function imageSlider(id){

	var $obj=$('#'+id);
	var $moveobj, $items, $godetailbtn, length, i;
	if(id=='funEventSlider'){
		$obj.data('over', false);
		$items=$obj.find('div.eventImages a');
		length=$items.length;
		if(!length) return;
		$godetailbtn=$('<a href="'+$items[0].href+'" class="button"><img src="../images/btn/btn_event_view.gif" alt="이벤트 자세히 보기" /></a>').appendTo($obj);
	}else{
		$moveobj=$obj.find('div.image');
		length=$moveobj.find('img').length;
	}
	if(2>length) return;

	if(id=='funEventSlider'){
		$obj
			.mouseenter(function(){
				$obj.data('over', true);
				clearrolling();
			}).mouseleave(function(){
				$obj.data('over', false);
				setrolling();
			});
		for(i=-1; ++i<length;){
			$items[i]=$($items[i]).css('opacity', 0).click(function(){
				return false;
			});
		}
	}

	var nowno=-1, autotimer=null;
	var movesize=$obj.width();
	var $paging=$('<p class="'+((id=='funEventSlider')? 'nowNum' : 'pageNum')+'"></p>').appendTo($obj);

	for(i=-1; ++i<length;){
		$paging.append($('<a href="#">'+(i+1)+'</a>'));
	}

	var $pagingbtn=$paging.find('a');
	for(i=-1; ++i<length;){
		if(jQuery.ua.ie) $pagingbtn[i].hideFocus=true;
		if(jQuery.ua.ie6 || jQuery.ua.ie7){
			$pagingbtn[i].innerHTML='';
			$pagingbtn[i].style.textIndent=0;
		}
		$pagingbtn[i]=$($pagingbtn[i]).data('no', i).mouseover(btnover).mouseout(btnout).click(btnclick);
	}

	function btnover(){
		if(!$(this).data('on')) $(this).addClass('on');
	}

	function btnout(){
		if(!$(this).data('on')) $(this).removeClass('on');
	}

	function btnclick(no){
		if(isNaN(no)) no=$(this).data('no');
		if(no==nowno) return false;
		nowno=no;
		for(i=-1; ++i<length;){
			if(i==no){
				$pagingbtn[i].data('on', true).addClass('on');
				if(id=='funEventSlider'){
					$items[i].css('opacity', 0).appendTo($items[i].parent());
					$items[i].animate({ opacity:1 }, { queue:false, duration:750, complete:setrolling });
					$godetailbtn.attr('href', $items[i].attr('href'));
				}else{
					$moveobj.animate({ left:-(i*movesize) }, { queue:false, duration:750, easing:'easeInOutExpo' });
				}
			}else{
				$pagingbtn[i].data('on', false).removeClass('on');
			}
		}
		return false;
	}

	btnclick(0);

	if(id!='funEventSlider') return;

	function setrolling(){
		clearrolling();
		if(!$obj.data('over')){
			autotimer=setTimeout(function(){
				btnclick((nowno==length-1)? 0 : nowno+1);
				setrolling();
			}, 2000);
		}
	}

	function clearrolling(){
		clearTimeout(autotimer);
	}

	setrolling();

}


// make histories
function makehistories(id){

	var $obj=$('#histories');
	var $years=$obj.children();

	var $scrolltarget=((/applewebkit/i).test(navigator.userAgent))?
			$(document.body) : $(document.documentElement);

	var imageheight=230;
	var i, j, max, jmax;
	for(i=-1, max=$years.length; ++i<max;){
		$years[i]=$($years[i]);
		$years[i].data('title', $years[i].find('h5').css('opacity', 0.11))
			.data('item', $years[i].find('li'));
		for(j=-1, jmax=$years[i].data('item').length; ++j<jmax;){
			$years[i].data('item')[j]=$($years[i].data('item')[j]);
			$years[i].data('item')[j]
				.css('position', 'absolute')
				.data('no', j)
				.data('parentno', i)
				.data('opened', (!i && !j)? true : false)
				.data('originalheight', parseInt($years[i].data('item')[j].css('height')))
				.data('txt', $years[i].data('item')[j].find('span span')
					.css('opacity', 0)
					.mouseover(txtover)
					.mouseout(txtout)
					.click(txtclick)
				)
				.data('image', $years[i].data('item')[j].find('p')
					.css({
						position : 'absolute',
						left : 0,
						top : 0,
						display : 'none',
						opacity : 0
					})
					.click(function(){
						txtclick.call($(this).find('img')[0]);
					})
				);
		}
		if(i>8) $years[i].css('display', 'none');
	}

	function txtover(){
		$(this).animate({ opacity:1 }, { queue:false, duration:300 });
	}

	function txtout(){
		$(this).animate({ opacity:0 }, { queue:false, duration:300 });
	}

	function txtclick(e, isfirstsetting){
		var $tg=$(this).parent().parent();
		var yearon, yearheight, itemtop, itemoriginalheight;
		for(i=-1, max=$years.length; ++i<max;){
			yearon=false;
			yearheight=($tg.data('parentno')==i && !$tg.data('no') && !$tg.data('opened'))? 0 : 14;
			for(j=-1, jmax=$years[i].data('item').length; ++j<jmax;){
				itemoriginalheight=$years[i].data('item')[j].data('originalheight');
				if(isfirstsetting){
					$years[i].data('item')[j].css('top', yearheight);
				}else{
					$years[i].data('item')[j].animate({ top:yearheight }, { queue:false, duration:400, easing:'easeOutExpo' });
				}
				if($tg[0]==$years[i].data('item')[j][0]){
					if(!$tg.data('opened')){
						yearon=true;
						yearheight+=imageheight;
						$tg.animate({ height:imageheight }, { queue:false, duration:600, easing:'easeOutExpo' }).data('opened', true);
						$tg.data('image').css('display', 'block').animate({ opacity:1 }, { queue:false, duration:400 });
					}else{
						yearheight+=itemoriginalheight;
						imageclose.call($tg.data('image')[0]);
					}
				}else{
					yearheight+=itemoriginalheight;
					if($years[i].data('item')[j].data('opened')){
						imageclose.call($years[i].data('item')[j].data('image')[0]);
					}
				}
				yearheight+=11;
			}
			if(isfirstsetting){
				$years[i].css('height', (67>yearheight+3)? 67 : yearheight+3);
			}else{
				$years[i].animate({ height:(67>yearheight+3)? 67 : yearheight+3 }, { queue:false, duration:400, easing:'easeOutExpo' });
				$years[i].data('title').animate({ opacity:(yearon)? 1 : 0.11 }, { queue:false, duration:500 });
			}
		}
	}

	function imageclose(){
		var $tg=$(this).parent();
		$tg.animate({ height:$tg.data('originalheight') }, { queue:false, duration:600, easing:'easeOutExpo' }).data('opened', false);
		$tg.data('image').animate({ opacity:0 }, { queue:false, duration:300, complete:function(){
			$(this).css('display', 'none');
		}});
	}

	var $gotopbtn=$('#historiestopbtn a').click(function(){
		$scrolltarget.animate({ scrollTop:$('#contents').offset().top+10 }, { queue:false, duration:1000, easing:'easeInOutExpo' });
		return false;
	});
	if(jQuery.ua.ie) $gotopbtn[0].hideFocus=true;

	var $morebtn=$('<p id="historiesmorebtn"><img src="/images/brands/btn_historymoreopen.gif" alt="더보기" /></p>')
		.insertBefore($gotopbtn.parent());
	$morebtn=$morebtn.find('img')
		.data('opened', false)
		.click(function(){
			var $this=$(this);
			if(!$this.data('opened')){
				$this.attr('src', $this.attr('src').replace('open.gif', 'close.gif')).data('opened', true);
				for(i=8, max=$years.length; ++i<max;){
					$years[i].css('display', 'block');
				}
			}else{
				$this.attr('src', $this.attr('src').replace('close.gif', 'open.gif')).data('opened', false);
				for(i=8, max=$years.length; ++i<max;){
					$years[i].css('display', 'none');
				}
			}
		});

	$years[0].data('item')[0].data('txt').trigger('click', true);

}


//make floating menu
function makeFloatingMenu(tabid, zindex){

	zindex=(zindex)? zindex : 1;

	var isie6=(/msie 6/i).test(navigator.userAgent);
	if(isie6) return; //cancel in ie6

	var scrolltarget=((/applewebkit/i).test(navigator.userAgent))?
			document.body : document.documentElement;

	var changed=false, setclasstimer=null;

	var $tab=$(tabid)
	$tab.css('width', $tab.width());

	var $tablinks=$tab.find('a');

	var original={
		top : $tab.offset().top,
		height : $tab.outerHeight(true)
	}

	var $replace=$('<div></div>')
			.css('height', original.height)
			.hide()
			.insertBefore($tab);

	var contentheights=[];
	for(var i=-1, max=$tablinks.length; ++i<max;){
		$tablinks[i].no=i;
		if(document.getElementById($tablinks[i].href.split('#')[1])){
			contentheights[i]=$('#'+$tablinks[i].href.split('#')[1]).outerHeight(true);
			if(i) contentheights[i]+=contentheights[i-1];
		}
	}

	$tablinks.bind('click', function(){
		$(scrolltarget).animate(
			{ scrollTop : $('#'+this.href.split('#')[1]).offset().top-original.height },
			{
				queue : false,
				duration : 1000,
				easing :'easeInOutExpo'
			}
		);
		settablinksclass(this.no);
		return false;
	});

	function settablinksclass(index){
		for(var i=-1, max=$tablinks.length; ++i<max;){
			if(index==i){
				$($tablinks[i]).addClass('on');
			}else{
				$($tablinks[i]).removeClass('on');
			}
		}
	}

	function check(now){
		clearTimeout(setclasstimer);
		if(isNaN(now)){
			now=scrolltarget.scrollTop;
		}
		if(!changed && now>original.top){
			$replace.show();
			$tab.css({
				position : (isie6)? 'absolute' : 'fixed',
				left : $replace.offset().left,
				top : 0,
				zIndex : zindex
			});
			changed=true;
		}else if(original.top>now){
			$replace.hide();
			$tab.css({
				position : 'static',
				zIndex : ''
			});
			changed=false;
		}
		if(isie6 && now>original.top){
			$tab.css('top', scrolltarget.scrollTop);
		}
		if(scrolltarget.scrollLeft){
			onresize();
		}
		setclasstimer=setTimeout(function(){
			if(original.top>now){
				settablinksclass(-1);
				return;
			}
			for(var i=-1, max=contentheights.length; ++i<max;){
				if(contentheights[i]+original.top>now){
					settablinksclass(i);
					break;
				}
			}
		}, 200);
	}

	function onresize(){
		$tab.css('left', -scrolltarget.scrollLeft || $replace.offset().left);
	}

	$(window).scroll(check);
	$(window).resize(onresize);

}


// make top navigation
function makeTopNavi(){

	var $header=$('#header');
	var $topnav=$('#topNav');

	var i, j, max, jmax;
	var maxsublength=0, onedepthoverno=-1;
	var headeropening=false, headeropenheight=0, headercloseheight=87, opentimer=null, closetimer=null;

	//get page code from #topNav's class name
	pagecode=[0, 0, 0];
	var topnavclass=$topnav.attr('class').split('_')[1];
	if(topnavclass.length){
		if(topnavclass.length>1) pagecode[0]=topnavclass.substr(0, 2);
		if(topnavclass.length>3) pagecode[1]=topnavclass.substr(0, 4);
		if(topnavclass.length>5) pagecode[2]=topnavclass.substr(0, 6);
	}

	/*
	if(location.href.indexOf('tupperwares.co.kr')==-1){
		pagecode=$topnav.attr('class').split('_');
		pagecode.shift();
		pagecode.pop();
		for(var i=-1; ++i<pagecode.length;) pagecode[i]=parseInt(pagecode[i]);
	}else{
		pagecode=[0, 0, 0];
		var topnavclass=$topnav.attr('class').split('_')[1];
		if(topnavclass.length){
			if(topnavclass.length>1) pagecode[0]=topnavclass.substr(0, 2);
			if(topnavclass.length>3) pagecode[1]=topnavclass.substr(0, 4);
			if(topnavclass.length>5) pagecode[2]=topnavclass.substr(0, 6);
		}
	}
	*/

	//get menu items and setting
	var $onedepthcontainer=$topnav.find('ul:first').mouseenter(open).mouseleave(reset);

	//menu initialize
	var $onedepth=$onedepthcontainer.children();
	topNavLength = $onedepth.length+1;

	for(i=-1, max=$onedepth.length; ++i<max;){
		$onedepth[i]=$($onedepth[i]);
		if($onedepth[i].attr('class')==pagecode[0]){
			pagecode[0]=i+1;
		}
		$onedepth[i]
			.data('no', i)
			.data('link', $onedepth[i].find('a:first'))
			.mouseenter(function(){
				onedepthset($(this).data('no'));
			})
			.data('subcontainer', $onedepth[i].find('ul'))
			.data('sub', $onedepth[i].find('li a'));
			for(j=-1, jmax=$onedepth[i].data('sub').length; ++j<jmax;){
				$onedepth[i].data('sub')[j]=$($onedepth[i].data('sub')[j]);
				if($onedepth[i].data('sub')[j].parent().attr('class')==pagecode[1]){
					pagecode[1]=j+1;
				}
				$onedepth[i].data('sub')[j]
					.data('no', i)
					.data('subno', j)
					.css('opacity', 0)
					.mouseenter(function(){
						twodepthset($(this).data('no'), $(this).data('subno'));
					})
					.click(function(){
						if((/stylish gallery/i).test(this.innerHTML)){
							openStylishGalleryFlash(this.href);
							return false;
						}
					});
			}
		if(jmax>maxsublength) maxsublength=jmax;
	}

	//one depth menu set
	function onedepthset(no){
		onedepthoverno=no;
		for(var i=-1, max=$onedepth.length, $target; ++i<max; ){
			$target=$($onedepth[i]);
			if(no==i){
				$target.data('link').animate({ opacity : 1 }, { queue:false, duration:500 });
				$target.data('subcontainer').animate({ opacity : 1 }, { queue:false, duration:500 });
			}else{
				$target.data('link').animate({ opacity : 0 }, { queue:false, duration:500 });
				$target.data('subcontainer').animate({ opacity : 0.6 }, { queue:false, duration:500 });
				twodepthset(i, -1);
			}
		}
	}

	//two depth menu set
	function twodepthset(no, subno){
		var $target=$($onedepth[no]).data('sub');
		for(var i=-1, max=$target.length; ++i<max; ){
			$($target[i]).animate({ opacity : (subno==i)? 1 : 0 }, { queue:false, duration:500 });
		}
	}

	//reset
	function reset(nodelay){
		closetimer=setTimeout(function(){
			if(pagecode[0]>0){
				if(6>pagecode[0]){
					onedepthset(pagecode[0]-1);
					twodepthset(pagecode[0]-1, pagecode[1]-1);
				}else{
					onedepthset(-1);
				}
			}else{
				onedepthset(-1);
			}
			if(nodelay!==true) close();
		}, (nodelay===true)? 0 : 300);
	}

	//header open
	function open(){
		clearTimeout(closetimer);
		if(isindex && tpm.counsel.opened) return;
		opentimer=setTimeout(function(){
			if(!headeropening){
				headeropening=true;
				$header.stop(true).animate({ height : headeropenheight }, { queue : false, duration : 1000, easing : 'easeInOutExpo', step : headerstep, complete : function(){
					headeropening=false;
				}});
			}
		}, 0);
	}

	//header close
	function close(){
		clearTimeout(opentimer);
		if(isindex && tpm.counsel.opened) return;
		$header.stop(true).animate({ height : headercloseheight }, { queue : false, duration : 750, easing : 'easeOutExpo', step : headerstep, complete : function(){
			for(var i=-1, max=$onedepth.length, $target; ++i<max; ){
				$onedepth[i].css('height', headercloseheight-66);
			}
		}});
		headeropening=false;
	}

	//header animate(open|close) step
	function headerstep(now){
		var height=(now-41)+'px';
		var bgposition='3px '+(headeropenheight-now+4)+'px';
		var opacity=(now-headercloseheight)/(headeropenheight-headercloseheight);
		for(var i=-1, max=$onedepth.length; ++i<max; ){
			$onedepth[i].css('height', height)
			$onedepth[i].data('subcontainer').css({
				backgroundPosition : bgposition,
				opacity : (i==onedepthoverno)? opacity : opacity*0.6
			});
		}
		if(isindex && tpm.archive.opened){
			tpm.archive.$obj.css('top', now-10);
		}
	}

	//set one depth li height to same size
	$onedepth.each(function(){
		$(this).data('subcontainer').css('height', maxsublength*24+30)
	});

	headeropenheight=maxsublength*24+101;

	reset(true);

}


// make side navigation
function makeSideNavi(){

	var $sidenav=$('#sideNav').addClass('sideNavJsMode');
	var $sidenavul=$sidenav.find('ul:first').mouseenter(resettimerclear).mouseleave(resettimerset);

	var $onedepth=$sidenavul.children();
	var onedepthheight=25, twodepthheight=24;
	var resettimer=null, twodepthresettimer=null;
	var onedepthopened=-1;

	for(var i=-1, max=$onedepth.length, j, jmax, fakehtml; ++i<max;){
		fakehtml='';
		$onedepth[i]=$($onedepth[i]).css({
			top : i*onedepthheight,
			height : onedepthheight,
			paddingBottom : 0,
			overflow : 'hidden'
		});
		if($onedepth[i].attr('class')==pagecode[1]){
			pagecode[1]=i+1;
		}
		$onedepth[i].data('link', $onedepth[i].find('a:first')
			.data('no', i)
			.wrap('<span></span>')
			.mouseenter(function(){
				onedepthset($(this).data('no'), true);
			})
			.mouseleave(function(){
				onedepthset(-1, true);
			})
		);
		$onedepth[i].data('sub', $onedepth[i].find('div:first'));
		if($onedepth[i].data('sub').length){
			$('<div class="fakemask"><div class="fake"><div></div></div></div>').insertBefore($onedepth[i].data('sub').find('ul:first'));
			$onedepth[i].data('sub')
				.css({
					display : 'block',
					opacity : 0
				})
				.data('fakemask', $onedepth[i].data('sub').find('div:eq(0)'))
				.data('fake', $onedepth[i].data('sub').find('div:eq(1)').css('top', -twodepthheight))
				.data('item', $onedepth[i].data('sub').find('li'));
			for(j=-1, jmax=$onedepth[i].data('sub').data('item').length; ++j<jmax;){
				$onedepth[i].data('sub').data('item')[j]=$($onedepth[i].data('sub').data('item')[j]);
				if($onedepth[i].data('sub').data('item')[j].attr('class')==pagecode[2]){
					pagecode[2]=j+1;
				}
				$onedepth[i].data('sub').data('item')[j]
					.css('background', 'none')
					.data('no', j)
					.data('parentno', i)
					.data('link', $onedepth[i].data('sub').data('item')[j].find('a'))
					.mouseenter(function(){
						twodepthset($(this).data('parentno'), $(this).data('no'));
					}).mouseleave(function(){
						var me=this;
						twodepthresettimer=setTimeout(function(){
							twodepthset($(me).data('parentno'), -1);
						}, 500);
					});
				fakehtml+='<li class="'+$onedepth[i].data('sub').data('item')[j].attr('class')+'"></li>';
			}
			$('<ul>'+fakehtml+'</ul>').appendTo($onedepth[i].data('sub').data('fake'));
			$('<ul>'+fakehtml+'</ul>').insertBefore($onedepth[i].data('sub').data('fake'));
			$onedepth[i].data('sub').data('fake').data('insideul', $onedepth[i].data('sub').data('fake').find('ul:first'));
			$onedepth[i].data('sub').data('fake').data('insideul').find('li').each(function(){
				var bgpos=(jQuery.ua.ie)? $(this).css('backgroundPositionX')+' '+$(this).css('backgroundPositionY') : $(this).css('backgroundPosition');
				this.style.backgroundPosition=bgpos.replace('0px', '-120px');
			});
			$onedepth[i].data('sub').data('fakemask').css('height', $onedepth[i].data('sub').data('item').length*twodepthheight+42);
			$onedepth[i].data('subheight', $onedepth[i].data('sub').data('item').length*twodepthheight+42);
			$onedepth[i].data('link').click(function(){
				if(pagecode[0]==1) return true;
				onedepthset($(this).data('no'));
				return false;
			});
		}else{
			$onedepth[i].data('sub', null);
			$onedepth[i].data('subheight', 0);
			if((/stylish gallery/i).test($onedepth[i].data('link').text())){
				$onedepth[i].data('link').click(function(){
					openStylishGalleryFlash(this.href);
					return false;
				});
			}
		}
	}
	$sidenavul.css('height', max*onedepthheight);

	function onedepthset(no, isover){
		if(!isover) onedepthopened=no;
		for(var i=-1, max=$onedepth.length; ++i<max; ){
			if(no==i){
				$onedepth[i].data('link').animate({ opacity:1 }, { queue:false, duration:400 });
				if(!isover){
					$onedepth[i].animate({
						top : i*onedepthheight,
						height : $onedepth[i].data('subheight')+onedepthheight
					}, { queue:false, easing:'easeOutExpo', duration:750 });
					if($onedepth[i].data('sub')){
						$onedepth[i].data('sub').animate({ opacity:1 }, { queue:false, easing:'easeInQuad', duration:500 });
					}
				}
			}else{
				if(onedepthopened!=i){
					$onedepth[i].data('link').animate({ opacity:0 }, { queue:false, duration:400 });
				}
				if(!isover){
					$onedepth[i].animate({ 
						top : (i>no && $onedepth[no].data('subheight'))? i*onedepthheight+$onedepth[no].data('subheight')-7 : i*onedepthheight,
						height : onedepthheight
					}, { queue:false, easing:'easeOutExpo', duration:500 });
					if($onedepth[i].data('sub')){
						$onedepth[i].data('sub').animate({ opacity:0 }, { queue:false,  easing:'easeOutSine', duration:500 });
						twodepthset(i, -1);
					}
				}
			}
		}
		if(!isover){
			$sidenavul.animate({
				height : max*onedepthheight+$onedepth[no].data('subheight')
			}, { queue:false, easing:'easeOutExpo', duration:750 });
		}
	}

	function twodepthset(no, subno){
		if(!$onedepth[no].data('sub')) return;
		clearTimeout(twodepthresettimer);
		if(no==pagecode[1]-1 && subno==-1){
			subno=pagecode[2]-1;
		}
		if(isNaN(subno)) subno=-1;
		$onedepth[no].data('sub').data('fake').animate({ 
			top : subno*twodepthheight
		}, {
			queue : false,
			easing : 'easeOutExpo',
			duration : 400,
			step : function(now, fx){
				$(fx.elem).data('insideul').css('top', -now);
			}
		});
		/*
		for(var i=-1, max=$onedepth[no].data('sub').data('item').length; ++i<max;){
			$onedepth[no].data('sub').data('item')[i].data('link').stop().animate({ opacity:(i==subno)? 1 : 0 }, { queue:false, duration:(i==subno)? 500 : 200 });
		}
		*/
	}

	function resettimerclear(){
		clearTimeout(resettimer);
	}

	function resettimerset(){
		resettimer=setTimeout(function(){
			reset();
		}, 1000);
	}

	function reset(){
		if(pagecode[0] == 'AG' &&pagecode[1] == 0) return;

		//if(pagecode[0]>0 && pagecode[0]<topNavLength){
			onedepthset(pagecode[1]-1);
			twodepthset(pagecode[1]-1, pagecode[2]-1);
		// }
	}

	productfinder.initialize();

	reset();

}


//store detail
var storedetail={

	$obj : null,
	$btn : null,

	$layer : null,
	$layerclosebtn : null,

	width : 814,
	height : 717,
	opened : false,

	open : function(src){
		if(!storedetail.$layer){
			storedetail.$layer=$('<div id="mapView"></div>').appendTo('#content');
			storedetail.$layerclosebtn=$('<button class="closebtn">Close</button>').click(storedetail.close);
			storedetail.$layerinside=$('<div class="inside"></div>')
				.append('<iframe src="'+src+'" frameborder="0" width="'+storedetail.width+'" height="'+storedetail.height+'" marginwidth="0" marginheight="0" scrolling="no"></iframe>')
				.append(storedetail.$layerclosebtn).appendTo(storedetail.$layer);
		}
		if(!storedetail.opened){
			storedetail.$layer.show();
			storedetail.$layerinside.find('iframe')[0].src=src;
			storedetail.$layer.animate({ height:storedetail.height+6 }, { queue:false, duration:1000, easing:'easeInOutExpo' });
			if(scrolltarget.scrollTop>204){
				$(scrolltarget).animate({ scrollTop:204 }, { queue:false, duration:1000, easing:'easeInOutExpo' })
			}
			storedetail.opened=true;
		}else{
			storedetail.close();
		}
		return false;
	},

	close : function(){
		storedetail.$layer.animate({ height:0 }, { queue:false, duration:500, easing:'easeInOutExpo', complete:function(){storedetail.$layer.hide();} });
		storedetail.opened=false;
	},

	initialize : function(){
		storedetail.$obj=$('#sideNav p:last');
		storedetail.$btn=storedetail.$obj.find('a').click(storedetail.open);
	}

}


//product finder
var productfinder={

	$obj : null,
	$btn : null,

	$layer : null,
	$layerclosebtn : null,

	width : 716,
	height : 445,
	opened : false,

	open : function(){
		if(!productfinder.$layer){
			productfinder.$layer=$('<div id="productFinder"></div>').appendTo('#content');
			productfinder.$layerclosebtn=$('<button class="closebtn">Close</button>').click(productfinder.close);
			productfinder.$layerinside=$('<div class="inside"></div>')
				.append('<iframe src="/product/ifr_product_finder.asp" frameborder="0" width="'+productfinder.width+'" height="'+productfinder.height+'" marginwidth="0" marginheight="0" scrolling="no"></iframe>')
				.append(productfinder.$layerclosebtn).appendTo(productfinder.$layer);
		}
		if(!productfinder.opened){
			productfinder.$layer.show();
			productfinder.$layer.animate({ height:productfinder.height+4 }, { queue:false, duration:1000, easing:'easeInOutExpo' });
			if(scrolltarget.scrollTop>204){
				$(scrolltarget).animate({ scrollTop:204 }, { queue:false, duration:1000, easing:'easeInOutExpo' })
			}
			productfinder.opened=true;
		}else{
			productfinder.close();
		}
		return false;
	},

	close : function(){
		productfinder.$layer.animate({ height:0 }, { queue:false, duration:500, easing:'easeInOutExpo', complete:function(){productfinder.$layer.hide();} });
		productfinder.opened=false;
	},

	initialize : function(){
		productfinder.$obj=$('#sideNav p:last');
		productfinder.$btn=productfinder.$obj.find('a').click(productfinder.open);
	}

}

//open catalog
function opencatalog(url){
	/* 2011 12 22 수정 - 사이즈, 리사이즈 가능, 스크롤바 가능 */
	//window.open(url, 'catalogpopup', 'width=1109, height=773, toolbar=no, scrollbars=yes, resizable=yes');
	window.open(url, 'catalogpopup', 'width=1169, height=773, toolbar=no, scrollbars=yes, resizable=yes');
}
