var showContainer = ""; // variable for optional show-hide lists
var showHover = ""; // variable for optional show-hide lists
var showOn = ""; // variable for optional show-hide lists


$(document).ready(function(){
    //domain forwording added by KJ.Lee on 2008-09-01

	var originalUrl = location.href;
    var theUrl = "";

	//2009.09.03 added by KJ.Lee for title
    if( originalUrl.indexOf("https://ssl.doosan.com") > -1 ){
        // do nothing
    } else {
     parent.document.title = document.title;
    }

	if( originalUrl.indexOf("http://doosanfeed.com") > -1 ){
		location.href = originalUrl.replace("http://doosanfeed.com", "http://www.doosanfeed.com");
        exit;
	}

	if( originalUrl.indexOf("http://doosan.") > -1 ){
		theUrl = originalUrl.replace("http://doosan.", "http://www.doosan.");
	} else {
		theUrl = originalUrl;
	}

    if( theUrl.indexOf(".co.kr") > 0 ){
        location.href = theUrl.replace(".co.kr", ".com");
        exit;
    }
	if( theUrl.indexOf(".org") > 0 ){
        location.href = theUrl.replace(".org", ".com");
        exit;
    }
	if( theUrl.indexOf(".net") > 0 ){
        location.href = theUrl.replace(".net", ".com");
        exit;
    }

	$(".jumpMenu").superfish().supposition().find(">li:has(ul)")
		.mouseover(function(){
			$("ul", this).bgiframe({width:100});
		})
		.find("a")
			.focus(function(){
				$("ul", $(".jumpMenu>li:has(ul)")).bgiframe({width:100});
			});
});

  // Drop-down menus
  $(document).ready(function(){
  	$('#mainNav').superfish({
		speed : 1,
		onShow : function() {
		  $(this).parents('li').siblings('li').addClass('navDim')
		},
		onHide : function() {
		  $(this).parents('li').siblings('li').removeClass('navDim')
		}
	  }).find('>li:has(ul)')
		.mouseover(function(){
			$('ul', this).bgiframe({width:'auto',top:'0px',left:'0px'});
		})
		.find("a")
			.focus(function(){
				$('ul', $(".jumpMenu>li:has(ul)")).bgiframe({width:'auto',top:'0px',left:'0px'});
			});
  });

// Mask under nav menus to avoid background "flicker", and additional
$(document).ready(function(){
  $("#container").append("<div id='navMask'></div>");
  $("#mainNav li.hasMenu").hover(function() {
  $(this).siblings("li").addClass("navDim");
  $("#navMask").show();
  }, function() {
  $("#navMask").hide();
  });
  $("#mainNav li.noMenu").hover(function() {
  $(this).siblings("li").addClass("navDim");
  }, function() {
  $(this).siblings("li").removeClass("navDim");
  });
});

$(document).ready(function(){
  $("#mainNav a.noClick").click(function() {
    $(this).parent("li").siblings("li").addClass("navDim");
    return false;
  });
});


// image rollovers for graphic subheads and left nav column headings
  $(document).ready(function() {

		// Preload all rollovers
		$(".overviewItem h2 img").each(function() {
			// Set the original src
			rollsrc = $(this).attr("src");
			rollON = rollsrc.replace(/.gif$/ig,"_on.gif");
			$("<img>").attr("src", rollON);
		});

		// Subhead rollovers (if links)
		$(".overviewItem h2 a").mouseover(function(){
			imgsrc = $(this).children("img").attr("src");
			matches = imgsrc.match(/_on/);

			// don't do the rollover if state is already ON
			if (!matches) {
			imgsrcON = imgsrc.replace(/.gif$/ig,"_on.gif"); // strip off extension
			$(this).children("img").attr("src", imgsrcON);
			}

		});
		$(".overviewItem h2 a").mouseout(function(){
			$(this).children("img").attr("src", imgsrc);
		});

        // Preload CMS componets all rollovers
        $(".compContent h2 img").each(function() {
            // Set the original src
            rollsrc = $(this).attr("src");
            rollON = rollsrc.replace(/.gif$/ig,"_on.gif");
            $("<img>").attr("src", rollON);
        });

        // Subhead CMS rollovers (if links)
        $(".compContent h2 a").mouseover(function(){
            if( $(this).children("img").attr("src") ){
                imgsrc = $(this).children("img").attr("src");
                matches = imgsrc.match(/_on/);

                // don't do the rollover if state is already ON
                if (!matches) {
                imgsrcON = imgsrc.replace(/.gif$/ig,"_on.gif"); // strip off extension
                $(this).children("img").attr("src", imgsrcON);
                }
            }
        });

        $(".compContent h2 a").mouseout(function(){
            if( $(this).children("img").attr("src") ) $(this).children("img").attr("src", imgsrc);
        });


        // Preload CMS componets all rollovers
        $(".compContentRight h3 img").each(function() {
            // Set the original src
            rollsrc = $(this).attr("src");
            rollON = rollsrc.replace(/.gif$/ig,"_on.gif");
            $("<img>").attr("src", rollON);
        });

        // Subhead CMS rollovers (if links)
        $(".compContentRight h3 a").mouseover(function(){
            imgsrc = $(this).children("img").attr("src");
            matches = imgsrc.match(/_on/);

            // don't do the rollover if state is already ON
            if (!matches) {
            imgsrcON = imgsrc.replace(/.gif$/ig,"_on.gif"); // strip off extension
            $(this).children("img").attr("src", imgsrcON);
            }

        });

        $(".compContentRight h3 a").mouseout(function(){
            $(this).children("img").attr("src", imgsrc);
        });

        // Preload CMS componets all rollovers
        $(".compContentRight h2 img").each(function() {
            // Set the original src
            rollsrc = $(this).attr("src");
            rollON = rollsrc.replace(/.gif$/ig,"_on.gif");
            $("<img>").attr("src", rollON);
        });

        // Subhead rollovers (if links)
        $(".compContentRight h2 a").mouseover(function(){
            imgsrc = $(this).children("img").attr("src");
            matches = imgsrc.match(/_on/);

            // don't do the rollover if state is already ON
            if (!matches) {
            imgsrcON = imgsrc.replace(/.gif$/ig,"_on.gif"); // strip off extension
            $(this).children("img").attr("src", imgsrcON);
            }

        });

        $(".compContentRight h2 a").mouseout(function(){
            $(this).children("img").attr("src", imgsrc);
        });


		// Nav heading rollovers (if links)
		$("#navList h2 a").mouseover(function(){
			imgsrc = $(this).children("img").attr("src");
			matches = imgsrc.match(/_on/);

			// don't do the rollover if state is already ON
			if (!matches) {
			imgsrcON = imgsrc.replace(/.gif$/ig,"_on.gif"); // strip off extension
			$(this).children("img").attr("src", imgsrcON);
			}

		});
		$("#navList h2 a").mouseout(function(){
			$(this).children("img").attr("src", imgsrc);
		});

		// "intro" module siteLink hovers
		$(".intro p.siteLink a").mouseover(function(){
			imgsrc = $(this).children("img").attr("src");
			matches = imgsrc.match(/_on/);

			// don't do the rollover if state is already ON
			if (!matches) {
			imgsrcON = imgsrc.replace(/.gif$/ig,"_on.gif"); // strip off extension
			$(this).children("img").attr("src", imgsrcON);
			}

		});
		$(".intro p.siteLink a").mouseout(function(){
			$(this).children("img").attr("src", imgsrc);
		});

        // #sitemap
		$("#sitemap h3 a").mouseover(function(){
			imgsrc = $(this).children("img").attr("src");
			matches = imgsrc.match(/_on/);

			// don't do the rollover if state is already ON
			if (!matches) {
			imgsrcON = imgsrc.replace(/.gif$/ig,"_on.gif"); // strip off extension
			$(this).children("img").attr("src", imgsrcON);
			}

		});
		$("#sitemap h3 a").mouseout(function(){
			$(this).children("img").attr("src", imgsrc);
		});

	});

// Accordion show-hide for definition lists
$(document).ready(function() {
  $('dl.' + showContainer + ' dt').hover(function() {
    $(this).addClass(showHover);
  }, function() {
    $(this).removeClass(showHover);
    });
  $('dl.' + showContainer + ' dt').click(function() {
    if ($(this).siblings('dt').hasClass(showOn)) $(this).siblings('dt').removeClass(showOn);
    if ($(this).hasClass(showOn)) {
    $(this).removeClass(showOn).next('dd:visible').hide();
    return false;
    }
    else {
    $(this).addClass(showOn).next('dd:hidden').slideDown('fast').siblings('dd:visible').hide();
    return false;
    }
});
});


// FAST Search
function mainSearch() {
    var query = $("#headSearchTxt").val();

    //query = encodeURIComponent( query );
    var defaultValue = document.getElementById("headSearchTxt").defaultValue;

    if ($("#headSearchTxt").val()=="" || $("#headSearchTxt").val() == defaultValue ) {
        $("#headSearchTxt").val("");
        $("#headSearchTxt").focus();

        return false;
    }

    var actionValue = "/doosanfeed/search/kr/index.jsp";
    var url = location.href;
	if(url.indexOf("devssl.") > -1) 
		actionValue =  "http://devdoosanfeed" + actionValue;
	else if(url.indexOf("ssl.doosan.com:444") > -1) actionValue = "http://www.doosanfeed.com" + actionValue;

    if (url.indexOf("/cn/") > -1) {
        actionValue = "/doosanfeed/search/cn/index.jsp";
    }

    $("#query").val( query );
    $("#headSearch").attr("action", actionValue);
    $("#headSearch").attr("method", "get");
    $("#headSearch").submit();

}

//lanugae change
var chngLanValidateURL;
function chngLan(lan1, lan2){
    if( lan1 != "" && lan2 != "" ){
        var url = location.href;
        lan1 = "/"+lan1;
        lan2 = "/"+lan2;

        var checkURL = chngLanValidateURL;
        if (checkURL != undefined) {
        	if (!chngLanValidate(url, lan1, lan2)) return;
        }

        var newUrl = url.replace(lan1, lan2);
        location.href = newUrl;
    }
}

var chngLanValidateDlm = "/chngLanValidateDlm";
var chngLanValidateURL =
{
	//URL의 언어부분 (ko|en|cn)을 chngLanValidateDlm 문자로 치환하고,
	//서버정보(http://localhost) 문자열은 삭제한다.
	"/chngLanValidateDlm/about/ethics_management/index.page": {"kr":true},
	"/chngLanValidateDlm/about/ethics_management/code_of_ethics.page": {"kr":true},
	"/chngLanValidateDlm/ethicsReport.do": {"kr":true},
	"/chngLanValidateDlm/about/fair_trade/index.page": {"kr":true},
	"/chngLanValidateDlm/about/fair_trade/ceo_compliance.page": {"kr":true},
	"/chngLanValidateDlm/about/fair_trade/compliance_program.page": {"kr":true},
	"/chngLanValidateDlm/about/fair_trade/promotion_contents.page": {"kr":true},
	"/chngLanValidateDlm/fairTradeNews.do": {"kr":true},
	"/chngLanValidateDlm/about/fair_trade/organization.page": {"kr":true},
	"/chngLanValidateDlm/ir/disclosures.page": {"kr":true}
}

var chngLanNotFoundURL =
{
	// 해당 한글이름의 페이지를 실제 URL 절대경로로 수정
	"/kr": {"/en":"/kr/not_found_en.page", "/cn":"/kr/not_found_cn.page"},
	"/en": {"/kr":"/en/not_found_kr.page", "/cn":"/en/not_found_cn.page"},
	"/cn": {"/kr":"/cn/not_found_kr.page", "/en":"/cn/not_found_en.page"}
}

function chngLanValidate(url, lan1, lan2) {
	var l_pageExt = [".page", ".html", ".htm", ".do"];
	var l_parsed = url.replace(lan1, chngLanValidateDlm);

	l_parsed = l_parsed.substring(l_parsed.indexOf(chngLanValidateDlm));
	for (var i = 0; i < l_pageExt.length; i++) {
		var l_pageExtIndex = l_parsed.indexOf(l_pageExt[i]);
		if (l_pageExtIndex > 0) {
			l_parsed = l_parsed.substring(0, l_pageExtIndex + l_pageExt[i].length);
			break;
		}
	}

	var l_acceptLan = chngLanValidateURL[l_parsed];
	if (l_acceptLan == undefined) return true;
	if (l_acceptLan[lan2] == undefined) {
		var l_notFoundURL = chngLanNotFoundURL[lan1];
		l_notFoundURL = l_notFoundURL[lan2];
		// 실제 페이지 없음 URL 입력후 아래 alert() 행 상제, 하단 주석 해제.
		// alert('Not Found!:' + l_parsed + "\n\n" + "[" + lan1 + "] --> [" + lan2 + "]" + "\n" + l_notFoundURL);
		location.href = l_notFoundURL;
		return false;
	}

	return true;
}

/*추가*/