﻿var nowPos = 0;
var currentPosX = 0
        , movePosX = 0
        , moved = false
        , isOver = false;
var contentID = new Array();

contentID[0] = "company";
contentID[1] = "business1";
contentID[2] = "business2";
contentID[3] = "people";
contentID[4] = "voice";

function ShowDetailView(postIdx) {
    ShowDetailUrl("/Board/BoardRead?postIdx=" + postIdx);
}

function showRecruit(idx) {
    switch (idx) {
        case 1:
            ShowDetailUrl("/Company/Recruit_UXPlanner");
            break;
        case 2:
            ShowDetailUrl("/Company/Recruit_UXDesigner");
            break;
        case 3:
            ShowDetailUrl("/Company/Recruit_Developer");
            break;
        default:
            break;

    }
}

function ShowDetailUrl(url) {

    $("#newsDetailView").attr("src", url);
    //$("#newsDetailContainer").overlay({ mask: '#000', closeOnClick: true, load: true });        
    $("#newsDetailContainer").css("left", $(window).width() / 2 - 250);
    $("#newsDetailContainer").css("top", $(window).height() < 200 ? "0" : "55px");
    if (url == "/SNS/BBS") {
        $("#newsDetailView").css("width", "620px");
        $("#newsDetailView").css("height", "600px");
        $("#newsDetailContainer").css("top", $(window).height() < 200 ? "0" : "30px");
    }
    else if (url == "/Company/Recruit_UXPlanner"
            || url == "/Company/Recruit_UXDesigner"
            || url == "/Company/Recruit_Developer") {
        $("#newsDetailView").css("width", "620px");
        $("#newsDetailView").css("height", "600px");
        $("#newsDetailContainer").css("top", $(window).height() < 200 ? "0" : "30px");
    }

    $("#newsDetailContainer").css("z-index", "9999");

    $("#newsDetailContainer").fadeIn(600);
    $("#exposeMask").fadeIn(600);
    $("#exposeMask").click
        (
            function () {
                $("#newsDetailContainer").css("z-index", "");
                $("#newsDetailContainer").css("display", "none");
                $("#exposeMask").css("display", "none");
            }
        );
}

function HideDiv() {
    $("#newsDetailContainer").css("z-index", "");
    $("#newsDetailContainer").css("display", "none");
    $("#exposeMask").css("display", "none");
}

$().ready(
    function () {
        var cnt = 0;
        $("img.cmdRollover").each(
            function (e) {
                if ($(this).attr("id") === '' || $(this).attr("id") == null) {
                    $(this).attr("id", "CLImageRollover" + cnt);
                    cnt++;
                }
                var currentElement = $(this);
                $(this).wrap("<span id='" + $(this).attr("id") + "container'></span>")
                    .after('<img src="' + $(this).attr("src").replace("off", "on") + '" id="On_' + $(this).attr("id") + '" style="display:none;" border="0" />');
                $("#" + $(this).attr("id") + "container").hover(
                    function () {
                        currentElement.css("display", "none");
                        $("#On_" + currentElement.attr("id")).css("display", "");
                    },
                    function () {
                        currentElement.css("display", "");
                        $("#On_" + currentElement.attr("id")).css("display", "none");
                    }
                );
            }
        );
    }
);

$().ready(
        function () {

            $("a").focus(
                function () {
                    this.blur();
                }
            );
            $("[id^=contentsFrame]").css("height", $(window).height() - 40);

            $("#guideArrow").css("width", $(window).width() - 130);
            $("#guideArrow").css("top", $(window).height() / 2 - 60);
            $(".sectiontitle").click(
                function () {
                    $("." + $(this).attr("id")).contents().find(".jspPane").css("top", "0px");
                    $("." + $(this).attr("id")).contents().find(".jspDrag").css("top", "0px");
                    var moveTarget = 0;
                    switch ($(this).attr("id")) {
                        case "company":
                            moveTarget = 0;
                            break;
                        case "business1":
                            moveTarget = 1;
                            break;
                        case "business2":
                            moveTarget = 2;
                            break;
                        case "people":
                            moveTarget = 3;
                            break;
                        case "voice":
                            moveTarget = 4;
                            break;
                        default:
                            moveTarget = 0;
                            break;
                    }
                    movePosition(moveTarget);
                }
            );

            $("#btnLeft").click(
                function () {
                    if (nowPos > 0) {
                        //                        if (nowPos == 1) {
                        //                            $("#btnright").css("display", "block");
                        //                            $("#btnLeft").css("display", "none");
                        //                        }
                        //                        else {
                        //                            $("#btnright").css("display", "block");
                        //                            $("#btnLeft").css("display", "block");
                        //                        }
                        movePosition(--nowPos);
                    }
                }
            );
            $("#btnright").click(
                function () {
                    if (nowPos < 4) {
                        //                        if (nowPos == 3) {
                        //                            $("#btnright").css("display", "none");
                        //                            $("#btnLeft").css("display", "block");
                        //                        }
                        //                        else {
                        //                            $("#btnright").css("display", "block");
                        //                            $("#btnLeft").css("display", "block");
                        //                        }
                        movePosition(++nowPos);

                    }
                }
            );


            var isSubOver = false;
            var loadInterval = 0;
            $("[id^=menu]").each(
                    function () {
                        $(this).hover(
                            function () {
                                isSubOver = true;
                                $("[id^=menu]").css("background-color", "transparent");
                                $(this).css("background-color", "#2E3E47");
                                $(".submenu").css("display", "none");
                                $("#sub" + $(this).attr("id").replace("menu", "")).css("display", "block");
                            },
                            function () {
                                isSubOver = false;
                                clearInterval(loadInterval);
                                loadInterval = setInterval(function () {
                                    if (isSubOver == false) {
                                        $("[id^=menu]").css("background-color", "transparent");

                                        $(".submenu").css("display", "none");
                                    }
                                }, 300);
                            }
                        );
                    }
            );

            $(".submenu").each(
                function () {
                    $(this).hover(
                        function () {
                            isSubOver = true;
                        },
                        function () {
                            isSubOver = false;
                        }
                    );
                }
            );

        }

    );

$(window).resize(
            function () {
                $("#guideArrow").css("width", $(window).width() - 130);
                $("#guideArrow").css("top", $(window).height() / 2 - 60);
                //$(".contentsFrame").css("height", $(this).height() - 40);
                $("[id^=contentsFrame]").css("height", $(window).height() - 40);
            }
        );





function GetMoveString(moveInt) {
    var retStr = "";
    retStr = moveInt > 0 ? "+=" : "-=";
    moveInt = moveInt < 0 ? moveInt * -1 : moveInt;
    retStr += moveInt.toString() + "px";
    //alert(retStr);
    return retStr;
}
var cellWidth = 568;
function movePosition(pos) {
    $("." + contentID[pos]).contents().find(".jspPane").css("top", "0px");
    $("." + contentID[pos]).contents().find(".jspDrag").css("top", "0px");
    $("[id^=navOrg]").attr("src", "/Img/bg/pages_off.png");
    $("#navOrg" + pos).attr("src", "/Img/bg/pages_on.png");
    movePositionNoMove(pos);
}

function movePositionWithSubDirection(main, sub) {
    var subTop = "0px";
    if (main == 0) {
        switch (sub) {
            case 0:
                subTop = "0px";
                break;
            case 1:
                subTop = "-498px";
                break;
            case 2:
                subTop = "-764px";
                break;
            case 3:
                subTop = "-1103px";
                break;
            default:
                break;
        }
    }
    if (main == 1) {
        switch (sub) {
            case 0:
                subTop = "0px";
                break;
            case 1:
                subTop = "-930px";
                break;
            case 2:
                subTop = "-1377px";
                break;
            default:
                break;
        }
    }
    if (main == 2) {
        switch (sub) {
            case 0:
                subTop = "0px";
                break;
            case 1:
                subTop = "-1332px";
                break;
            case 2:
                subTop = "-1724px";
                break;
            case 3:
                subTop = "-2450px";
                break;
            default:
                break;
        }
    }
    if (main == 3) {
        switch (sub) {
            case 0:
                subTop = "0px";
                break;
            case 1:
                subTop = "-900px";
                break;
            case 2:
                subTop = "-2250px";
                break;
            default:
                break;
        }
    }
    if (main == 4) {
        switch (sub) {
            case 0:
                subTop = "0px";
                break;
            case 1:
                subTop = "-640px";
                break;
            case 2:
                subTop = "-1138px";
                break;
            case 3:
                subTop = "-1560px";
                break;
            default:
                break;
        }
    }
    else {

    }
    $("." + contentID[main]).contents().find(".jspPane").css("top", subTop);
    //$("." + contentID[pos]).contents().find(".jspDrag").css("top", "0px");
    movePositionNoMove(main);
}
function movePositionNoMove(pos) {
    nowPos = pos;
    movePosX = currentPosX - pos * cellWidth;
    currentPosX = pos * cellWidth;
    $("#block").animate({ "left": GetMoveString(movePosX) }, { duration: 500, queue: true, complete: function () { moved = false; } });
}

function SetCurrentDirection(pos) {
    if (pos == 0) {

        $("." + contentID[pos]).contents().find(".jspPane").css("top", "-1088px");

        //$("." + contentID[pos]).contents().find(".jspDrag").css("top", "0px");
    }
    else if (pos == 3) {
        $("." + contentID[pos]).contents().find(".jspPane").css("top", "-2385px");
    }
    movePositionNoMove(pos);
    HideDiv();
}
