/*!
    Swap Images Easy
	Author: XuanND
	http://xuannd.wordpress.com/2010/12/03/jquery-swap-images-easy/
*/
(function($){$.fn.swapimg=function(options){var defaults={imgOn:"_on.",imgOff:"_off."};var options=$.extend(defaults,options);var $isOn=false;var $obj_index=-1;return this.each(function(){if($(this).is('img')){obj=$(this)}else{obj=$(this).find('img')}obj.hover(function(){if(this.src.indexOf('_on')==-1){$isOn=false}else{$isOn=true}if($isOn==false){this.src=this.src.replace(options.imgOff,options.imgOn)}},function(){if($isOn==false){this.src=this.src.replace(options.imgOn,options.imgOff)}})})}})(jQuery);

/* JS Custom */
$(document).ready(function(){
	// Swap Images
	$('.naviLeft ul img, .gnb ul img, .tabRight img').swapimg({imgOn: "_on.gif", imgOff: ".gif"});
	$('.symptom_toolbar li img').swapimg({imgOn: "_on.jpg", imgOff: ".jpg"});

	// Site map
	$('.sitemap').hide();
	$('.sitemap_link a').click(function(){
		//$('.bg_subMenu, .gnb ul, .sitemap_link').hide();
		$('.sitemap').show();
	});
	$('.sitemap').hover(
		function(){
			//
		},function(){
			$('.sitemap').hide();
			//$('.bg_subMenu, .gnb ul, .sitemap_link').show();
		}
	);

	// Quick Menu
	//$('.quickView_all').hide();
	$('.quickMenu').click(function(){
		$('.quickView_all').show();
	});
	$('.quickView_all .close').click(function(){
		$('.quickView_all').hide();
	});

	// Click ID
	$('.map_assigned .map').hide();
	$('#Circum').show();
	$('.pos1 img').attr("src", function(){return $(this).attr("src").replace(".png", "_on.png");});
	$('.interactive_map a').click(function(){
		$('.interactive_map a img').attr("src", function(){return $(this).attr("src").replace("_on.png", ".png");});
		$(this).find('img').attr("src", function(){return $(this).attr("src").replace(".png", "_on.png");});
		$id_show = $(this).attr('href');
		$('.map_assigned .map').hide();
		$($id_show).show();
		return false;
	});

	// Good Map Popup
	$('.link_goodmap').click(function(){
		var $link_map = $(this).attr('href');
		newwindow=window.open($link_map,'name', 'height=750,width=950');
		if (window.focus) {newwindow.focus()}
		return false;
	});

	// Media Popup
	$('.book_bounder a').click(function(){
		var $link_map = $(this).attr('href');
		newwindow=window.open($link_map,'name', '');
		if (window.focus) {newwindow.focus()}
		return false;
	});

	// Tabs dropdown: FAQ List
	$('.tabs_faq .lv01').swapimg({imgOn: "_on.gif", imgOff: ".gif"});
	$(".tabs_faq .lv01")
		.mouseover(function() {
			$(".tabs_faq .lv01").find('.subtab_faq').hide()
			$(this).find('.subtab_faq').show();
		})
		.mouseout(function(){
			$(this).find('.subtab_faq').hide();
	});

	// tabs tvcf
	$('.hidetvcf').hide();
	$('#tabs_tvcf_01').show();
	$('#tabs_tvcf li a').click(function(){
		$('#tabs_tvcf li img').attr("src", function(){return $(this).attr("src").replace("_on.gif", ".gif");});
		$('#tabs_tvcf li').find('a').removeClass('current');
		$(this).addClass('current').find('img').attr("src", function(){return $(this).attr("src").replace(".gif", "_on.gif");});
		$id_show = $(this).attr('href');
		$('.hidetvcf').hide();
		$($id_show).show();
		return false;
	});


});

// Include flash
var flashvars = {
	pageNum:"",
	subNum: ""
};
var params = {
	quality: "best",
	allowFullScreen: "true",
	wmode: "transparent"
};

// swfobject ÀÌ ¾øÀ»°æ¿ì ¿¹¿ÜÃ³¸®ÇÔ
if(typeof(swfobject) != 'undefined')
{
  swfobject.embedSWF("/Bproduct/images/fla/main/main_banner.swf","flaMainBanner","480","150","8.0.0","",flashvars,params);
  swfobject.embedSWF("/Bproduct/images/fla/introduction/map_center.swf","flaMapCenter","720","320","8.0.0","",flashvars,params);
  swfobject.embedSWF("/Bproduct/images/fla/community/create_map.swf","flaCommunity","720","242","8.0.0","",flashvars,params);
  swfobject.embedSWF("/Bproduct/images/fla/product/korea_map.swf","flaProcuct","650","300","8.0.0","",flashvars,params);
}

// GNB
function initNavigation(seq) {
	nav = document.getElementById("gnb");
	nav.menu = new Array();
	nav.current = null;
	nav.menuseq = 0;
	navLen = nav.childNodes.length;

	allA = nav.getElementsByTagName("a")
	for(k = 0; k < allA.length; k++) {
		allA.item(k).onmouseover = allA.item(k).onfocus = function () {
			nav.isOver = true;
		}
		allA.item(k).onmouseout = allA.item(k).onblur = function () {
			nav.isOver = false;
			setTimeout(function () {
				if (nav.isOver == false) {
					if (nav.menu[seq])
						nav.menu[seq].onmouseover();
					else if(nav.current) {
						menuImg = nav.current.childNodes.item(0);
						menuImg.src = menuImg.src.replace("_on.gif", ".gif");
						if (nav.current.submenu)
							nav.current.submenu.style.display = "none";
						nav.current = null;
					}
				}
			}, 500);
		}
	}

	for (i = 0; i < navLen; i++) {
		navItem = nav.childNodes.item(i);
		if (navItem.tagName != "LI")
			continue;

		navAnchor = navItem.getElementsByTagName("a").item(0);
		navAnchor.submenu = navItem.getElementsByTagName("ul").item(0);

		navAnchor.onmouseover = navAnchor.onfocus = function () {
			if (nav.current) {
				menuImg = nav.current.childNodes.item(0);
				menuImg.src = menuImg.src.replace("_on.gif", ".gif");
				if (nav.current.submenu)
					nav.current.submenu.style.display = "none";
				nav.current = null;
			}
			if (nav.current != this) {
				menuImg = this.childNodes.item(0);
				menuImg.src = menuImg.src.replace(".gif", "_on.gif");
				if (this.submenu)
					this.submenu.style.display = "block";
				nav.current = this;
			}
			nav.isOver = true;
		}
		nav.menuseq++;
		nav.menu[nav.menuseq] = navAnchor;
	}
	if (nav.menu[seq])
		nav.menu[seq].onmouseover();
}


// Áß¾ÓÁ¤·Ä
function popupCenter(url, popName, w, h, scrollbars) {

    if(scrollbars == "") scrollbars = "no";

    var positionT = (screen.height - h) / 2;
    var positionL = (screen.width - w) / 2;
    var feat = "width=" + w + ", height=" + h +", top=" + positionT + ", left=" + positionL + ", resizable=no, scrollbars="+ scrollbars+ ", status=no"
    win_open(url, popName, feat)
}

function popup_mov(url, popName, w, h, scrollbars) {

    var positionT = (screen.height - h) / 2;
    var positionL = (screen.width - w) / 2;
    var feat = "width=" + w + ", height=" + h +", top=" + positionT + ", left=" + positionL + ", resizable=no, scrollbars="+ scrollbars+ ", status=no"
    window.open(url, popName, feat)
}

// ÄíÅ° ÀÔ·Â
function set_cookie(name, value, expirehours, domain)
{
    var today = new Date();
    today.setTime(today.getTime() + (60*60*1000*expirehours));
    document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + today.toGMTString() + ";";
    if (domain) {
        document.cookie += "domain=" + domain + ";";
    }
}

// Äí±âÀÐ±â
function getCookie(name)
{
  var nameOfCookie = name + "=";
  var x = 0;

  while ( x <= document.cookie.length ){

    var y = (x+nameOfCookie.length);
    if ( document.cookie.substring( x, y ) == nameOfCookie ) {
      if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
      endOfCookie = document.cookie.length;
      return unescape( document.cookie.substring( y, endOfCookie ) );
    }
    x = document.cookie.indexOf( " ", x ) + 1;
    if ( x == 0 )
    break;
  }
  return "";
}


// ÄÁÅÙÃ÷ º¸±â¿ë ÁÂÇ¥ Ã£±â
function getPosition(object) {
  var valueT = 0, valueL = 0;
	do {
	  valueT += object.offsetTop  || 0;
	  valueL += object.offsetLeft || 0;
	  object = object.offsetParent;
	  if (object) {
		if(object.tagName.toUpperCase()=='BODY') break;
	  }
	} while (object);
	return {x: valueL, y:valueT};
}



function trim_byte(check_string, max_byte_size,addstring) {
  var strLength = check_string.length;
  var char_ASCII;
  var i = 0;
  var total_byte = 0;
  var result="";
  var j =1;
  var tmpstr="";
  var tmpchk=true;
  var addYN="N";

  while(i<check_string.length){
    char_ASCII = check_string.charCodeAt(i);
      //¼ýÀÚ
      if (char_ASCII >= 48 && char_ASCII <= 57 ) {
        total_byte++;
        if (total_byte <= max_byte_size){
          result = result + check_string.substr(i,1);
        }else{
          addYN="Y";
        }

      //¿µ¾î
      } else if ((char_ASCII>=65 && char_ASCII<=90) || (char_ASCII>=97 && char_ASCII<=122)) {
        total_byte++;
        if (total_byte <= max_byte_size){
            result = result  + check_string.substr(i,1);
        }else{
          addYN="Y";
        }
      //Æ¯¼ö±âÈ£ ½ºÆäÀÌ½º Æ÷ÇÔ(32)
      } else if ((char_ASCII>=32 && char_ASCII<=47) || (char_ASCII>=58 && char_ASCII<=64)
          || (char_ASCII>=91 && char_ASCII<=96)  || (char_ASCII>=123 && char_ASCII<=126)) {
        total_byte++;
        if (total_byte <= max_byte_size){
            result = result + check_string.substr(i,1);
        }else{
          addYN="Y";
        }
      //ÇÑ±Û
      } else if ((char_ASCII >= 12592) || (char_ASCII <= 12687)) {
        total_byte = total_byte + 2;
        if (total_byte <= max_byte_size){
          result = result +  (check_string.substr(i,1));
        }else{
          addYN="Y";
        }
      }

      //check_string¾Õ´Ü¿¡ &nbsp; °¡ ÀÖ´Ù¸é »èÁ¦
      if (tmpchk == true) {
      tmpstr = result;
      if(j!=6){
        j++;
      }else{
        if(tmpstr =="&nbsp;"){
          result = "";
          max_byte_size = max_byte_size + 6;
        }else{
          tmpchk = false;
        }
        j=1;
      }
    }

    i++;
  }

  if(addYN == "Y"){
    if (addstring == "undefined") addstring = "...";
    result = result + addstring;
  }

  return result;
}
