//---------------------------------------------------------
//   ¹è³Ê °ü·Ã Å¬·¡½º
//---------------------------------------------------------

	//---------------------------------------------------------
	//   »ý¼ºÀÚ 
	//---------------------------------------------------------
  function Banner(inst_Common){

		var form;
		var add;
		var max_num;
		var max_goods;
		var show;
		var count;
		var ImgCnt; 
  var anibanarray; // ¾Ö´Ï¹è³Ê ¹è¿­

	
			//  °ø¿ë Å¬·¡½º ÀÎ½ºÅÏ½º ·Îµù
		this.inst_Common = inst_Common;
		this.add = 0;
		this.max_goods = 15;  // ÄíÅ°¿¡ ´ãÀ» ÃÖ´ë »óÇ°°¹¼ö
		this.show = document.getElementById("show");
		this.count = document.getElementById("count");
  this.anibanarray = new Array(); // ¾Ö´Ï¹è³Ê¿ë ¹è¿­
    
  //  ÇÃ·¹ÀÌ ¸ðµå 
  var playmode;
  this.playmode = false; // trueÀÏ °æ¿ì ÀÚµ¿ ÇÃ·¹ÀÌ , falseÀÏ °æ¿ì ÇÃ·¹ÀÌ ¸ØÃã  

  // ÀÚµ¿ ÇÃ·¹ÀÌ ¹è³Ê ÀÎ½ºÅÏ½º 
  var inst_autobans;
  this.inst_autobans = null;
  
  // ¹è³Ê ¹è¿­ÀÇ ÇöÀç Ä¿¼­
  var bancursor;
  this.bancursor=0;
  
  // »óÇ°ÀÌ¹ÌÁö ±âº» °æ·Î 
  var GoodsImgUrl;
  this.GoodsImgUrl=""; // ÀÌ¹ÌÁö ÃÊ±âÈ­ ¸Þ¼Òµå¿¡¼­ ¼³Á¤µÊ 

  var slideLayer;
  this.slideLayer = ''; // ±×³É ±âº» ·¹ÀÌ¾î¸í 

  var slideTop;
  this.slideTop = 0; // ½½¶óÀÌµù ·¹ÀÌ¾î Top ºÎÅÍ ¾Æ·¡·Î ³»·Á°¥ »çÀÌÁî ÁöÁ¤ 
  
  // ¿À´Ãº» »óÇ° id °ªÀÇ ÇÁ¸®ÇÈ½º 
  var todayViews_id_prefix;
  this.todayViews_id_prefix=null;

	// function - End
}

Banner.prototype={

  //-----------------------------------------------------------------------------
  //  »óÇ° ÀÌ¹ÌÁö °æ·Î Àü¿ª ¼¼ÆÃ ¸Þ¼Òµå 
  //-----------------------------------------------------------------------------
  SetGoodsImageUrl : function(ImgUrl) { this.GoodsImgUrl = ImgUrl; },

  //-----------------------------------------------------------------------------
  //  ½½¶óÀÌµù ¹è³Ê °ü·Ã ¼³Á¤ Àû¿ë  
  //-----------------------------------------------------------------------------
  SetSlideInfo : function(slideLayer, slideTop) { 
    this.slideLayer = slideLayer; // ±×³É ±âº» ·¹ÀÌ¾î¸í 
    this.slideTop = slideTop; // ½½¶óÀÌµù ·¹ÀÌ¾î Top ºÎÅÍ ¾Æ·¡·Î ³»·Á°¥ »çÀÌÁî ÁöÁ¤ 
  },

		//-----------------------------------------------------------------------------
		//    ¹è³Ê ·¹ÀÌ¾î ¿òÁ÷ÀÌ´Â ¸Þ¼­µå
		//-----------------------------------------------------------------------------
		SlidingBanner : function() {

				var obj_layer = document.getElementById('floater')

				// ÄíÅ°¿¡¼­ »óÇ°Á¤º¸ °¡Á®¿À±â
				str = this.inst_Common.GetCookie('banner_g');

				// ¿À´Ãº» »óÇ°ÀÌ ÀÖÀ»¶§¸¸ Ãâ·Â
				if (str == "") { obj_layer.style.display="none"; }
				else { obj_layer.style.display="block"; }

				windowHeight = document.body.clientHeight;
				windowWidth = document.body.clientWidth;
				scrollY = document.documentElement.scrollTop;
				obj_layer.style.top = 50 + scrollY;

		// function - End
		},

  //-----------------------------------------------------------------------------
  //  Æ¯Á¤ ·¹ÀÌ¾î¸¦ Æ¯Á¤ À§Ä¡¿¡ °íÁ¤ : onscroll  ¿ë 
  //-----------------------------------------------------------------------------
  LayerSliding : function() {

    var openflag = this.inst_Common.GetCookie('CookieLayer');

    // ¿À´Ãº» »óÇ° ÇÏ´ÜBarÀÇ ³ôÀÌ ¸¸Å­ À§Ä¡ Á¶Àý 
        // 1. Á¢ÇôÁø »óÅÂ
    if (openflag == 'false') { var TopLength_ = 144; }
    
    // 2. ÆìÁø»óÅÂ
    else if (openflag == 'true') { var TopLength_ = -6; }

    // 3. ÄíÅ°°¡ ¾Æ¿¹ ¾øÀ» ¶§ Ã³À½ Á¢±ÙÇÑ »ç¶÷ 
    else { var TopLength_ = 144; }

    var Obj = document.getElementById(LayerName);
    Obj.style.position="absolute";
    Obj.style.zIndex=9999;

				var ST = parseFloat(document.documentElement.scrollTop);//  ÇöÀç ½ºÅ©·ÑµÈ »óÅÂ¿¡¼­ÀÇ ÃÖ»ó´Ü
				var SH = parseFloat(document.documentElement.clientHeight);//  ÇöÀç ½ºÅ©·ÑµÈ »óÅÂ¿¡¼­ÀÇ ÃÖ»ó´Ü

				Obj.style.top = (ST+SH - 172 + TopLength_);				//  ·¹ÀÌ¾îÀÇ topÀ» ±³Ã¼ 

  // function - End
  },

		//-----------------------------------------------------------------------------
		//    ¹è³Ê ·¹ÀÌ¾î¿¡ »óÇ°Ãâ·Â
		//-----------------------------------------------------------------------------
		showGoods : function(state,width,cnt) {

				// 11¹ø ½ºÅ² ºÎÅÍ´Â _head.tpl¿¡ inst_Shop.ImgCnt·Î Àû¿ë
				// 10¹ø ½ºÅ²±îÁö´Â _head.tpl °ú detail.tpl µÎ±ºµ¥ inst_Banner.showGoods('',inst_Shop.SlidingWidth,5);
				// 2009-02-24 ³²ÇüÁø
				this.ImgCnt = cnt == undefined ? 4:cnt;// ½½¶óÀÌµù ¹è³Ê ÀÌ¹ÌÁö °¹¼ö

				this.show.innerHTML="";
				var str,goods_data,goods_info,co;
				// ÄíÅ°¿¡¼­ »óÇ°ÄÚµå¿Í ÀÌ¹ÌÁö °¡Á®¿À±â
				str = this.inst_Common.GetCookie('banner_g');
				goods_array = str.split('|');

				// ÃÑ»óÇ° °¹¼ö
				this.max_num = goods_array.length-1;

				goods_data = "";
				goods_count = 0;
				co = 0;

				if ( this.add > this.max_num ) { this.add = 1 }
				if ( this.add < 0 ) { this.add = this.max_num-1 }

				for(i = 0+this.add; i <this.ImgCnt+this.add ; i++) 	{
						if ( goods_array[i] != null && goods_array[i] != '' ) {
								goods_info = goods_array[i].split('^');
								goods_data = goods_data+"<div style='padding:2px 0;'><a href='http://"+document.domain+"/?action=Detail&GoodsCode="+goods_info[0]+"'><img src='"+goods_info[1]+"' width='"+width+"px' style='cursor:hand; border-bottom:1px solid #E7E7E7;'></a></div>";
								co++;
						}
				}

				for(i = 0; i < this.ImgCnt-co ; i++) 	{
						if ( goods_array[i] != null && goods_array[i] != '' && this.max_num > this.ImgCnt ) {
								goods_info = goods_array[i].split('^');
								goods_data = goods_data+"<div style='padding:2px 0;'><a href='http://"+document.domain+"/?action=Detail&GoodsCode="+goods_info[0]+"'><img src='"+goods_info[1]+"' width='"+width+"px' style='cursor:hand; border-bottom:1px solid #E7E7E7;'></a></div>";
						}
				}

				this.show.innerHTML="<div>"+goods_data+"</div>";
				this.count.innerHTML=this.max_num;

		},

		//-----------------------------------------------------------------------------
		//   ÄíÅ°±Á±â
		//-----------------------------------------------------------------------------
		B_SetCookie : function(sName, sValue) {

				var goods_info,goods_array,goods_back;

				goods_info = this.inst_Common.GetCookie(sName);
				goods_array = goods_info.split('|');

				// °°Àº»óÇ°ÄÚµåÀÇ »óÇ°ÀÌ ÀÖÀ¸¸é ÆÐ½º~
				if ( this.inst_Common.in_array(goods_array, sValue) === false) { return false; }

				//  ÃÖ´ë 15°³±îÁö¸¸ ÄíÅ°¿¡ ´ãÀ½
				if (this.max_num >= this.max_goods) {
						goods_info = "";
						for(i = 0; i <this.max_goods-1 ; i++) 	{
								goods_info = goods_info + goods_array[i] + "|";
						}
				}

				sValue = sValue + "|" + goods_info; 
    sValue = this.inst_Common.CutTail(sValue,"|",1);

				this.inst_Common.SetCookie(sName,sValue);
		},

		//-----------------------------------------------------------------------------
		//   »óÇ° À§,¾Æ·¡ ÀÌµ¿
		//-----------------------------------------------------------------------------
		AddCount : function(no,AddCount) {
				if (this.max_num > this.ImgCnt) {
						this.add = this.add+no;
						this.showGoods('',AddCount,this.ImgCnt);
				}
		},



//===================================================================================================================
// 
//                                                                      ·Ñ¸µ ¹è³Ê °ü·Ã ¸Þ¼Òµåµé 2009-04-21 
//
//===================================================================================================================


  //-----------------------------------------------------------------------------
  //  ¹è³Ê ÇÃ·¹ÀÌ
  //-----------------------------------------------------------------------------
  PlayBan : function(turm) {
   
    if (this.playmode==false) {
      this.inst_autobans = window.setInterval("inst_Banner.NextBan();", turm); 
      this.playmode = true;
    }

  // function - End
  },

  //-----------------------------------------------------------------------------
  //  ´ÙÀ½ ¹è³Ê 
  //-----------------------------------------------------------------------------
  NextBan : function() {

    for (var i=0; i<this.anibanarray.length; i++) {
      if( this.bancursor==i ) {
       this.Filter_A();
       document.getElementById(this.anibanarray[i]).style.display='block';
      }
      else { document.getElementById(this.anibanarray[i]).style.display='none'; }
    }
    this.PlusCursor();
 
  // function - End
  },

  //-----------------------------------------------------------------------------
  //  ¹è³Ê ¸ØÃã 
  //-----------------------------------------------------------------------------
  StopBan : function() {
   
    if (this.playmodegoods==true) {
      window.clearInterval(this.inst_autogoods); 
      this.playmodegoods = false;
    }

  // function - End
  },

  //-----------------------------------------------------------------------------
  //  ÀÌÀü ¹è³Ê 
  //-----------------------------------------------------------------------------
  PrevBan : function() {
   
    if (this.playmodegoods==true) {
      window.clearInterval(this.inst_autogoods); 
      this.playmodegoods = false;
    }

  // function - End
  },

  //-----------------------------------------------------------------------------
  //  ¹è³Ê ·Îµù
  //-----------------------------------------------------------------------------
  LoadBan : function() {
   
    if (this.playmodegoods==true) {
      window.clearInterval(this.inst_autogoods); 
      this.playmodegoods = false;
    }

  // function - End
  },

  //-----------------------------------------------------------------------------
  //  Ä¿¼­ Áõ°¡ 
  //-----------------------------------------------------------------------------
  PlusCursor : function() {
    
    //  ÇÑ¹ÙÄû µ¹¸é Ã³À½À¸·Î
    if(this.bancursor+1 >= this.anibanarray.length ) { this.bancursor = 0; }
    else { this.bancursor++; }

  // function - End
  },

  //-----------------------------------------------------------------------------
  //  Ä¿¼­ °¨¼Ò 
  //-----------------------------------------------------------------------------
  MinusCursor : function() {

    //  ÇÑ¹ÙÄû µ¹¸é Ã³À½À¸·Î
    if(this.bancursor-1 < 0 ) { this.bancursor = this.anibanarray.length-1; }
    else { this.bancursor--; }

  // function - End
  },

  //-----------------------------------------------------------------------------
  //  ÆäÀÌµå¾Æ¿ô È¿°ú ÁÖ´Â ÇÊÅÍ
  //-----------------------------------------------------------------------------
  Filter_A : function() {
    document.getElementById(this.anibanarray[this.bancursor]).style.filter = "blendTrans(duration=3)";
    document.getElementById(this.anibanarray[this.bancursor]).style.filter = "blendTrans(duration=crossFadeDuration)";
    document.getElementById(this.anibanarray[this.bancursor]).filters.blendTrans.Apply();
    document.getElementById(this.anibanarray[this.bancursor]).filters.blendTrans.Play();
  // function - End
  },

//===================================================================================================================
// 
//                                                                      ¿À´Ãº»»óÇ° °ü·Ã ½ºÅ©¸³Æ® 2009-05-11 
//
//===================================================================================================================

  //-----------------------------------------------------------------------------
  //  ÄíÅ°¿¡ ÀúÀåµÈ ¿À´Ãº» »óÇ° Á¤º¸ ¹®ÀÚ¿­À» ¹è¿­·Î ¸¸µé¾î¼­ ¸®ÅÏÇØÁØ´Ù.
  //-----------------------------------------------------------------------------
  GetCookGoods : function() {
  
    // ÄíÅ°¿¡ ´ã±ä ¿À´Ãº» »óÇ°Á¤º¸ ¹®ÀÚ¿­ 
    var temp = this.inst_Common.GetCookie('todaygoods');
    if (!temp.trim()) { return false; }
    var temp2 = temp.split("|")

    // ÄíÅ°¿¡¼­ »óÇ°ÄÚµå¿Í ÀÌ¹ÌÁö °¡Á®¿À±â
    var goods_array = new Array();
    goods_array['code'] = new Array();
    goods_array['img'] = new Array();
    goods_array['opt'] = new Array();
    
    // »óÇ° Á¤º¸ ¹®ÀÚ¿­À» ¹è¿­·Î 
    for (var i=0; i<temp2.length; i++) {
      var temp3 = temp2[i].split("^");
      goods_array['code'][i] = temp3[0];
      goods_array['img'][i] = temp3[1];
      goods_array['opt'][i] = temp3[2];
    // loop - End
    }
    return goods_array;

  // function - End
  },

  //-----------------------------------------------------------------------------
  //  ¿À´Ãº» »óÇ°À» ·¹ÀÌ¾î¿¡ Ãâ·Â 
  //-----------------------------------------------------------------------------
  ViewToDayGoods : function(prefix, maxlength ,todayviews_ID ) {
    
    // id °ªÀÇ ÇÁ¸®ÇÈ½º¸¦ Àü¿ªÀ¸·Î 
    this.todayViews_id_prefix = prefix;

    // ¿À´Ãº»»óÇ° ÃÑ°¹¼ö , ÄíÅ°°¡ ¾ø´Â °æ¿ì ±×³É ¸®ÅÏÇÏ±â ¶§¹®¿¡ ¿À´Ãº» »óÇ°¼ö¸¦ À§¿¡¼­ Ç×»ó 0À¸·Î ÃÊ±âÈ­ ÇÑ´Ù.
    var today_goods_count = 0;
    var todayviews = document.getElementById(todayviews_ID);
    todayviews.innerHTML = today_goods_count;
   
    // »óÇ° ¹è¿­
    goods_array = new Array();
    goods_array = this.GetCookGoods();

    // ¿À´Ãº» »óÇ°ÀÌ ¾øÀ» °æ¿ì ¸ØÃã
    if (goods_array == false) { return false; }

    // Ã¼Å©¹Ú½º °´Ã¼
    var checkgoods = document.getElementsByName('checkgoods');
    
    // ÇöÀç ¿À´Ãº»»óÇ° ¸Å´ºÀÇ ÀÌ¹ÌÁö Ãâ·Â ÃÖ´ë °¹¼ö¸¸Å­ ·çÇÁ 
    for (var i=0; i< maxlength; i++) {
      
      // ÇÏ³ªÀÇ »óÇ° ·¹ÀÌ¾î 
      var goods_layer = document.getElementById(prefix+i);

      //  ÇÏ³ªÀÇ »óÇ° ·¹ÀÌ¾î¿¡ ÀÚ½Ä ³ëµåµé¸¸Å­ ·çÇÁµ¹´Ù°¡ 
      //  ÀÌ¹ÌÁö¸¦ ¸¸³ª¸é ÀÌ¹ÌÁö °æ·Î¸¦ ÇöÀç »óÇ°À¸·Î º¯°æÇØÁØ´Ù.
      for (var j=0; j<goods_layer.childNodes.length; j++) {

        // ÀÌ¹ÌÁö Å×±×¸¦ ¸¸³ª¸é 
        if (goods_layer.childNodes[j].nodeName == 'IMG') {

          // »óÇ°ÀÌ¹ÌÁö°¡ ÀÖÀ» °æ¿ì¸¸ ÇØ´ç ÀÌ¹ÌÁö·Î ±³Ã¼ 
          if( goods_array['code'][i]!='undefined' && goods_array['code'][i]!='' && goods_array['code'][i]  ){ 
            goods_layer.childNodes[j].src = this.GoodsImgUrl+goods_array['img'][i];
            goods_layer.childNodes[j].style.width = '84px';
            goods_layer.childNodes[j].style.height = '84px';
            checkgoods[i].value = goods_array['code'][i];
            today_goods_count ++;
            
            // ¿É¼ÇÀÌ ÀÖ´Â »óÇ°Àº ¼±ÅÃ ºÒ°¡·Î 
            if ( goods_array['opt'][i]=='y') { checkgoods[i].disabled=true;  }

          }
          // ¹è¿­¿¡ µî·ÏµÈ »óÇ°ÀÌ ¾øÀ»°æ¿ì Ã¼Å©¹Ú½º¸¦ »ç¿ë ºÒ°¡·Î 
          else { checkgoods[i].disabled=true; }

        }

      // loop - End
      }

    // loop - End
    }
    
    // ¿À´Ãº» »óÇ° °¹¼ö Ãâ·Â
    todayviews.innerHTML = today_goods_count;

  // function - End
  },

  //-----------------------------------------------------------------------------
  //  ¿À´Ãº» »óÇ° Å¬¸¯ ½Ã ÇØ´ç »óÇ°À¸·Î ÀÌµ¿ 
  //-----------------------------------------------------------------------------
  GotoGoodsToday : function(node) {

    // »óÇ° ¹è¿­
    goods_array = new Array();
    goods_array = this.GetCookGoods();
    //var temp = node.id.split(this.todayViews_id_prefix);
    //var goods_number = temp[1];
    var goods_number = node;

    if (goods_array['code'][goods_number]!='' && goods_array['code'][goods_number] && goods_array['code'][goods_number]!='undefined') {
      location.href="/?action=Detail&GoodsCode="+goods_array['code'][goods_number];
    }
  
  // function - End
  }


// class - End
}
