/*
  Title _ WCAG 1.0 Common Script
  Author _ Choojiho(chubo@gmail.com)
  Date _ 2008. 5. 28
*/

$(document).ready(function(){

  /* Outer Link Icon Print */
  $("a[href*='http://']").addClass("outer");
  $("a[href*='http://']").focus(function(){
    $(this).addClass("outer_focus");
  }).blur(function(){
    $(this).removeClass("outer_focus");
  });
  $("a[href*='http://']").hover(
    function(){
      $(this).addClass("outer_focus");
    },
    function(){
      $(this).removeClass("outer_focus");
    });

  $("a > img").parent().removeClass("outer");
  $("#contents a[href*='mailto:']").addClass("email");

  /* GNB */
  $("#main_menu > ul >li > a").focus(function(){
      $(this).parent().parent().children("li").css( {position: "relative", height: "28px"} );
      $(this).parent().parent().children("li").children("ul").hide();
      $(this).parent().children("ul").show();
  });

  $("#main_menu > ul >li > a").mouseover(function(){
      $(this).parent().parent().children("li").css( {position: "relative", height: "28px"} );
      $(this).parent().parent().children("li").children("ul").hide();
      $(this).parent().children("ul").show();
  });

  /* Family Site Controll */
  $("#family_site > ul > li > a").focus(function(){
    $(this).parent().parent().addClass("open");
  });
  $("#family_site > ul > li > a").blur(function(){
    $(this).parent().parent().removeClass("open");
  });
  $("#family_site > ul").mouseover(function(){
    $(this).addClass("open");
  });
  $("#family_site > ul").mouseout(function(){
    $(this).removeClass("open");
  });

  /* Text Zoomin */
  $(".text_zoomin").toggle(
    function(){
      $(this).addClass("text_zoomout");
      $("#wrapper").addClass("sub_zoomin");
      $(".sub #contents .item h4").addClass("zoomin");
    },
    function(){
      $(this).removeClass("text_zoomout");
      $("#wrapper").removeClass("sub_zoomin");
    }
  );

  /* Popup Tooltip Support */
  $("a[href*='#cmt']").click(function(){
    $(".tooltip div.popup").hide();
    $(this).attr("id","return_lnk");
    obj = $($(this).attr("href"));
    subject = obj.html();
    content = obj.next().html();
    $(this).parent().addClass("tooltip").append("<div></div>").children("div").addClass("popup").append("<h6>"+subject+"</h6>").append("<p>"+content+"</p>").append("<a href='#return_lnk' class='btn_close'></a>").click(function(){ $(this).hide(); }).children("a").append("<img src='../images/btn/btn_close.gif' alt='닫기' width='8' height='8' />");
    return false;
  });
});

function close_tooltip(){
  $(".tooltip div.popup").hide();
}

// Paging
var stmnRIGHT = 0; // Right Margin
var stmnGAP1 = 0; // Top Margin
var stmnGAP2 = -260; // Scroll Top Margin
var stmnBASE = 0; // Scroll Start Point
var stmnActivateSpeed = 10;
var stmnScrollSpeed = 500;
var stmnTimer;

function RefreshStaticMenu() {
  var stmnStartPoint, stmnEndPoint;

  stmnStartPoint = parseInt(document.getElementById('paging').style.top, 10);
  stmnEndPoint = Math.max(document.documentElement.scrollTop, document.body.scrollTop) + stmnGAP2;
  if (stmnEndPoint < stmnGAP1) stmnEndPoint = stmnGAP1;

  if (stmnStartPoint != stmnEndPoint) {
    stmnScrollAmount = Math.ceil( Math.abs( stmnEndPoint - stmnStartPoint ) / 5 );
    document.getElementById('paging').style.top = parseInt(document.getElementById('paging').style.top, 10) + ( ( stmnEndPoint<stmnStartPoint ) ? -stmnScrollAmount : stmnScrollAmount ) + 'px';
    stmnRefreshTimer = stmnScrollSpeed;
  }

  stmnTimer = setTimeout("RefreshStaticMenu();", stmnActivateSpeed);
}

function InitializeStaticMenu() {
  document.getElementById('paging').style.right = stmnRIGHT + 'px';
  document.getElementById('paging').style.top = document.body.scrollTop + stmnBASE + 'px';
  RefreshStaticMenu();
}
// Paging