﻿// START DOCUMENT READY
$(document).ready(function() {

var time = 500;
        var block_timer = null;
        
        // START BLOCK ONE
        $("a.one img").hover(
            function() {
                $(this).attr("src", "/journey/market-top-left-hover.png");
                $(".block1").show();
                $(".block2").hide();
                $(".block3").hide();
                $(".block4").hide();
            },
            function() {
                $(this).attr("src", "/journey/market-top-left.png");
                if (block_timer == null) {
                    block_timer = setTimeout(function() {
                        $(".block1").hide();
                    }, time);
                }
            });

        $('.block1 img').mouseenter(function() {
            $("a.one img").attr("src", "/journey/market-top-left-hover.png");
            clearTimeout(block_timer);
            block_timer = null;
        });
        
        $('.block1').mouseleave(function() {
            $("a.one img").attr("src", "/journey/market-top-left.png");
            $(".block1").hide();
        });
        // END BLOCK ONE

        // START BLOCK TWO
        $("a.two img").hover(
            function() {
                $(this).attr("src", "/journey/market-top-right-hover.png");
                $(".block1").hide();
                $(".block2").show();
                $(".block3").hide();
                $(".block4").hide();
            },
            function() {
                $(this).attr("src", "/journey/market-top-right.png");
                if (block_timer == null) {
                    block_timer = setTimeout(function() {
                        $(".block2").hide();
                    }, time);
                }
            });

        $('.block2 img').mouseenter(function() {
            $("a.two img").attr("src", "/journey/market-top-right-hover.png");
            clearTimeout(block_timer);
            block_timer = null;
        });

        $('.block2').mouseleave(function() {
            $("a.two img").attr("src", "/journey/market-top-right.png");
            $(".block2").hide();
        });
        // END BLOCK TWO

        // START BLOCK THREE
        $("a.three img").hover(
            function() {
                $(this).attr("src", "/journey/market-bottom-left-hover.png");
                $(".block1").hide();
                $(".block2").hide();
                $(".block3").show();
                $(".block4").hide();
            },
            function() {
                $(this).attr("src", "/journey/market-bottom-left.png");
                if (block_timer == null) {
                    block_timer = setTimeout(function() {
                        $(".block3").hide();
                    }, time);
                }
            });

        $('.block3 img').mouseenter(function() {
            $("a.three img").attr("src", "/journey/market-bottom-left-hover.png");
            clearTimeout(block_timer);
            block_timer = null;
        });

        $('.block3').mouseleave(function() {
            $("a.three img").attr("src", "/journey/market-bottom-left.png");
            $(".block3").hide();
        });
        // END BLOCK THREE

        // START BLOCK FOUR
        $("a.four img").hover(
            function() {
                $(this).attr("src", "/journey/market-bottom-right-hover.png");
                $(".block1").hide();
                $(".block2").hide();
                $(".block3").hide();
                $(".block4").show();
            },
            function() {
                $(this).attr("src", "/journey/market-bottom-right.png");
                if (block_timer == null) {
                    block_timer = setTimeout(function() {
                        $(".block4").hide();
                    }, time);
                }
            });

        $('.block4 img').mouseenter(function() {
            $("a.four img").attr("src", "/journey/market-bottom-right-hover.png");
            clearTimeout(block_timer);
            block_timer = null;
        });

        $('.block4').mouseleave(function() {
            $("a.four img").attr("src", "/journey/market-bottom-right.png");
            $(".block4").hide();
        });
        // END BLOCK FOUR

    // START TOOLTIP
    $('.tooltip').hide();

    var tooltipTimer = 0;
    var auditTooltipTimer = 0;
    
    $('a.audit-tooltip').mouseenter(function() {
        var offset = $(this).offset();
        if ($(this).hasClass("map")) {
            $('.auditmessage').css('top', offset.top - 165);
        }
        else {
            $('.auditmessage').css('top', offset.top - 19);
        }
        $('.auditmessage').css('left', offset.left - 244);
        $('.auditmessage').show();
        clearTimeout(auditTooltipTimer);
    });

    $('a.create-tooltip').mouseenter(function() {
        var offset = $(this).offset();
        $('#template-1 .tooltip').css('top', offset.top - 315);
        $('#template-2 .tooltip').css('top', offset.top - 285);
        $('#template-3 .tooltip').css('top', offset.top - 315);
        $('#template-4 .tooltip').css('top', offset.top - 315);
        $('#template-5 .tooltip').css('top', offset.top - 315);
        $('#template-6 .tooltip').css('top', offset.top - 315);
        $('.tooltip').show();
        clearTimeout(tooltipTimer);
    });



    $('a.create-tooltip').mouseleave(function() {
        auditTooltipTimer = setTimeout(function() { hideTooltip() }, 500);
    });
    
    $('a.audit-tooltip').mouseleave(function() {
        tooltipTimer = setTimeout(function() { hideAuditTooltip() }, 50);
    });
    
    // END TOOLTIP

    //START SEARCH
    $("#btnSubmit").click(function() {
        window.location.href = "/page.aspx?pointerid=20a62849b3c14ee893c3942db3244924&txtSearch=" + $(".search-box").val();
    });

    $(".search-box").keypress(function(e) {
        if (e.keyCode == 13) {
            e.preventDefault();
            url = "/page.aspx?pointerid=20a62849b3c14ee893c3942db3244924&txtSearch=" + $(this).val();
            window.location.href = url;
        }
    });

    // END SEARCH

    // START PRINT
    $(".printer").click(function() {
        window.print()
    });
    // END PRINT

    // START SEARCH
    $('.search-box').click(function() {
        $(this).addClass("search-selected");
        $(this).removeClass("search-box");
        $(this).parent().removeClass("small").addClass("large");
        $(this).parent().parent().addClass("large");
    });

    $('.search-box').focusout(function() {
        $(this).addClass("search-box");
        $(this).removeClass("search-selected");
        $(this).parent().addClass("small").removeClass("large");
        $(this).parent().parent().removeClass("large");
        $(this).val("");
    });
    // END SEARCH

    var t1 = null;
    var t2 = null;

    // START BOARD MEMBER 1
    $(".board").hover(
    function() {

        clearTimeout(t1);
        t1 = setTimeout(function() {
            $(".board li img:not(.hover)").fadeTo(400, 0.5);
            $('#meet').fadeTo(0, 0.5);
        }, 100);


    },
    function() {

        clearTimeout(t2);
        t2 = setTimeout(function() {
            $(".board li img").fadeTo(400, 1);
            $('#meet').fadeTo(0, 1);
        }, 100);


    });
    // END BOARD MEMBER 1

    // START BOARD MEMBER 2
    $(".board li a img").hover(
    function() {
        $(this).addClass("hover");
        $(this).fadeTo(0, 1);

        if ($(this).parent().parent().hasClass('position-overwrite')) {
            $(this).parent().parent().find('div').css({ 'top': '360px', 'left': '0px' }).show();

        } else if ($(this).parent().parent().hasClass('one')) {
            $(this).parent().parent().find('div').css('left', '120px').show();

        } else if ($(this).parent().parent().hasClass('two')) {
            $(this).parent().parent().find('div').css('left', '240px').show();

        } else if ($(this).parent().parent().hasClass('three')) {
            $(this).parent().parent().find('div').css('right', '243px').show();

        } else {
            $(this).parent().parent().find('div').css('right', '123px').show();
        }
    },
    function() {
        $(this).removeClass("hover");
        $(this).fadeTo(0, 0.5);
        $("ul.board div").hide();
    });
    // END BOARD MEMBER 2

    

    // START ACCORDION
    //$('.acc-container').hide();
    $('.trigger').click(function(e) {
        e.preventDefault();
        if ($(this).parent().next(".acc-container").is(':hidden')) {
            $('.trigger').removeClass('acc-active').parent().next(".acc-container").slideUp();
            $(this).addClass('acc-active');
            $(this).parent().next(".acc-container").slideDown();
        } else {
            $('.trigger').removeClass('acc-active').parent().next().slideUp();
        }
    });
    //When indicating the accordion on the URL, this opens it and scrolls right to it
    $(".acc-container.active").each(function() {
        $(this).show();
        $('html, body').animate({
            scrollTop: $(this).prev().offset().top
        }, 2000);

    });

    // END ACCORDION

});
// END DOCUMENT READY

function boardFocus(focusedImage) {
    $("ul.board div").hide();
        $(focusedImage).addClass("hover");
        $(focusedImage).fadeTo(0, 1);

        if ($(focusedImage).parent().hasClass('position-overwrite')) {
            $(focusedImage).parent().find('div').css({ 'top': '360px', 'left': '0px' }).show();

        } else if ($(focusedImage).parent().hasClass('one')) {
            $(focusedImage).parent().find('div').css('left', '120px').show();

        } else if ($(focusedImage).parent().hasClass('two')) {
            $(focusedImage).parent().find('div').css('left', '240px').show();

        } else if ($(focusedImage).parent().hasClass('three')) {
            $(focusedImage).parent().find('div').css('right', '243px').show();

        } else {
            $(focusedImage).parent().find('div').css('right', '123px').show();
        }
    
//    function() {
//        $(this).removeClass("hover");
//        $(this).fadeTo(0, 0.5);
//        $("ul.board div").hide();
//    });
    
}

// START CHECK ALL FUNCTION
$(function() {
    $('.checkall').click(function() {
        $(this).parent('li:eq(0)').find(':checkbox').attr('checked', this.checked);
    });
});
// END CHECK ALL FUNCTION

// START DROP NAV FUNCTION
function hideDropdowns() {
    $('.drop-nav').hide();
}
// END DROP NAV FUNCTION

// START CLEAR TIMERS FUNCTION
function clearTimers() {
    clearTimeout(hideLiTimer);
    clearTimeout(hideDropTimer);
    clearTimeout(nonTopNavTimer);
}
// END CLEAR TIMERS FUNCTION

// START DYNAMIC SELECT FUNCTION
$(function() {
    $('.dynamic-select').bind('change', function() {
        var url = $(this).val();
        if (url != '') {
            window.location = url;
        }
        return false;
    });
});
// END DYNAMIC SELECT FUNCTION




// START TOOLTIP
function hideTooltip() {
    $('.tooltip').hide();
}
function hideAuditTooltip() {
    $('.auditmessage').hide();
}
// END TOOLTIP

// Generate the PDF
function generatePDF() {
    
    $("#error").html("");

    var valArray = $('input:checkbox').serializeArray();
    var PDFstr = "";
    jQuery.each(valArray, function(i, field){
        if (PDFstr.length > 0) {
            PDFstr = PDFstr + ",";
        }
        PDFstr = PDFstr + field.name;
    });
    
    if (PDFstr == "") {
        $("#error").html("<p style=\"color: #FF0000; font-weight: bold; margin-top: 12px\"><strong>Please select at least one section</p>");
    }
    else {
        dcsMultiTrack('DCS.dcsuri', "/outputPDF.aspx", 'WT.dl', '20');
        window.open("/outputPDF.aspx?data=" + PDFstr);
    }
    
}

    function navigateTo(inURL) {
        dcsMultiTrack('DCS.dcsuri', inURL, 'WT.dl', '20');
        window.open(inURL);
    }
