﻿function hidePopup1(boxName) {
    if ($('#PopCheck1').attr('checked')) {
        $.cookie('pop' + $('#PopCheck1').attr('value'), '1', { expires: 1 });
    }
    $('#Pop1').hide();
}

function hidePopup2(boxName) {
    if ($('#PopCheck2').attr('checked')) {
        $.cookie('pop' + $('#PopCheck2').attr('value'), '1', { expires: 1 });
    }
    $('#Pop2').hide();
}

$(document).ready(function () {
    $('#repNext img').click(function () {
        rotateNextRepSec();
    });

    $('#repPrev img').click(function () {
        rotatePrevRepSec();
    });

    $('[id$="SearchText"]').blur(function () {
        if ($(this).val() == '') {
            $(this).css("backgroundImage", "url(/Img/searchBg2.png)");
            $(this).css("backgroundRepeat", "no-repeat");
        }
    });

    $(window).scroll(function () {
        var pos = $(window).scrollTop();
        $('#extPnl').stop().animate({ 'top': pos + 'px' }, 500);
    });

    setTimeout(swapViewerImage, 5000);
});

var viewerImgIdx = 0;
var kcrViewerImgs = new Array('/SiteImages/kcrk.jpg', '/SiteImages/kcre.jpg');
var eduViewerImgs = new Array('/SiteImages/edunewsk.jpg', '/SiteImages/edunewse.jpg');

function swapViewerImage() {
/*
    $('#kcrViewImg').attr('src', kcrViewerImgs[viewerImgIdx]);
    $('#eduViewImg').attr('src', eduViewerImgs[viewerImgIdx]);
    viewerImgIdx = (viewerImgIdx + 1) % 2; */

    rotateNextRepSec();
    rotateNextPhoto();
    nextColumns();

    setTimeout(swapViewerImage, 5000);
}

function onQueryKeyDown(obj) {
    if (window.event.keyCode == 13) {
        __doPostBack("srch", obj.value);
    }
      
    $('#srchBox input').css("background", "none");
}

function rotateNextRepSec() {
    var itemWid = $('#repCaroUl .repSec').outerWidth() + 5;
    var indent = parseInt($('#repCaroUl').css('left')) - itemWid;

    $('#repCaroUl:not(:animated)').animate({ 'left': indent }, 500, function () {
        $('#repCaroUl .repSec:last').after($('#repCaroUl .repSec:first'));
        $('#repCaroUl').css({ 'left': '-130px' });
    });
}

function rotatePrevRepSec() {
    var itemWid = $('#repCaroUl .repSec').outerWidth() + 5;
    var indent = parseInt($('#repCaroUl').css('left')) + itemWid;

    $('#repCaroUl:not(:animated)').animate({ 'left': indent }, 500, function () {
        $('#repCaroUl .repSec:first').before($('#repCaroUl .repSec:last'));
        $('#repCaroUl').css({ 'left': '-130px' });
    });
}

function openRadio() {
    window.open("http://society79.com.ne.kr/radio.html", "rw", "width=340,height=200,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

$(document).ready(function () {
    $('#caroUl li:first').before($('#caroUl li:last'));
    $('#caroUl').css({ 'left': '-50px' });

    setPhotoInfo(1);

    $('#mainMenu a.mm').hover(function () {
        $('#childMenu span.sm').hide();
        $('#childMenu span.sm:eq(' + $(this).index() + ')').show();
    });

    $('#menuBar').hover(function () {
    }, function () {
        $('#childMenu span.sm').hide();
    });

    // Hide tab panels except the first one
    for (i = 0; i < $('.tabPnl').length; i++)
        $('.tabPnl:eq(' + i + ') > div:not(:first)').hide();

    // Hide column sets except the idx-th one
    var idx = 0; // Math.floor(Math.random() * 15);
    $('#colPnl > ul > li').eq(idx).show();
    $('#colPnl > ul > li').eq(idx).addClass('sel');

    $('.tabStrip a').click(function (e) {

        // Activate new tab
        var strip = $(this).parent();  // tab strip
        strip.children('a').removeClass('sel');
        $(this).addClass('sel');

        // Make the corresponding content visible
        var panel = strip.siblings('.tabPnl');
        panel.children('div').hide();
        panel.children($(this).attr('href')).show();

        e.preventDefault();

    });

    $('#colNav a').click(function (e) {
        if ($(this).index() == 1)
            nextColumns();
        else
            prevColumns();

        e.preventDefault();
    });

    $('#navNext img').click(function () {
        rotateNextPhoto();
    });

    $('#navPrev img').click(function () {
        rotatePrevPhoto();
    });

    $('#caroUl li a').click(function (e) {
        $('#caroSelTtl a').text($(this).children('img').attr('title'));
        $('#caroSelImg').attr('src', $(this).children('img').attr('src'));
        $('#caroSelTtl a').attr('href', $(this).attr('href'));
        e.preventDefault();
    });
});

function prevColumns() {
    var curItem = $('#colPnl ul li.sel');
    var prevItem = curItem.prev().length ? curItem.prev() : curItem.parent().children(':last');

    curItem.removeClass('sel');
    curItem.hide();
    prevItem.addClass('sel');
    prevItem.show();
}

function nextColumns() {
    var curItem = $('#colPnl ul li.sel');
    var nextItem = curItem.next().length ? curItem.next() : curItem.parent().children(':first');

    curItem.removeClass('sel');
    curItem.hide();
    nextItem.addClass('sel');
    nextItem.show();
}

function rotateNextPhoto() {
    var itemWid = $('#caroUl li').outerWidth() + 5;
    var indent = parseInt($('#caroUl').css('left')) - itemWid;

    $('#caroUl:not(:animated)').animate({ 'left': indent }, 500, function () {
        $('#caroUl li:last').after($('#caroUl li:first'));
        $('#caroUl').css({ 'left': '-50px' });
    });

    setPhotoInfo(2);
}

function rotatePrevPhoto() {
    var itemWid = $('#caroUl li').outerWidth() + 5;
    var indent = parseInt($('#caroUl').css('left')) + itemWid;

    $('#caroUl:not(:animated)').animate({ 'left': indent }, 500, function () {
        $('#caroUl li:first').before($('#caroUl li:last'));
        $('#caroUl').css({ 'left': '-50px' });
    });

    setPhotoInfo(0);
}

function setPhotoInfo(idx) {
    var first = $('#caroUl li a:eq(' + idx + ')');
    $('#caroSelTtl a').text(first.children('img').attr('title'));
    $('#caroSelImg').attr('src', first.children('img').attr('src'));
    $('#caroSelTtl a').attr('href', first.attr('href'));
}

function setPhotoInfo2() {
    var first = $('#caroUl li a:first'); //eq(1)');
    $('#caroSelTtl a').text(first.children('img').attr('title'));
    $('#caroSelImg').attr('src', first.children('img').attr('src'));
    $('#caroSelTtl a').attr('href', first.attr('href'));
}


// 벼룩시장 광고
$(document).ready(function () {
    $('.ind').css('color', '#fff');
    var last = $('#itemList').children(':last');
    last.addClass('selItem');
    setPreviewImage(last.children('img'));

    slideItem();

    $('#itemList li').hover(function () {
        $('#itemListBox li.selItem').removeClass('selItem');
        $(this).addClass('selItem');
        $('.ind').css('color', '#fff');
        $(this).children('.ind').css('color', '#ff0000');
        setPreviewImage($(this).children('img'));
    });
});

function slideItem() {
    var curItem = $('#itemList li.selItem');
    var nextItem = curItem.next().length ? curItem.next() : curItem.parent().children(':first');

    curItem.removeClass('selItem');
    nextItem.addClass('selItem');
    curItem.children('.ind').css('color', '#fff');
    nextItem.children('.ind').css('color', '#ff0000');

    setPreviewImage(nextItem.children('img'));
    setTimeout(slideItem, 3000);
}

function setPreviewImage(prvImg) {
    var wid = 120 * prvImg.width() / prvImg.height();
    var margin = (160 - wid) / 2;

    $('#prvBox img').width(wid);
    $('#prvBox img').height(120);
    $('#prvBox img').css('marginLeft', '' + Math.round(margin) + 'px');

    $('#prvBox img').attr('src', prvImg.attr('src'));
}


