function headlogCheck(f)
{
	if (f.id.value == "")
	{
		alert("아이디를 입력해 주세요.         ");
		f.id.focus();
		return false;
	}
	if (f.pw.value == "")
	{
		alert("비밀번호를 입력해 주세요.         ");
		f.pw.focus();
		return false;
	}
	if(f.referer.value=="") f.referer.value = location.href;
}
function remember_idpw(ths)
{
	if (ths.checked == true)
	{
		if (!confirm('\n\n패스워드정보를 저장할 경우 다음접속시 \n\n패스워드를 입력하지 않으셔도 됩니다.\n\n그러나, 개인PC가 아닐 경우 타인이 로그인할 수 있습니다.     \n\nPC를 여러사람이 사용하는 공공장소에서는 체크하지 마세요.\n\n정말로 패스워드를 기억시키겠습니까?\n\n'))
		{
			ths.checked = false;
		}
	}
}
function CreateBookmark() {
  var title = document.title;
  var url = location.href;
  try {
	  window.external.AddFavorite(url, title);
	} catch(e) { 
	try {
	  window.sidebar.addPanel(title, url,"");
	} catch(e) { 
	try {
    var elem = document.createElement('a');
    elem.rel = 'sidebar';
    elem.title = title;
    elem.href = url;
//    elem.setAttribute('href',url);
//    elem.setAttribute('title',title);
//    elem.setAttribute('rel','sidebar');
    elem.click();
  } catch (e) {
    alert('알림창을 닫고, Ctl+D 나 Ctl+B를 누르세요.');
  }
	}
	}
	return false;
}
function toggleLayer(i,t,path,img1,img2) {
  var i = document.getElementById(i)||i;
  var t = document.getElementById(t)||t;
  if(t.style.display!='none') {
    t.style.display = 'none';
    i.innerHTML = '<img src="'+path+'/'+img1+'" alt="SHOW" />';
  } else {
    t.style.display = 'block';
    i.innerHTML = '<img src="'+path+'/'+img2+'" alt="HIDE" />';
  }
  return false;
}

$.fn.wait = function(time, type) {
  time = time || 1000;
  type = type || "fx";
  return this.queue(type, function() {
    var self = this;
    setTimeout(function() {
      $(self).dequeue();
    }, time);
  });
};
function init_bannerHeader() {
  $('#bannerHeader').cycle({ 
    prev:     '#bannerHeaderWrap a.prev',
    next:     '#bannerHeaderWrap a.next', 
    fx:       'scrollHorz',
    easing:   'easeout',
    speed:    1000,
    timeout:  0,
    pause:    1,
    delay:    -1000
  });
}
function init_bannerText() {
  $('#bannerText').cycle({ 
    prev:     '#bannerTextWrap a.prev',
    next:     '#bannerTextWrap a.next', 
    fx:       'scrollHorz',
    easing:   'easeout',
    speed:    1000,
    timeout:  0,
    pause:    1,
    delay:    -1000
  });
}
function init_loginbox() {
  $('#showlogin').click(function(){
    if($('#logoffBox form').width()==48) {
      $('#logoffBox form').animate({width:406},500);
      $(this).children('img').attr({src:'./image/hidelogin.gif',alt:'hide the login box'});
      setTimeout("$('#logoffBox #id').focus();",1000);
    } else if($('#logoffBox form').width()==406) {
      $('#logoffBox form').animate({width:48},500);
      $(this).children('img').attr({src:'./image/showlogin.gif',alt:'show the login box'});
    }
    return false;
  });
}
function init_submenu() {
  var t;
  $('#mainMenu li a').mouseenter(function(){
    clearTimeout(t);
    var nowclass = $(this).parent().attr('class');
    $('#subMenu > ul[class!='+nowclass+']').stop(true,true).hide();
    $('#subMenu > ul[class='+nowclass+']:hidden').show();
  }).parent().parent()
    .mouseleave(function(){t=setTimeout(function(){$('#subMenu > ul').slideUp();},1000);});
  $('#subMenu > ul')
    .mouseleave(function(){$('#subMenu > ul').slideUp();})
    .mouseenter(function(){clearTimeout(t);});
//  $('#content')
//    .mouseover(function(){$('#subMenu > ul').slideUp();});
}
function init_quicklink() {
  var t;
  $('#quickLink li a').mouseenter(function(){
    clearTimeout(t);
    var nowclass = $(this).parent().attr('class');
    $('#quickLinkSub > div[class!='+nowclass+']').stop(true,true).hide();
    $('#quickLinkSub > div[class='+nowclass+']:hidden').slideDown();
  }).parent().parent()
    .mouseleave(function(){t=setTimeout(function(){$('#quickLinkSub > div').slideUp();},1000);});
  $('#quickLinkSub')
    .mouseleave(function(){$('#quickLinkSub > div').slideUp();})
    .mouseenter(function(){clearTimeout(t);});
//  $('#content')
//    .mouseover(function(){$('#quickLinkSub > div').slideUp();});
}
function flyBannerClose() {
  $('#bannerOver').css({zIndex:'0',left:'960px',width:'140px'});
  $('#bannerOver > div').css({position:'absolute',left:'-960px'});
  $('#bannerBbsTop').children().show();
}
function flyBannerOpen() {
  $('#bannerBbsTop').children().hide();
  $('#bannerOver').css({zIndex:'999',left:'0px',width:'1110px'});
  $('#bannerOver > div').css({position:'absolute',left:'0px'});
  $('#bannerOver form').submit();
  return false;
}
function init_bannerOver() {
  $('#bannerOver').css({position:'absolute',zIndex:'0',left:'960px',top:'158px',width:'140px',overflow:'hidden',display:'block'});
  $('#bannerOver > div').css({position:'absolute',left:'-960px'});
}
function init_bannerOut() {
  if($('#bannerOut a').attr('href')!='#') return false;
  $('#bannerOut').append('<a class="close" href="#"><img src="./image/close.gif" alt="close" /></a>');
  var t = ($('#bannerOver').height()>240) ? $('#bannerOver').height()-32 : 240-32;
  $('#bannerOut a.close').css({top:t}).click(function(){
    $('#bannerOver').hide();
    $('#bannerOut a.close').hide();
  });
  $('#bannerOut form a').click(function(t){
    if($('#bannerOver').is(':hidden')) {
      $("#bannerOut form input[name='cuid']").val($("#bannerOver form input[name='uid']").val())
      $('#bannerOut form').submit();
    }
    $('#bannerOver').toggle();
    $('#bannerOut a.close').toggle();
    return false;
  });
  $('#bannerOut').hide().show();
}
function init_bookmark() {
  $('#bookmark').click(function(){CreateBookmark();});
}
function chasing(oid, topPos, topLimit, btmLimit, duration){
	var obj = $(oid);
	var btmLimit = $(document).height() - obj.height() - btmLimit;
	if(topPos > 0){pos = $(document).scrollTop() + topPos;} else {pos = $(document).scrollTop() + $(window).innerHeight() - obj.height() + topPos;} 
	if(pos > btmLimit){pos = btmLimit;}
	if(pos < topLimit){pos = topLimit;}
	var topOffset = $(document).scrollTop() - obj.height() - 100;
	var btmOffset = $(document).scrollTop() + $(window).height() + 100;
  if(obj.position().top < topOffset) obj.stop(true,true).css({top:topOffset});
  if(obj.position().top  > btmOffset) obj.stop(true,true).css({top:btmOffset});
	obj.stop().animate({top:pos},duration,'easeinout');
}
function init_chasing() {
  $(window).scroll(function(){chasing('#chasingRight',100,418,100,800);});
  $(window).scroll(function(){chasing('#chasingLeft',100,418,100,800);});
}
function init_menuicon(){
  $('#mainMenu li img').each(function(i){
    var l = parseInt(($(this).parent().width()-$(this).width())/2);
    $(this).css({left:l,top:'-5px',position:'absolute'});
  });
}
$(document).ready(function(){
  init_bannerHeader();
  init_bannerText();
  init_menuicon();
  init_submenu();
  init_quicklink();
  init_loginbox();
  init_bannerOver();
  init_bannerOut();
  init_chasing();
  init_bookmark();
  $('#keyword').focus();
  $('.scrollto').scrollToHash();
  $('.scrolldiv').scrollbarPaper();
});
