var isInterval = "";
var now_brd_index = 0;
var g_auto_change_event;

$(function() {
    Main.init();
    $('#area_notice ul li .tab_menu').hover(Main.changeTabMenuForNotice);
    $('#area_news ul li .tab_menu').hover(Main.changeTabMenuForNews);
    $('#area_eventlist ul li .tab_menu').hover(Main.changeTabMenuForEvent);
    $('#btn_event li a').click(Main.setEventBanner);
    $('#btn_auto_change_banner').click(Main.autoChangeBanner);
    // ForcedPopup.init("pop_20110615");
    // ForcedPopup.init("pop_20111006");
    // ForcedPopup.init("pop_20111125");
});

var Main = {
    init : function() {
        $('#btn_event li a:first').addClass('on');
        $('#event_banner li').hide();
        $('#event_banner li:first').show();

        // ÀÌ¹ÌÁö ·Ñ¸µ ½ÃÀÛ
        Main.startAutoChangeBanner();

        // ¿À´ÃÀÇ Ç÷¾×Á¤º¸ Ç¥Çö È¿°ú Ã³¸®
        Main.TodayBldInfo.init();
    },
    changeTabMenuForNotice: function() {  // °øÁö °Ô½ÃÆÇ ¿µ¿ª ¼³Á¤
        $('#area_notice ul li').removeClass('on');
        $(this).parent().addClass('on');
    },
    changeTabMenuForNews : function() {   // ´º½º °Ô½ÃÆÇ ¿µ¿ª ¼³Á¤
        $('#area_news ul li').removeClass('on');
        $(this).parent().addClass('on');
    },
    changeTabMenuForEvent : function() {  // ÀÌº¥Æ® °Ô½ÃÆÇ ¿µ¿ª ¼³Á¤
        $('#area_eventlist ul li').removeClass('on');
        $(this).parent().addClass('on');
    },
    setEventBanner : function() {         // ÀÌº¥Æ® ¹è³Ê ¿µ¿ª ¼³Á¤
        // ÃÊ±âÈ­(¹öÆ° ºÒ²ô±â, ¹è³Ê ¼û±â±â)
        $('#btn_event li a').removeClass('on');
        $('#event_banner li').hide();

        // ÇØ´ç ¹öÆ° ºÒ Å°±â
        $(this).addClass('on');

        // ÇØ´ç ¹è³Ê º¸ÀÌ°Ô Ã³¸®
        $('#btn_event .event_num').each(function(p_index, p_item) {
            if($(p_item).hasClass('on')) {
                $('#event_banner li').eq(p_index).show();
            }
        });
        return false;
    },
    autoChangeBanner : function() {
        try {
            var l_status = $(this).hasClass('play');
            if(l_status) {
                Main.startAutoChangeBanner();
                $(this).removeClass('play');
                $(this).addClass('pause');
                $(this).attr('title', 'Å¬¸¯ÇÏ½Ã¸é ¹è³Ê°¡ ÀÚµ¿º¯°æÀ» ¸ØÃä´Ï´Ù.');
                $(this).html('Àç»ý');
            } else {
                Main.stopAutoChangeBanner();
                $(this).removeClass('pause');
                $(this).addClass('play');
                $(this).attr('title', 'Å¬¸¯ÇÏ½Ã¸é ¹è³Ê°¡ 5ÃÊ °£°ÝÀ¸·Î ÀÚµ¿º¯°æµË´Ï´Ù.');
                $(this).html('ÀÏ½ÃÁ¤Áö');
            }

            return false;
        } catch(e) {
            alert("[script/main/main.js's Main.autoChangeBanner's ]"+e.description);
        }
    },
    autoChangeEvent : function() {        // ÀÌº¥Æ® ¹è³Ê ·Ñ¸µ
        var event_banner_totcnt = $('#event_banner li img').size();

        $('.banner_list').each(function(i) {
            if($(this).css('display') != 'none') {
                now_brd_index = i;   
            }
        });

        if(now_brd_index == (event_banner_totcnt-1)) {
            now_brd_index = 0;
        } else {
            now_brd_index++;
        }

        $('.banner_list').each(function(i) {
            if(i == now_brd_index) {
                $('#btn_event li a').removeClass('on');
                $('#btn_event li a').eq(i).addClass('on');
                $(this).show();
            } else {
                $(this).hide();
            }
        });
    },
    TodayBldInfo : {
        init : function() {
            try {
                // ÃÊ±âÈ­
                var obj_list = $('p.blood_stock');
                obj_list.css('display', 'none');

                // display Ã³¸®
                $(obj_list[0]).slideDown(function() {
                    $(obj_list[1]).slideDown(function() {
                        $(obj_list[2]).slideDown(function() {
                            $(obj_list[3]).slideDown();
                        });
                    });
                });
            } catch(e) {
                alert(e.description);
            }
        }
    },
    startAutoChangeBanner : function() {
        try {
            g_auto_change_event = setInterval('Main.autoChangeEvent();', 5000);  // ÀÌ¹ÌÁö ·Ñ¸µ ¼³Á¤
        } catch(e) {
            alert("[script/main/main.js's Main.startAutoChangeBanner's ]"+e.description);
        }
    },
    stopAutoChangeBanner : function() {
        try {
            clearInterval(g_auto_change_event);  // ÀÌ¹ÌÁö ·Ñ¸µ Á¤Áö
        } catch(e) {
            alert("[script/main/main.js's Main.stopAutoChangeBanner's ]"+e.description);
        }
    }
}


/**
 * ÆË¾÷Á¸ÀÌ ¾Æ´Ñ °­Á¦ ÆË¾÷(2011-06-15 : Á¤Ã¢Áø)
 */
var ForcedPopup = {
    init : function(p_popupid) {
        try {
            if(p_popupid == "") {
                return false;
            } else if(p_popupid == "pop_20111125") {
                ForcedPopup.temppopup();
            }
        } catch(e) {
            alert("[script/main/main.js's ForcedPopup.init's ]"+e.description);
        }
    }, getCookie : function(p_name) {
        try {
            var nameOfCookie = p_name + "=";
            var x = 0;
            
            while ( x <= document.cookie.length ) {
                var y = (x+nameOfCookie.length);
                if ( document.cookie.substring( x, y ) == nameOfCookie ) {
                    if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
                    endOfCookie = document.cookie.length;
                    return unescape( document.cookie.substring( y, endOfCookie ) );
                }
                x = document.cookie.indexOf( " ", x ) + 1;
                if ( x == 0 ) break;
            }
            return "";
        } catch(e) {
            alert("[script/main/main.js's ForcedPopup.getCookie] " + e.description);
        }
    },
    temppopup : function() {
        try {
            if(ForcedPopup.getCookie("pop_20111125") != "pop_20111125") {
                var l_win_popup = window.open('/main/forced_popup.jsp', 'POPUP', 'width=323px, height=325px');
                if(l_win_popup == null) {
                    alert("ÆË¾÷ÀÌ Â÷´ÜµÇ¾î¼­ Á¤»óÀûÀ¸·Î »ç¿ëÇÏ½Ç¼ö ¾ø½À´Ï´Ù. \n\n"+document.domain+"ÁÖ¼Ò¸¦ ÆË¾÷Â÷´Ü¿¡¼­ Çã¿ëÇØ ÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.\n\n====================== Âü °í ==================\n\n1.Explore µµ±¸ - ÆË¾÷ Â÷´Ü ¼³Á¤ ¿¡¼­ ÆË¾÷Â÷´Ü »çÇ×À» È®ÀÎÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.\n\n2. ÀÎÅÍ³Ý¿¡¼­ Åø¹Ù¸¦ ¼³Ä¡ÇÏ½Å °æ¿ì¿¡ Åø¹Ù¿¡¼­ ÆË¾÷Â÷´Ü ¼³Á¤ »çÇ×À» È®ÀÎÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.");
                } else {
                    l_win_popup.focus();
                }
            }
        } catch(e) {
            alert("[script/main/main.js's ForcedPopup.init's ]"+e.description);
        }
    }
}
