// IE flicker 버그 FIX
try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}

// IE6 이하 버전에서는 투명png핵 때문에 로고영역에 클릭 이벤트를 추가
if (navigator.userAgent.match(/.+MSIE (6|5).*/)) {
    Event.observe(window, 'load', function() {
        Event.observe($('ie6_sucks'), "click", function() { document.location.href = '/'; });
    });
}

// 메인 NAV 오버시에 하위메뉴 show, hide
var nav = {};
Event.observe(window, 'load', function() {
    $$('div#main_nav-wrap > ul > li').each(function(el) {
        nav[el.id] = {'id':el.id, 'obj':el.down('.depth2')};
        Event.observe(el, "mouseover", showSubmenu);
    });
});
function showSubmenu(event) {
    var src_id = Event.findElement(event, 'li').readAttribute('id');
    if (src_id == null || src_id == '') {
        return;
    }
    for (data in nav) {
        var obj = nav[data];
        if (obj.id == src_id) {
            obj.obj.show();
        } else {
            obj.obj.hide();
        }
    }
}

// 서브메뉴는 mouseout시에 감추기, 인건 event bubble 때문에 일단 잠시 보류(아니면 슬쩍 넘어갈 수도...)
$$('div.depth2').each(function(el) {});

// 좌측 sitemap 슬리이딩
function toggleSitemap() {
    if ($('site_map-wrap').style.left == '' || $('site_map-wrap').style.left == '-332px') {
        new Effect.Move($('site_map-wrap'), {x:0, y:0, mode:'absolute', duration:0.2});
        Event.observe(document, "mouseover", hideSitemap);
    } else {
        new Effect.Move($('site_map-wrap'), {x:-332, y:0, mode:'absolute', duration:0.2});
        Event.stopObserving($('site_map-wrap'), "mouseout", hideSitemap);
    }
}
function hideSitemap(event) {
    if (Event.pointerX(event) > 360) {
        new Effect.Move($('site_map-wrap'), {x:-332, y:0, mode:'absolute', duration:0.2});
        Event.stopObserving(document, "mouseover", hideSitemap);
    }
}

// 갤러리 초기화기능 소이미지에 마우스오버 이벤트를 추가하는거임
function initGallery() {
    $$('div#gellery_sub_wrap img').each(function(el) {
        if (el.src.indexOf('ready_img_s.png') == '-1') {
            Event.observe(el, 'mouseover', swapImage);
        }
    })
}

// 갤러리 소이미지 마우스오버시 중이미지를 변경하는 기능
function swapImage(event) {
    var obj = Event.findElement(event, 'img');
    $$('div#gellery_wrap img').each(function(el) {
        el.hide();
    });
    var tmp = obj.id.split('_');
    $('gal_' + tmp[1] + '_m').show();        
}

