﻿function offerTitleRepace(buf)
{
	buf = replaceText(buf, "%", "%25");
	buf = replaceText(buf, "&", "%26");
	buf = replaceText(buf, "'", "%27");
	buf = replaceText(buf, "\"", "%22");
	buf = replaceText(buf, "/", "%252F");
	buf = replaceText(buf, '`', '_');
	buf = replaceText(buf, '~', '_');
	buf = replaceText(buf, '!', '_');
	buf = replaceText(buf, '@', '_');
	buf = replaceText(buf, '^', '_');
	buf = replaceText(buf, '*', '_');
	buf = replaceText(buf, '(', '_');
	buf = replaceText(buf, ')', '_');
	buf = replaceText(buf, '=', '_');
	buf = replaceText(buf, '+', '_');
	buf = replaceText(buf, ' ', '_');
	buf = replaceText(buf, '|', '_');
	buf = replaceText(buf, '[', '_');
	buf = replaceText(buf, ']', '_');
	buf = replaceText(buf, '{', '_');
	buf = replaceText(buf, '}', '_');
	buf = replaceText(buf, ';', '_');
	buf = replaceText(buf, ':', '_');
	buf = replaceText(buf, ',', '_');
	buf = replaceText(buf, '.', '_');
	buf = replaceText(buf, '<', '_');
	buf = replaceText(buf, '>', '_');
	buf = replaceText(buf, '?', '_');
	buf = replaceText(buf, '\t','_');
	buf = replaceText(buf, '__','_');
	buf = replaceText(buf, '__','_');
	return buf;
}

//YUI Widget 
function displayOfferList()
{
	YAHOO.namespace("EC");
	YAHOO.namespace("EC.widget");
	EC=YAHOO.EC;$D=YAHOO.util.Dom;
	$E=YAHOO.util.Event;
	$U=YAHOO.util;EC.widget.SimpleScroll=new function(){var $Y=YAHOO.util;var defConfig={delay:2,speed:20,startDelay:2,scrollItemCount:1};this.decorate=function(aa,ba){aa=YAHOO.util.Dom.get(aa);ba=EC.applyIf(ba||{},defConfig);var ca={};var da=null,pause=false;var ea=new $U.CustomEvent("onScroll",ca,false,$U.CustomEvent.FLAT);if(ba.onScroll){ea.subscribe(ba.onScroll);}
	else{ea.subscribe(function(){for(var i=0;i<ba.scrollItemCount;i++){aa.appendChild(aa.getElementsByTagName("li")[0]);}});}
	var fa=function(){if(pause){return;}
	aa.scrollTop+=2;var lh=ba.lineHeight||aa.getElementsByTagName("li")[0].offsetHeight;if(aa.scrollTop%lh<=1){clearInterval(da);ea.fire();aa.scrollTop=0;setTimeout(ga,ba.delay*1000);}};var ga=function(){var lh=ba.lineHeight||aa.getElementsByTagName("li")[0].offsetHeight;if(aa.scrollHeight-aa.offsetHeight>=lh){da=setInterval(fa,ba.speed);}};$E.on(aa,"mouseover",function(){pause=true;});$E.on(aa,"mouseout",function(){pause=false;});setTimeout(ga,ba.startDelay*1000);ca.onScroll=ca.subscribeOnScroll;return ca;};}
	EC.applyIf=function(ha,ia){if(ha&&ia&&typeof ia=='object'){for(var p in ia){if(!YAHOO.lang.hasOwnProperty(ha,p))ha[p]=ia[p];}}
	return ha;}
}

var imgPointer = 0; //실제로 가르킴
function prevProductList()
{
	imgPointer--;
	if (imgPointer<0)
	{
		imgPointer = 20;
	}
	showProductList(imgPointer);
	//alert(imgPointer);
}

function nextProductList()
{
	imgPointer++;
	if (imgPointer>20)
	{
		imgPointer = 0;
	}
	showProductList(imgPointer);
	//alert(imgPointer);
}

function showProductList(imgPointer)
{
	var imgCount=1; //출력한갯수

	while(1)
	{

		// remove all children from element
		
		
		var catalogNm = productList[imgPointer].catalogNm;
		if (catalogNm.length > 30)
		{
			catalogNm= catalogNm.substr(0,30) + "...";
		}
		/*
		if (catalogNm.indexOf(" ")==-1)
		{
			catalogNm = catalogNm.substr(0, 15) + " " + catalogNm.substr(15);
		}*/


		imgCount++;
		imgPointer++;

		//5개 채우면 정지
		if (imgCount>5)
		{
			break;
		}

		//21번 포인터 일경우 0번으로 돌림
		if (imgPointer==21)
		{
			imgPointer=0;
		}
	}
	setTimeout("nextProductList()",5000);

}

function changeFeatured(target)
{
	//alert(target);
	var switch1Img = document.getElementById('featuredSwitch1');
	var switch2Img = document.getElementById('featuredSwitch2');
	//var switch3Img = document.getElementById('featuredSwitch3');
	var div1 = document.getElementById('featured_1');
	var div2 = document.getElementById('featured_2');
	//var div3 = document.getElementById('featured_3');

	if (target==1)
	{
		switch1Img.src = "http://image.ec21.com/img/ec/main/num01_on.gif";
		switch2Img.src = "http://image.ec21.com/img/ec/main/num02_off.gif";
		//switch3Img.src = "http://image.ec21.com/img/ec/main/num03_off.gif";
		div1.style.display = "block";
		div2.style.display = "none";
		//div3.style.display = "none";
	}
	else if (target==2)
	{
		switch1Img.src = "http://image.ec21.com/img/ec/main/num01_off.gif";
		switch2Img.src = "http://image.ec21.com/img/ec/main/num02_on.gif";
		//switch3Img.src = "http://image.ec21.com/img/ec/main/num03_off.gif";
		div1.style.display = "none";
		div2.style.display = "block";
		//div3.style.display = "none";
	}
	/*
	else if (target==3)
	{
		switch1Img.src = "http://image.ec21.com/img/ec/main/num01_off.gif";
		switch2Img.src = "http://image.ec21.com/img/ec/main/num02_off.gif";
		switch3Img.src = "http://image.ec21.com/img/ec/main/num03_on.gif";
		div1.style.display = "none";
		div2.style.display = "none";
		div3.style.display = "block";
	}
	*/
}

function changeStatusFeaturedAutoSwitcher(status)
{
	var isAuto = document.getElementById('featuredAuto');

	isAuto.value = status;

}


/* CategoryList */
function displayNoneCategorySubTimeOut(categorymId)
{
	//setTimeout("displayNoneCategorySub("+categorymId+");", 500);
	displayNoneCategorySub(categorymId);
}

function displayNoneCategorySub(categorymId)
{
	$('catetitle'+categorymId).style.backgroundPosition = "0 0";
	$('catetitle'+categorymId).getElementsByTagName("div")[0].style.display = 'none';
}

function displayBlankCategorySubTimeOut(categorymId)
{
	//setTimeout("displayBlankCategorySub("+categorymId+");", 500);
	displayBlankCategorySub(categorymId);
}

function displayBlankCategorySub(categorymId)
{
	var categoryTitle = $('catetitle'+categorymId);
	var categorySub = categoryTitle.getElementsByTagName("div")[0];

	if ((categoryTitle.className).indexOf("double")>-1)
	{
		categoryTitle.style.backgroundPosition = "0 -37px";
	}
	else
	{
		categoryTitle.style.backgroundPosition = "0 -28px";
	}

	categorySub.style.display = "";
}

function initCategoryList() {
    var k = 0;
    var allDiv = document.getElementsByTagName("li");
    for (var j = 0; j < allDiv.length; j++) {
        if (allDiv[j].className == "catetitle") {
            k++;
         }
     }
        for (i = 1; i <= k  ; i++) {
        $('catetitle' + i).setAttribute("index", i);
        $('catetitle' + i).onmouseover = function() { displayBlankCategorySubTimeOut(this.getAttribute("index")); };
        $('catetitle' + i).onmouseout = function() { displayNoneCategorySubTimeOut(this.getAttribute("index")); };

        var categorySub = $('catetitle' + i).getElementsByTagName("div")[0];
        categorySub.setAttribute("index", i);
        categorySub.onmouseover = function() { displayBlankCategorySubTimeOut(this.getAttribute("index")); };
        categorySub.onmouseout = function() { displayNoneCategorySubTimeOut(this.getAttribute("index")); };
    }
}
/* /CategoryList */
