function goUrl(url, target)
{
  if (url != null && url.length > 0) {
    window.open(url, target);
  }
}

// ------------------------------ ÁÖ¿ä»ç¾÷ Start ------------------------------//


function expandEventList()
{
	eventViewerMouseOver();

	var eventListSize = $("div.eventList").length;

	$("#expEventListBG").show();
	$("#expEventListBG").height((parseInt(eventListSize/4)+1) * 150 + 10);

	var vTop = 0, vLeft = 0;
	for(var i=0; i<eventListSize; i++)
	{
		vTop = parseInt(i/4) * 150;
		vLeft = (i%4) * 230;
		$("#eventList_" + (i+1)).css("position", "absolute").unbind("mouseout").show().css("top",300 + vTop).css("left", 50 + vLeft).css("z-index", 15001);
	}
}

function collapseEventList()
{
	$("#expEventListBG").hide();

	var eventListSize = $("div.eventList").length;
	var eventObj;
	for(var i=0; i<eventListSize; i++)
	{
		eventObj = $("#eventList_" + (i+1)).css({position:"relative",top:0,left:0}).bind("mouseout", startSlideEventImage);
		if(currentEventSeq == (i+1))
		{
			eventObj.show();
		}
		else
		{
			eventObj.hide();
		}
	}
	startSlideEventImage();
}

var sizeEventList = 0;
var currentEventSeq = 1;
var loopEventImages;
var eventOffsetTop = 0;
var eventOffsetLeft = 0;
function slideEventImage()
{
  if (++currentEventSeq > sizeEventList) {
    currentEventSeq = 1;
  }

  for( var i = 0; i < sizeEventList; i++) {
    if (currentEventSeq == (i + 1)) {
      if($("#eventSeq_" + currentEventSeq + "_on").is(":hidden"))
      {
        $("#eventSeq_" + currentEventSeq + "_on").show();
        $("#eventSeq_" + currentEventSeq + "_off").hide();
        $("#eventList_" + currentEventSeq).show();
      }
    } else {
      if($("#eventSeq_" + (i + 1) + "_on").is(":visible"))
      {
        $("#eventSeq_" + (i + 1) + "_on").hide();
        $("#eventSeq_" + (i + 1) + "_off").show();
        $("#eventList_" + (i + 1)).hide();
      }
    }
  }
  
  /*
  if(currentEventSeq == 1)
  {
    if($("#eventList_pre").length == 0)
    {
      var lastEvent = $("#eventList_" + sizeEventList);
      var bg = "\"" + lastEvent.css("background-image") + " no-repeat\"";
      $("#cnepop").prepend("<div id='eventList_pre' style='background:" + bg + ";'></div>");
      $("#eventList_pre").width(lastEvent.width()).height(lastEvent.height());
    }
    $("#eventList_pre").show();
    $("#eventList_" + sizeEventList).hide();
  }
  * /

  $("#eventList_" + currentEventSeq).css({position:"absolute", top:eventOffsetTop, left:eventOffsetLeft}).show(1000);

  window.setTimeout( function()
  {
    var eventJQuery;
    for(i = 0; i < sizeEventList; i++) {
      eventJQuery = $("#eventList_" + (i + 1));
      if(currentEventSeq == (i + 1))
      {
        if(eventJQuery.is(":hidden"))
        {
          eventJQuery.css({position:"relative", top:0, left:0}).show();
        }
      }
      else
      {
        eventJQuery.hide();
      }
    }

/*
    if(currentEventSeq == 1)
    {
      $("eventList_pre").hide();
    }
* /    
  }, 1200);
  
  */
}

function changeEventImage(eventSeq)
{
  currentEventSeq = eventSeq;
  $(".eventList").each(function(i){
    if(currentEventSeq == (i+1))
    {
      if($(this).is(":hidden"))
      {
        $("#eventSeq_" + (i + 1) + "_on").show();
        $("#eventSeq_" + (i + 1) + "_off").hide();
        $(this).show();
      }
    }
    else
    {
      if($(this).is(":visible"))
      {
        $("#eventSeq_" + (i + 1) + "_on").hide();
        $("#eventSeq_" + (i + 1) + "_off").show();
        $(this).hide();
      }
    }
  });
}

function startSlideEventImage()
{
  if(loopEventImages == null)
  {
    loopEventImages = setInterval("slideEventImage()", 5000);
  }
}

function eventSeqMouseOver(eventSeq)
{
  clearInterval(loopEventImages);
  changeEventImage(eventSeq);
  loopEventImages = null;
}

function eventViewerMouseOver()
{
  clearInterval(loopEventImages);
  loopEventImages = null;
}
// ------------------------------ ÁÖ¿ä»ç¾÷ End ------------------------------//



// ------------------------------ Ãæ³² ÀÎ»çÀÌµå Start ------------------------------//
var sizeInsideList = 0;
var currentInsideSeq = 1;
var loopInside;

function slideInside()
{
  var startIdx;
  var viewIdx;
  $("#absInsideView dd").hide();
  $("#randomNews dd:visible").each( function()
  {
    viewIdx = $("#randomNews dd").index(this);
    if (!startIdx) {
      startIdx = viewIdx + 4;
    }
    $("#absInsideView dd:eq(" + viewIdx + ")").show();
  });

  if (startIdx >= sizeInsideList) {
    startIdx = 0;
  }
  
  $("#absInsideView").show().fadeOut(1000);

  var idx = 0;
  $("#randomNews dd").each( function()
  {
    if (idx >= startIdx && idx < (startIdx + 4)) {
      this.style.display = "block";
    } else {
      this.style.display = "none";
    }
    idx++;
  });
}

function changeInside(direction)
{
  var startIdx = -1;
  $("#randomNews dd:visible").each( function()
  {
    if (startIdx == -1) {
      startIdx = $("#randomNews dd").index(this);
      return;
    }
  });

  if (direction == 'prev') {
    startIdx -= 4;
    if (startIdx < 0) {
      startIdx = parseInt((sizeInsideList - 1) / 4) * 4;
    }
  } else {
    startIdx += 4;
    if (startIdx >= sizeInsideList) {
      startIdx = 0;
    }
  }

  $("#randomNews dd:lt(" + startIdx + ")").hide();
  $("#randomNews dd:gt(" + (startIdx - 1) + "):lt(" + (startIdx + 4) + ")").show();

  $("#absInsideView").hide();
}

function startSlideInside()
{
  loopInside = setInterval("slideInside()", 5000);
}

function stopSlideInside()
{
  clearInterval(loopInside);
}
// ------------------------------ Ãæ³² ÀÎ»çÀÌµå End ------------------------------//



// ------------------------------ ÇÖ¸µÅ© Start ------------------------------//

function setComboText(comboKey, valueText)
{
  if (valueText.trim() == "Áö¿ª±³À°Ã»" || valueText.trim() == "Á÷¼Ó±â°ü") {
    valueText = "Áö¿ª±³À°Ã»/Á÷¼Ó±â°ü";
  }
  $("#" + comboKey + "_text").text(valueText);
}

function loadCombo(comboKey, backColor)
{
  $("#hotlink").data("backgroundColor_" + comboKey, backColor);
  $("#" + comboKey).css("background-color", backColor)
      .mouseover( function(){
        showComboList(comboKey);
      })
      .mouseout( function(){
        hideComboList(comboKey);
      })
      .show();

  setComboText(comboKey, $("#" + comboKey + "_list li:first").text());

  $("#" + comboKey + "_list")
      .css({
        position :"absolute",
        top :($("#" + comboKey).offset().top - ($("#" + comboKey + "_list").height() / 2) * 1.5 ),
        left :($("#" + comboKey).offset().left - $("#" + comboKey).width() + 13)
      })
      .mouseover( function(){
        showComboList(comboKey);
      })
      .mouseout( function(){
        hideComboList(comboKey);
      })
      .hide();

  $("#" + comboKey + "_list li")
      .css("cursor", "pointer")
      .mouseover(function(){
        $(this).data("backgroundColor", $(this).css("background-color")).css(
            "background-color", backColor);
      })
      .mouseout( function(){
        $(this).css("background-color", $(this).data("backgroundColor"));
      })
      .add("#" + comboKey + "_list li a")
      .click( function(){
        // text°ªÀ» º¯°æ
        setComboText(comboKey, $(this).text());
  
        // anchor tag·ÎºÎÅÍ Á¤º¸¸¦ ¾ò¾î ÆäÀÌÁö ÀÌµ¿À» ÇÑ´Ù.
        /*
        var href = $(this).children("a").attr("href");
        if (href) {
          var target = $(this).children("a").attr("target");
          if (target) window.open(href, target);
          else self.location.href = href;
        }
        */
      });

  $("#" + comboKey + "_text, #" + comboKey + "_list li a")
      .focus( function(){
        showComboList(comboKey);
      })
      .blur( function(){
        hideComboList(comboKey);
      });
}

function showComboList(comboKey)
{
  $("#hotlink").data("hide_" + comboKey, false);
  if ($("#" + comboKey + "_list").is(":hidden")) {
    $("#" + comboKey + "_list").show();
    $("#" + comboKey + "_list li.combo_item").css("background-color", "window");
    $("#" + comboKey + "_list li.combo_item:contains(" + $("#" + comboKey).text() + ")")
        .css("background-color", $("#hotlink").data("backgroundColor_" + comboKey));
  }
}

function hideComboList(comboKey)
{
  $("#hotlink").data("hide_" + comboKey, true);
  window.setTimeout("hideComboListWorker('" + comboKey + "')", "200");
}

function hideComboListWorker(comboKey)
{
  if ($("#hotlink").data("hide_" + comboKey)) {
    $("#" + comboKey + "_list").hide();
  }
}
// ------------------------------ ÇÖ¸µÅ© End ------------------------------//


// ------------------------------ ÀÚÁÖÃ£´Â ¸Þ´º Start ------------------------------//

function showFavorite()
{
  $("#favori_win").show();                
}
// ------------------------------ ÀÚÁÖÃ£´Â ¸Þ´º End ------------------------------//

// ------------------------------ ¹è³Ê Start ------------------------------//
var bannerWidth = 0;
var bannerViewWidth = 760;
var bannerSlidingSize = 780;
var bannerMargin = 0;
var bannerDirection = "right";
var bannerSM = 0;
var bannerEM = 0;
var isStop = false;
function slideBanner(direction, isAuto)
{
  if (isAuto) direction = bannerDirection;
  // var temp = bannerWidth - bannerViewWidth;
  var temp = bannerWidth - bannerSlidingSize;
  if ($("#bannerViewer").queue("fx").length > 0 || isStop) {
    if (bannerDirection == direction) {
      if (isStop) {
        bannerMargin = bannerSM;
      } else {
        return;
      }
    }

    $("#bannerViewer").stop();
  }

  isStop = false;

  if (isAuto) {
    if (direction == "right") {
      if (Math.abs(bannerMargin) >= temp) {
        direction = "left";
      }
    } else {
      if (bannerMargin >= 0) {
  		stopAutoSlideBanner();
		return;

		direction = "right";
      }
    }
  }

  bannerSM = bannerMargin;
  if (direction == "right") {
    if (Math.abs(bannerMargin - bannerSlidingSize) > temp) {
      if (temp % bannerSlidingSize > 0) {
        bannerMargin = -(temp) - (bannerSlidingSize + (-temp % bannerSlidingSize));
      }
    } else {
      bannerMargin = bannerSM - bannerSlidingSize;
    }
  } else {
    if (bannerMargin + bannerSlidingSize >= 0) {
      bannerMargin = 0;
    } else {
      bannerMargin = bannerSM + bannerSlidingSize;
    }
  }
  bannerEM = bannerMargin;

  bannerDirection = direction;

  $("#bannerViewer").animate({marginLeft :bannerMargin + "px"}, {queue :true, duration :1000});
}

var bannerTimer;
function autoSlideBanner()
{
  bannerTimer = window.setInterval("slideBanner(null, true)", 10000);
}

function stopAutoSlideBanner()
{
  if (bannerTimer) {
    window.clearInterval(bannerTimer);
  }

  if ($("#bannerViewer").queue("fx").length > 0) {
    isStop = true;
    $("#bannerViewer").stop();
  }
}

function manualSlideBanner(direction)
{
  if (bannerTimer) {
    window.clearInterval(bannerTimer);
  }

  slideBanner(direction);

//  autoSlideBanner();

}
// ------------------------------ ¹è³Ê End ------------------------------//

$(document).ready(function(){

  $(this).focus();

  // ////// ±ÛÀÚÅ©±â ¼³Á¤
  initFontSize();

  // ////// ÀÌº¥Æ®ÃÊ±âÈ­
  initEvents();

  // ////// ÁÖ¿ä»ç¾÷
  sizeEventList = $(".eventList").length;
  if (sizeEventList > 1) {
    eventOffsetTop = $("#eventList_1").offset().top; 
    eventOffsetLeft = $("#eventList_1").offset().left;
    for( var no = 1; no <= sizeEventList; no++) {
      $("#eventSeq_" + no + "_on, #eventSeq_" + no + "_off")
                          .data("no", no)
                          .mouseover( function(){
                            eventSeqMouseOver($(this).data("no"));
                          })
                          .mouseout( function(){
                            startSlideEventImage();
                          });
      $("#eventList_" + no).mouseover( function(){
                           eventViewerMouseOver();
                         })
                         .mouseout( function()
                         {
                           startSlideEventImage();
                         });
    }

    startSlideEventImage();
  }



  // ////// Ãæ³²ÀÎ»çÀÌµå
  /*
  sizeInsideList = $("#randomNews > dd").length;
  if (sizeInsideList > 4) {
    $("<div></div>").attr("id", "absInsideView")
                    .css("position", "absolute")
                    .css("top", $("#randomNews").offset().top)
                    .css("left", $("#randomNews").offset().left)
                    .css("width", $("#randomNews").width() - 6)
                    .css("height", $("#randomNews").height())
                    .prependTo("body")
                    .append("<dl></dl>")
                    // .css("background-color", "#FFFFFF")
                    .hide();

    $("#randomNews dd").each( function()
    {
      $("#absInsideView > dl").append($(this).clone(true));
    });
    
    $("#absInsideView dd:gt(3), #randomNews dd:gt(3)").hide();

    $(".inside_button a, #randomNews dd").each( function()
    {
      $(this).mouseover(stopSlideInside).mouseout(startSlideInside);
    });

    startSlideInside();
  }
  */

  
  
  // ////// ÇÖ¸µÅ©
  $("#hotlink").height(107);
  loadCombo("hotLink1", "#FFFFDD");
  loadCombo("hotLink2", "#cee3fd");
  loadCombo("hotLink3", "#FFEEEE");

  
  
  // ////// ÀÚÁÖÃ£´Â ¸Þ´º
  //MSIE6.0 or MSIE5.5 min-width ¼Ó¼ºÀÌ Àû¿ëµÇÁö ¾Ê¾Æ Ã³¸®ÇØÁÜ. 
  /*
  if($.browser.msie && ($.browser.version == "6.0" || $.browser.version == "5.5"))
  {
    $("#favori li").each(function(){
      if($(this).width() < 90){
         $(this).width(90);
      }
    });
  }

  $("#favori_hd").css("cursor", "move");
  $("#favori_ft").css("cursor", "move");

  $("#favorite_close_btn").show();
  $("#favori_win").css({position:"absolute", zIndex:1000});
  center("favori_win");
  $("#favorite_close_btn").click(function(){ $("#favori_win").hide(); });
  $("#favori_win").hide();
  */
  
  
  // ////// ¹è³Ê
  bannerWidth = $("#bannerViewer").width();
  autoSlideBanner();

  
  // ////// TTS init
  f_VoiceInit();

});

