﻿try {
    document.execCommand('BackgroundImageCache', false, true);
} catch (e) { }


var $File = {

    download: function(Url) {
        // download handler 로 연결
        location.href = "/common/handler/downloadHandler.ashx?path=" + Url;
    }
}

/********************************************************************************************************
팝업 수동 Open 정의
변수 정의 : pop - 파일명, width - 가로사이즈, height - 세로사이즈, flag - 0:스크롤없음, 1:스크롤있음
********************************************************************************************************/
function popfix(pop,tname,width,height,flag)
{
  var url = pop;
  var wd = width;
  var he = height;
  var tn = tname;

  if ((window.navigator.userAgent.indexOf("SV1") != -1) || (window.navigator.userAgent.indexOf("MSIE 7") != -1)) {
    wd = wd + 8;
    he = he + 10;

    if (flag == "0" )    {
      winObj =  window.open(url,tn,"toolbar=0,menubar=0,scrollbars=no,resizable=no,width=" + wd + ",height=" + he + ";");
	  winObj.focus(); 	}
    else  {
      winObj =  window.open(url,tn,"toolbar=0,menubar=0,scrollbars=yes,resizable=no,width=" + wd + ",height=" + he + ";");
	  winObj.focus();  }
  }

  else {
  if (flag == "0" )    {
    winObj =  window.open(url,tn,"toolbar=0,menubar=0,scrollbars=no,resizable=no,width=" + wd +",height=" + he + ";");
	winObj.focus();   }
  else  {
    winObj =  window.open(url,tn,"toolbar=0,menubar=0,scrollbars=yes,resizable=no,width=" + wd +",height=" + he + ";");
	winObj.focus();   }
  }
}

/*********** 팝업창 오픈  **********/
function uf_popOpen(url,wname) {
	var positionX = 0;
	var positionY = 0;
	winStr = window.open(url,wname,"left="+positionX+",top="+positionY+",width=100,height=100,toolbar=no,scrollbars=no" );
	winStr.focus();
}

/****** 팝업창 자동 리사이즈 **************************************************************/
function uf_popResize() {

	var Station = {
        check : function (type, checkStr, checkPoint)
        {
            var name = "ETC";
            for ( var list in checkPoint )
            {
                if (checkStr.indexOf(list) != -1)
                {
                    name = checkPoint[list];
                }
            }
            escape("this." + type + " = function () { return name }") ;
            return name;
        },
        os : function ()
        {
            var checkStr = navigator.platform.toLowerCase();
            var checkPoint =
            {
                "win" : "WINDOW", "mac" : "MAC", "unix" : "UNIX",
                "linux" : "LINUX"
            }
            return this.check("os", checkStr, checkPoint );
        },
        browser : function ()
        {
            var checkStr = navigator.userAgent.toLowerCase();
            var checkPoint =
            {
                "msie 6" : "IE6" , "msie 7" : "IE7",
                "firefox" : "FF", "navigator" : "NETSCAPE",
                "opera" : "OPERA" , "msie 8" : "IE8"
            }
            return this.check("browser", checkStr, checkPoint);

        }
    } 	/*browser Check*/

	var thisX = document.getElementById("offsetTable").offsetWidth;
	var thisY = document.getElementById("offsetTable").offsetHeight;
	var maxThisX = screen.width - 50;
	var maxThisY = screen.height - 80;

	if (Station.browser() == "IE7") {
		var marginY = 78;
	}
	else if (Station.browser() == "IE6") {
		var marginY = 36;
	}
	else if (Station.browser() == "FF") {
		var marginY = 88;
	}
		else if (Station.browser() == "IE8") {
		var marginY = 78;
	}
	else  {
		var marginY = 78;
	}

	if (thisX > maxThisX) {
		window.document.body.scroll = "yes";
		thisX = maxThisX;
	}
	if (thisY > maxThisY - marginY) {
		window.document.body.scroll = "yes";
		thisX += 19;
		thisY = maxThisY - marginY;
	}

	var windowX = (screen.width - (thisX+10))/2;
	var windowY = (screen.height - (thisY+marginY))/2 - 20;
	//window.moveTo(windowX,windowY);
		if (Station.browser() == "IE6") {
		window.resizeTo(thisX+18,thisY+marginY);
	}
	else {
		window.resizeTo(thisX+11,thisY+marginY);
	}
}

function setPng24(obj) {
    obj.width = obj.height = 1;
    obj.className = obj.className.replace(/\bpng24\b/i, '');
    obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + obj.src + "',sizingMethod='image');"
    obj.src = '';
    return '';
}

function menu_open(str) {
    if (str == "true") {
        document.getElementById("flash_gnb").height = "600";
    } else {
        document.getElementById("flash_gnb").height = "104";
    }
}

function goSite() {
    if (document.getElementById("ulf").style.display == "none") {
        document.getElementById("ulf").style.display = "block"
    } else {
        document.getElementById("ulf").style.display = "none";
    }
}

/*global vehicles Distinct Features */
function callFeatures() {
				document.location = "#pos-distinct";
}

function doSNS(btn) {
	var longUrl = escape("http://lyricsbird.net/");
	var reurl = "";
	var option = "toolbar=yes,directories=yes,status=yes,menubar=yes,resizable=yes,scrollbars=yes";
	var shortener = "http://udanax.org/";
	var targetWin = window.open('', 'sharer', option);
	$.ajax({
	  type: 'GET',
	  url: shortener + "shorturl.jsp?mode=api&longurl=" + location.href + "&jsoncallback=?",
	  dataType: 'json',
	  timeout: 6000,
	  success: function(data, status) {
	    reurl = shortener + data.shorturl;
	    if (btn == "retweet") {
	      //window.open('http://twitter.com/home?status=Visit Kia Motors corporate web site ' + reurl, 'sharer', option)
	      window.open('http://twitter.com/intent/tweet?url=' + reurl + '&text=Visit Kia Motors corporate web site', 'sharer', option);
	      targetWin.location.href = 'http://twitter.com/intent/tweet?url=' + reurl + '&text=Visit Kia Motors corporate web site';
	    } else if (btn == "share") {
	      //window.open('http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=' + reurl, 'sharer', option+',width=626,height=436');
	      window.open('http://www.facebook.com/share.php?u=' + reurl, 'sharer', option + ',width=626,height=436');
	      targetWin.location.href = 'http://www.facebook.com/share.php?u=' + reurl;
	    }
	  },
	  error: function(request, status, error) {
	    alert("Error status : " + status);
	  }
	});
}

function doShare() {
    var test = window.open('http://www.addthis.com/bookmark.php?v=250');
    test.location.href = 'http://www.addthis.com/bookmark.php?v=250';
}

/* 외부 JS include */
document.write(' <script type="text/javascript" src="/common/js/fakeselect.js"></script> ');

/* GNB Control */
window.gnb_timer = null;
window.gnb_num = null;
var state = "hide";
function categoryLayer(num){
    if (window.gnb_timer) {
        clearTimeout(window.gnb_timer);
        window.gnb_timer = null;
    }

    if (state == "hide") {
    		state = "show";
        window.gnb_timer = setTimeout(function() {
            if (window.gnb_num != num) {
                for (var i = 1; i <= 2; i++) {
                    var e = document.getElementById("idgnb_" + i);
                    var d = document.getElementById("btmImg_" + i);

                    jQuery(e).stop();
                    e.style.height = "";
                    e.style.overflow = "";
                    e.style.display = "none";
                    d.style.display = "none";
                    jQuery(e).parent().parent('.menu'+i).removeClass('onUnder');//underline

                    if (i == num) {
                    		jQuery(d).show();
                        jQuery(e).slideDown(500, function(){ this.style.overflow = ""; });
                        jQuery(e).parent().parent('.menu'+i).addClass('onUnder');//underline
                    }
                }

                window.gnb_num = num;
            }
        }, 10);
    }
    else {
    	state = "hide";
        window.gnb_timer = setTimeout(function() {
            for (var j = 1; j <= 2; j++) {
                var e = document.getElementById("idgnb_" + j);
                var d = document.getElementById("btmImg_" + j);

                jQuery(e).parent().parent('.menu'+j).removeClass('onUnder');//underline
                jQuery(e).animate({height:0}, function() {
                    this.style.display = "none";
                });
            }
            window.gnb_num = null;
        }, 300);
    }
}

/* gnb menu1 navi active - jquery.js include */
$(document).ready(function(){
	$(".menuDep1 > li > dl").hide();
	$(".menuDep1 dd ul > .current > a").css("color", "#000");
	$(".menuDep1 dd ul > .current").parent().parent().parent().parent().parent().show();
	$(".menuDep1 dd ul > .current").parent().parent().parent().parent().parent().parent().find("dfn").hide();
	$(".menuDep1 dd ul > .current").parent().parent().parent().parent().parent().parent().find("li").css("background", "none");

	/* click event */
	$(".menuDep1 > li > dfn").css("cursor", "hand");
	$(".menuDep1 > li > dfn").click(function() {
		$(".menuDep1 > li > dl").hide();
		$(".menuDep1 > li > dfn").show();
		$(this).parent().css("background", "none");
		$(this).hide();
		$(this).parent().find("dl").show();
	});
});


function footerExt(){
	var obj = document.getElementById("hid_area");
	var clic = document.getElementById("ico_plus");

	if (obj.style.display == "" || obj.style.display == "none"){
		obj.style.display = "block";
		clic.className = "ico_plus on";
	}else{
		obj.style.display = "none";
		clic.className = "ico_plus";
	}
}


function vr_area(idx){
	for(i = 1; i <= 2 ; i++ ){
	document.getElementById('vr360'+i).style.display = "none";
	}
	document.getElementById('vr360'+idx).style.display = "block";
	}

   /* GNB Control */
window.gnb_timer = null;
window.gnb_num = null;
var state = "hide";
function categoryLayer(num){
    if (window.gnb_timer) {
        clearTimeout(window.gnb_timer);
        window.gnb_timer = null;
    }

    if (state == "hide") {
    		state = "show";
        window.gnb_timer = setTimeout(function() {
            if (window.gnb_num != num) {
                for (var i = 1; i <= 2; i++) {
                    var e = document.getElementById("idgnb_" + i);
                    var d = document.getElementById("btmImg_" + i);

                    jQuery(e).stop();
                    e.style.height = "";
                    e.style.overflow = "";
                    e.style.display = "none";
                    d.style.display = "none";
                    jQuery(e).parent().parent('.menu'+i).removeClass('onUnder');//underline

                    if (i == num) {
                    		jQuery(d).show();
                        jQuery(e).slideDown(500, function(){ this.style.overflow = ""; });
                        jQuery(e).parent().parent('.menu'+i).addClass('onUnder');//underline
                    }
                }

                window.gnb_num = num;
            }
        }, 10);
    }
    else {
    	state = "hide";
        window.gnb_timer = setTimeout(function() {
            for (var j = 1; j <= 2; j++) {
                var e = document.getElementById("idgnb_" + j);
                var d = document.getElementById("btmImg_" + j);

                jQuery(e).parent().parent('.menu'+j).removeClass('onUnder');//underline
                jQuery(e).animate({height:0}, function() {
                    this.style.display = "none";
                });
            }
            window.gnb_num = null;
        }, 300);
    }
}


// car menu moving
var move_px = 2;
var max_move_tb_px = 18;
var movingState = false;
var strPosTop = 0;
var movetotal = 0;
var limitMove_px;

function moveScroll(direction, num) {
  if (movingState) { return; }
  else {
    movetotal = 0;
    limitMove_px = document.getElementById("thumbDiv" + num).clientHeight - document.getElementById("moveDiv" + num).clientHeight;

    if (document.getElementById("moveDiv" + num).style.top == "") {
      document.getElementById("moveDiv" + num).style.top = "0px";
    }

    if (direction == "b") {
      if (parseInt(document.getElementById("moveDiv" + num).style.top) > parseInt(limitMove_px)) {
        movingState = true;
        actMove(direction, num);
      }
    } else if (direction == "t") {
      if (parseInt(document.getElementById("moveDiv" + num).style.top) < 0) {
        movingState = true;
        actMove(direction, num);
      }
    }
  }
}

function actMove(direction, num) {
  if (movetotal < max_move_tb_px) {
    if (direction == "b") {
      if (parseInt(document.getElementById("moveDiv" + num).style.top) > parseInt(limitMove_px)) {
        strPosTop -= move_px;
      } else {
        clearTimeout(go);
        movingState = false;
      }
    }
    else {
      if (parseInt(document.getElementById("moveDiv" + num).style.top) < 0) {
        strPosTop += move_px;
      } else {
        clearTimeout(go);
        movingState = false;
      }
    }

    document.getElementById("moveDiv" + num).style.top = strPosTop + "px";

    movetotal += move_px;

    go = setTimeout("actMove('" + direction + "', " + num + ")", 1)
  } else {
    clearTimeout(go);
    movingState = false;
  }
}
function viewSearchInput() {
	document.getElementById("searchBox").style.display = "block";
}
