﻿/* gnb menu display */
function tabMenu(idx){
	if (idx == 2) $("#CenterModel").fadeOut();
	//if (idx == 3) { 
	//
	//$("#gnbMenu > div").hide(); return false; }
	document.getElementById("gnbMenu").style.display = "block";
	$("#gnbMenu > div").hide();
	document.getElementById("menu"+idx).style.display = "block";
	if (idx == 1) { $("#CenterModel").fadeOut();
		//$("#gnbMenu > div").hide();
		//$("#gnbMenu").hide();
		//hideDep2();
		//$(".headTop > ul > li").removeClass("onUnder");
		$('.menuDep2x').fadeOut();
		//alert('here!!!');
		$(".menuDep2x").show(); 
		hideDep();
		
			document.getElementById("menuDep2_"+idx+"_"+1).style.display="block";
			document.getElementById("menuDep3_"+idx+"_"+1).style.display="block";

	}
	document.getElementById("gnb").className = "gnb" + " under";
	/* 1005 수정 */
	hideDep2();
}

var ekgalpos = 0;
function ekgalcat(id){
//alert(id);
$(".eksubm").fadeOut();
$(".ekgalcurr").removeClass("ekgalcurr");
$(".ekgalyear"+id).addClass("ekgalcurr");
$("#ekgalscat"+id).fadeIn();
$('#ekgalscat'+id+' .scnum_0').click();
return false;
}

function lugalcat(id){
$(".lugalyear").removeClass("lugalcurr");
$(".lugalyear"+id).addClass("lugalcurr");

$('.luobjcnt').attr('style','display:none');
$('.luobjcnt'+id).fadeIn();
//$("#ekgalscat"+id).fadeIn();
return false;
}

var currpic=0;
function ekgalsubcat(id,s1,s2){
//alert('here');
$(".scactive").removeClass("scactive");
$('.eksubc'+s1+'_'+s2).addClass("scactive");
currpic = 0;
$(".ekgalmc").load('http://kia-israel.co.il/get_ekgal.php?cat_id='+id,function(){
if ($('.activemv0').length>0) $('.activemv0').click();
//alert('suc');
//alert($("#ekgalpicd0").html());
$("#mcs3_container .content").html($("#ekgalpicd0").html());
$("#mcs3_container").mCustomScrollbar("vertical",0,"easeOutCirc",1.05,"auto","no","no",20);
//return false;
});
return false;
}
function activemovie(src,id){
  var so = new SWFObject('player.swf','ply','630','340','9','#000000');
  so.addParam('allowfullscreen','true');
  so.addParam('allowscriptaccess','always');
  so.addParam('wmode','opaque');
  so.addVariable('file',src);
  so.write(id);
  return false;
	}
function prevpic(){
	if ($("#ekgalpic"+(1+currpic)).length==0) currpic=-1;
	if ($("#ekgalpic"+(1+currpic)).length>0){
		currpic++;
		if ($('.activemv'+currpic).length>0) $('.activemv'+currpic).click();
		$(".ekgalpic").fadeOut();
		$("#ekgalpic"+currpic).fadeIn();
		$(".gpiccount").html(1+currpic);
		$("#mcs3_container .content").html($("#ekgalpicd"+currpic).html());
		$("#mcs3_container").mCustomScrollbar("vertical",0,"easeOutCirc",1.05,"auto","no","no",20);
	}
	return false;
}

function nextpic(){
	if (currpic==0) currpic=($(".ekgalmc").children().size()-1)/2;
	if (currpic > 0){
		currpic--;
		if ($('.activemv'+currpic).length>0) $('.activemv'+currpic).click();
		$(".ekgalpic").fadeOut();
		$("#ekgalpic"+currpic).fadeIn();
		$(".gpiccount").html(1+currpic);
		$("#mcs3_container .content").html($("#ekgalpicd"+currpic).html());
		$("#mcs3_container").mCustomScrollbar("vertical",0,"easeOutCirc",1.05,"auto","no","no",20);
	}
	return false;
}

/* gnb menu1 navi active - jquery.js include */
$(document).ready(function(){
	$('.header').fadeIn();
	if ($('.eksubc0_0').length>0) $('.eksubc0_0').click();
	var ekgaltotal = $(".galright").attr('rel');
	var lugaltotal = $(".lugalleft").attr('rel');
	$(".galleft").click(function() {
		if (ekgalpos > 0){
		ekgalpos--;
		$(".ekgalslider").animate({
		right: "+=90"
	  }, 500);
	  }
	  return false;
	});
	$(".galright").click(function() {
		if (ekgalpos < ekgaltotal-7){
			ekgalpos++;
			$(".ekgalslider").animate({
			right: "-=90"
		  }, 500);
	  }
	  return false;
	});
	
	$(".lugalright").click(function() {
		if (ekgalpos > 0){
		ekgalpos--;
		$(".ekgalslider").animate({
		right: "+=91"
	  }, 500);
	  }
	  return false;
	});
	$(".lugalleft").click(function() {
		if (ekgalpos < lugaltotal-7){
			ekgalpos++;
			$(".ekgalslider").animate({
			right: "-=91"
		  }, 500);
	  }
	  return false;
	});

	
	/*== GNB Control ==*/

	//$(".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").mouseover(function() {
		$(".menuDep1 > li > dl").hide();
		$(".menuDep1 > li > dfn").show();
		$(this).parent().css("background", "none");
		$(this).hide();
		$(this).parent().find("dl").show();
	});
	/*== GNB Control ==*/

	/*== Model MouseOver ==*/
//	$("#CenterModel").mouseover(function() {
//		$(this).css("cursor", "hand");
//		$("#gnbMenu").show();
//		tabMenu(1);
//		$("#menuDep2_1_1").show();
//		$("#menuDep3_1_1").show();
//	});
	$("#gnbMenu").mouseleave(function() {
		$("#gnbMenu > div").hide();
		$("#gnbMenu").hide();
		hideDep2();
		$(".headTop > ul > li").removeClass("onUnder");
		$("#CenterModel").fadeIn();
	});
	/*== Model MouseOver ==*/

	/*== GNB underline ==*/
	$("#menu1").mouseover(function() {
		$("#gnb1").addClass("onUnder");
		
	});
	$("#menu2").mouseover(function() {
		$("#gnb2").addClass("onUnder");
		//$("#models_btm").css("display","none");
		//$("#kia_btm").css("display","block");
	});
	$("#menu3").mouseover(function() {
		$("#gnb3").addClass("onUnder");
	});

	$("#gnbMenu").mouseleave(function() {
		$("#gnb1").removeClass("onUnder");
		$("#gnb2").removeClass("onUnder");
		$("#gnb3").removeClass("onUnder");
	});
	/*== GNB underline ==*/
	
	$("#gnb2").mouseover(function() {
		$("#models_btm").css("display","none");
		$("#kia_btm").css("display","block");
		$("#history").css("display","none");
		
		//$("#models_png").css("display","none");
	});
	$("#menu2").mouseover(function() {
		$("#models_btm").css("display","none");
		$("#kia_btm").css("display","block");
		$("#history").css("display","none");
		
		
		//$("#models_png").css("display","none");
	});
	$("#menu2").mouseleave(function() {
		$("#models_btm").css("display","block");
		$("#kia_btm").css("display","none");
		$("#history").css("display","block");
		
		//$("#models_png").css("display","none");
	});
	$("#gnb2").mouseleave(function() {
		$("#models_btm").css("display","block");
		$("#kia_btm").css("display","none");
		$("#history").css("display","block");
		//$("#models_png").css("display","block");
	});
	
	$("#gnb4").mouseover(function() {
		$("#CenterModel").css("display","block");
	});
	$("#gnb4").mouseleave(function() {
		//$("#CenterModel").css("display","none");
	});
	
	
	setInterval ( 'movemaincar()', 8000 );
	
	
	//$(".nopoint").bind('click', function() {
	//	window.location.href=$(this).attr("src");
	//});
});



/* call swf*/
function swfView(id, swfPath, width, height, bgColor, wmode, accessMode, subConId) {
	if (!bgColor) bgColor = "#FFFFFF";
 	if (!wmode) wmode = "transparent";
	if (!accessMode) accessMode = "sameDomain";
	var swfStr = "";
	swfStr = "<object id=\"" + id + "\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"" + location.protocol + "//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10.0.42.34\" width=\"" + width + "px\" height=\"" + height +"px\">";
	swfStr += "<param name=\"movie\" value=\"" + swfPath + "\" />";
	swfStr += "<param name=\"quality\" value=\"high\" />";
	swfStr += "<param name=\"bgColor\" value=\"" + bgColor + "\" />";
	swfStr += "<param name=\"wmode\" value=\"" + wmode + "\" />";
	swfStr += "<param name=\"allowscriptAccess\" value=\"" + accessMode + "\" />";
	swfStr += "<!--[if !IE]> <-->";
	swfStr += "<object id=\"" + id + "NIE\" type=\"application/x-shockwave-flash\" data=\"" + swfPath + "\" width=\"" + width + "px\" height=\"" + height + "px\">";
	swfStr += "<param name=\"movie\" value=\"" + swfPath + "\" />";
	swfStr += "<param name=\"quality\" value=\"high\" />";
	swfStr += "<param name=\"bgColor\" value=\"" + bgColor + "\" />";
	swfStr += "<param name=\"wmode\" value=\"" + wmode + "\" />";
	swfStr += "<param name=\"allowscriptAccess\" value=\"" + accessMode + "\" />";
	swfStr += "<!--> <![endif]-->";
	if (subConId != "" && document.getElementById(subConId) != null) {
		swfStr += document.getElementById(subConId).innerHTML;
		document.getElementById(subConId).innerHTML = "";
	}
	swfStr += "<!--[if !IE]> <-->";
	swfStr += "</object>";
	swfStr += "<!--> <![endif]-->";
	swfStr += "</object>";
	document.write(swfStr);
}

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='about:blank;';
	return '';
}

function setPngSize(obj) {
	obj.width = obj.height = 1;
	obj.className = obj.className.replace(/\bpngSize\b/i,'');
	obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='scale');"
	obj.src='http://www.kiaglobal.com/Images/Common/blank.gif';
	return '';
}

/* 1005 수정 */
var mone = 0;
var lastaction = 0;
function moveUp(element,pos,m1,m2,l){
	if (l+1 != lastaction) return false;
	if (pos == 0) opc = 0;
	else if (pos > 4) opc = 0;
	opc = 1 / pos;
	var leftt = 0;
	if (pos == 3) leftt = '10px';
	if (pos == 4) leftt = '20px';
	if (pos == 5) leftt = '30px';	
	//if (pos<0) pos = 0;
	pos = pos*60;
	//alert('move '+pos);
	element.animate({
		opacity: opc,
		top: pos,
		left: leftt,filter:''
	  }, 500, function() {
		if ((mone>48) && (l+1 == lastaction)){
		hideDep();
		$("#menuDep2_" + m1 +"_" + m2).show();
		$("#menuDep3_" + m1 +"_" + m2).show();
		$("#m_menuDep2_" + m1 +"_" + m2).show();
		}
		else mone++;
	  });
	
}

var curdep = 1;
function displayDep2x(m1, m2) {
	mone = 0;
	l = lastaction++;
	showDep(m1);
	$(".allsm").hide();
	var i = 0;
	//alert('curr ='+curdep+' and m2= '+m2);
//	if (m2 > curdep) {
		while (50 >= i){
			if (document.getElementById("menuDep2_"+m1+"_"+i))
			{
			//alert('move '+curdep+' to '+curdep+'-'+m2);
				moveUp($("#menuDep2_" + m1 +"_" + i),i-parseInt(m2)+1,m1, m2,l);
			}
			else mone++;
			i++;
		}
		curdep = m2;
	
}

function hideDep2() {
	for(i=0;i<10;i++){
		for(j=0;j<50;j++){
			if(document.getElementById("menuDep2_"+i+"_"+j)){
			//document.getElementById("menuDep2_"+i+"_"+j).style.display="none";
			//document.getElementById("menuDep3_"+i+"_"+j).style.display="none";
			}
		}
	}
}
function hideDep() {
	for(i=0;i<10;i++){
		for(j=0;j<50;j++){
			if(document.getElementById("menuDep2_"+i+"_"+j)){
			document.getElementById("menuDep2_"+i+"_"+j).style.display="none";
			document.getElementById("menuDep3_"+i+"_"+j).style.display="none";
			}
		}
	}
}
function showDep(i) {
		for(j=0;j<50;j++){
			if(document.getElementById("menuDep2_"+i+"_"+j)){
			document.getElementById("menuDep2_"+i+"_"+j).style.display="block";
			//document.getElementById("menuDep3_"+i+"_"+j).style.display="block";
			}
		}
}
/* 1005 수정 */

// 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;
	}
}

// image moving
var move_lr_px = 4;
var max_move_lr_px = 128;
var lr_movingState = false;
var strPosLeft = 0;
var lr_movetotal = 0;

function moveScroll_lr(direction) {
    if (lr_movingState) { return; }
	else {
		lr_movetotal = 0;
		img_cnt = document.getElementById("moveDiv").getElementsByTagName("li").length;
		if (direction == "r") {
			if(img_cnt < 6) {
				return;
			}else if (document.getElementById("moveDiv").style.left != -((img_cnt - 5) * max_move_lr_px) + "px") {
				lr_movingState = true;
				actMove_lr(direction);
			}
		} else if (direction == "l") {
			if (document.getElementById("moveDiv").style.left != "0px" && document.getElementById("moveDiv").style.left != "") {
				lr_movingState = true;
				actMove_lr(direction);
			}
		}
	}
}

function actMove_lr(direction) {
	if (lr_movetotal < max_move_lr_px) {
		if(direction == "l"){strPosLeft += move_lr_px;}
		else{strPosLeft -= move_lr_px;}

		document.getElementById("moveDiv").style.left = strPosLeft + "px";

		lr_movetotal += move_lr_px;

		go_lr = setTimeout ("actMove_lr('" + direction + "')", 1)
	} else {
    	clearTimeout(go_lr);
    	lr_movingState = false;
	}
}

function changeBigImg(index){
    var srcObj = document.getElementById("imgbig_" + index);
    var targetObj = document.getElementById("BigImg");
    targetObj.src = srcObj.href;
    document.getElementById("imgDate").innerHTML = srcObj.date;
    document.getElementById("imgDesc").innerHTML = srcObj.title;
}

function changeImg(index){
    var srcObj = document.getElementById("imgbig_" + index);
    var targetObj = document.getElementById("BigImg");
    targetObj.src = srcObj.href;
}

/* banner btn */
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/";
 $.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/home?status=Visit Kia Motors corporate web site ' + reurl, 'sharer', option);
 } 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');
 }
 },
 error: function (request, status, error) {
  alert("Error status : " + status);
 }
 });
}

/* input background control */
function trim(str) {
	return str.replace(/^\s+|\s+$/g,"");
}
function resetBg(obj, claName) {
	if (trim(obj.value) == "") obj.className = claName;
}
function fnSetComma(str) {
  return Number(String(str).replace(/\..*|[^\d]/g,"")).toLocaleString().slice(0,-3);
}
var nextmaincar = 2;
var aftermv = 0;
function changetitles(title1,title2){
	$('.carname1').html(title1.replace('###',"'"));
	$('.carname2').html(title2.replace('###',"'"));
}
function viewmainlogo(object,next,title1,title2,title_current){
$('#rightarrow').fadeOut();
$('#leftarrow').fadeOut();
setTimeout("changetitles('"+title1+"','"+title2+"')",300);
	
$('#rightarrow').fadeIn();
$('#leftarrow').fadeIn();
//alert(title1+' and '+title2);
	aftermv = 1;
	setTimeout('aftermv = 0;',1000);
	if (nextmaincar == next) window.location.href='http://kia-israel.co.il/motors/'+title_current;//return false;
	nextmaincar = next; 
	$('.logoimg').fadeOut();
	$('.'+object).fadeIn();
	
	
}
function movemaincar(){
	//alert(next = nextmaincar);

	if (aftermv) return false;
	//$('.car'+nextmaincar).click();
}
function setgallery(xml,num){
$('.galeryinter').fadeOut();
$('.gallery'+num).fadeIn();

}
