﻿
$(function() {
    try {
        SetSubMenu();
    } catch (e) {

    }
});

var timeout = 1000;
var closetimer = 0;
var ddmenuitem = 0;

$(document).ready(function () {
    //    $('.gnb ul.depth1').children('li').hover(
    //			function () { $('.gnb ul.depth2').hide(); hoverhighlight($(this).children('a').children('img')); CancelTimer(); $(this).children('.depth2').show(); },
    //			function () { closetimer = window.setTimeout(CloseMenu, timeout); }

    //    );

    $('.gnb ul.depth1').children('li').mouseover(
		function () {
		    ResetMainMenuhighlight();
		    CancelTimer();
		    $('.gnb ul.depth2').hide();
		    $(this).children('.depth2').show();
		    var temp = $(this).children('a').children('img').attr('src');
		    var length = temp.length;
		    var file_name = temp.substring(0, length - 4);
		    var status = temp.substring(length - 9).substring(0, 5); // _over
		    var file_type = temp.substring(length - 6).substring(2);
		    if (status != '_over') {
		        $(this).children('a').children('img').attr('src', file_name + '_over' + file_type);
		    }
		}).mouseout(function () {
		    closetimer = window.setTimeout(CloseMenu, timeout);
		    var temp = $(this).children('a').children('img').attr('src');
		    var length = temp.length;
		    var file_name = temp.substring(0, length - 4);
		    var status = temp.substring(length - 9).substring(0, 5); // _over
		    var file_type = temp.substring(length - 6).substring(2);
		    if (status == '_over') {
		        $(this).children('a').children('img').attr('src', (file_name.replace('_over', '') + file_type));
		    }
		}
    );

    $('.gnb ul.depth2').children('li').children('a').children('img').mouseover(
		function () {
		    var temp = $(this).attr('src');
		    var length = temp.length;
		    var file_name = temp.substring(0, length - 4);
		    var status = temp.substring(length - 9).substring(0, 5); // _over
		    var file_type = temp.substring(length - 6).substring(2);
		    if (status != '_over') {
		        $(this).attr('src', file_name + '_over' + file_type);
		    }
		}).mouseout(function () {
		    var arrUrl = document.location.href.split('?')[0].split('/');
		    // 도메인을 제외한 페이지 경로
		    var curUrl = '';
		    for (var j = 3; j <= 4; ++j) {
		        curUrl += arrUrl[j];
		    }

		    if (this.id != 'img_' + curUrl.toLowerCase()) {
		        var temp = $(this).attr('src');
		        var length = temp.length;
		        var file_name = temp.substring(0, length - 4);
		        var status = temp.substring(length - 9).substring(0, 5); // _over
		        var file_type = temp.substring(length - 6).substring(2);
		        if (status == '_over') {
		            $(this).attr('src', (file_name.replace('_over', '') + file_type));
		        }
		    }
		}
    );
});

function CloseMenu() {
    SetSubMenu();
}

function CancelTimer() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}

function ResetMainMenuhighlight() {

    $('img#img_Public').attr({ src: "/images/2.0/menu_01.gif" });
    $('img#img_Enterprise').attr({ src: "/images/2.0/menu_02.gif" });
    $('img#img_SecurityCenter').attr({ src: "/images/2.0/menu_03.gif" });
    $('img#img_SecurityService').attr({ src: "/images/2.0/menu_04.gif" });
    $('img#img_Customer').attr({ src: "/images/2.0/menu_05.gif" });
}

//function hoverhighlight(target) {
//    ResetMainMenuhighlight();
//    if (target) {
//        var file = target.attr('src').split('/');
//        var filename = file[file.length - 1];
//        var path = '';
//        for (i = 0; i < file.length - 1; i++) {
//            path = (i == 0) ? path + file[i] : path + '/' + file[i];
//        }

//        target.attr('src', path + '/' + filename.replace('.gif', '_over.gif'));
//    }
//}

//하위페이지에 들어갔을 경우 하위메뉴 바인딩
function SetSubMenu() {

    var arrUrl = document.location.href.split('?')[0].split('/');
    // 도메인을 제외한 페이지 경로
    var curUrl = '';
    for (var j = 3; j < 4; ++j) {
        curUrl += arrUrl[j];
    }

    try {
        if ($('#submenu_' + curUrl).css('display') == 'none') {
            $('.gnb ul.depth2').hide();
            $('#submenu_' + curUrl).show('3000');

            ResetMainMenuhighlight();

            var file = $('#img_' + curUrl).attr('src').split('/');
            var filename = file[file.length - 1];
            var path = '';
            for (i = 0; i < file.length - 1; i++) {
                path = (i == 0) ? path + file[i] : path + '/' + file[i];
            }

            $('#img_' + curUrl).attr('src', path + '/' + filename.replace('.gif', '_over.gif'));
        }
    }
    catch (e) {
    }

    //서브메뉴 하이라이트
    curUrl = '';
    for (var j = 3; j <= 4; ++j) {
        curUrl += arrUrl[j];
    }

    try {

        var temp = $('#img_' + curUrl.toLowerCase()).attr('src');
        var length = temp.length;
        var file_name = temp.substring(0, length - 4);
        var status = temp.substring(length - 9).substring(0, 5); // _over
        var file_type = temp.substring(length - 6).substring(2);
        if (status != '_over') {
            $('#img_' + curUrl.toLowerCase()).attr('src', (file_name + '_over' + file_type));
        }
    }
    catch (e) {
    }
}
