﻿var ctime; // set Time

$J('#selectedCountry').ready(function() {
    $J('#selectedCountry').click(function() {
        // 선택국가 클릭하면 국가목록 show
        showCountry();
    });

    $J('#selectedCountry').mouseout(function() {
        // 선택국가 mouseout시 국가목록 hide
        ctime = window.setTimeout(hideCountry, 300);
    });

    $J('#countryLayer').mouseover(function() {
        // 국가목록 mouseover시 show 유지
        showCountry();
    });

    $J('#countryLayer').mouseout(function() {
        // 국가목록 mouseout시 hide
        ctime = window.setTimeout(hideCountry, 300);
    });
});

// 국가목록 show
function showCountry() {
    closetime();
    changeCountryImage($J('#selectedCountry'), 1);
    $J('#countryLayer').show();
}

// 국가목록 hide
function hideCountry() {
    changeCountryImage($J('#selectedCountry'), 2);
    $J('#countryLayer').hide();
}

// close time 
function closetime() {
    if (ctime) {
        window.clearTimeout(ctime);
        ctime = null;
    }
}

// 이미지 교체
function changeCountryImage(obj, flag) {
    obj.attr('src', obj.attr('src').replace('_o.gif', '.gif'));
    if (flag == 1) {
        obj.attr('src', obj.attr('src').replace('.gif', '_o.gif'));
    }
}

// 국가목록에서 해당 이미지 교체
$J('#countryLayer').ready(function() {
    $J('#countryLayer img').hover(
        function() {
            changeCountryImage($J(this), 1);
        },
        function() {
            changeCountryImage($J(this), 2);
        }
    );
});

var cate_time;  // category set time
var curr_id;    // sub카테고리 layer ID

// sub Category show
function showCategory() {
    if (curr_id) {
        $J('#' + curr_id.replace('cate', 'subCategory')).attr('style', 'display:block');
    }
}

// sub Category hide
function hideCategory() {
    if (curr_id) {
        $J('#' + curr_id.replace('cate', 'subCategory')).attr('style', 'display:none');
    }
}

// close time - category
function closeCategorytime() {
    if (cate_time) {
        window.clearTimeout(cate_time);
        cate_time = null;
    }
}

// top 카테고리 mouseover/mouseout 시 sub Category show/hide 처리
$J('#topCategory').ready(function() {
    $J('#topCategory li').mouseover(
    function() {
        try {
            closeCategorytime();
            hideCategory();

            curr_id = $J(this).attr('id');
            showCategory();
        } catch (e) {  }
    });

    $J('#topCategory li').mouseout(
    function() {
        try {
            curr_id = $J(this).attr('id');
            cate_time = window.setTimeout(hideCategory, 1000);
        } catch (e) {  alert(e.message) }
    }
    );
});

// sub Category mouseover/mouseout 시 show/hide 처리
$J('div[class^="submenu"]').ready(function() {

    $J('div[class^="submenu"]').bind('mouseover',function() {
        closeCategorytime();
        curr_id = $J(this).attr('id').replace('subCategory', 'cate');
        showCategory();
    });

    $J('div[class^="submenu"]').bind('mouseout', function() {
        curr_id = $J(this).attr('id').replace('subCategory', 'cate');
        cate_time = window.setTimeout(hideCategory, 500);
    });
});



