
$(document).ready(function () {

    $("#fourBoxes .learnMoreBox").css({ 'opacity': '0' });
    $("#fourBoxes .learnMoreBox").css({ 'display': 'none' });
    $("#fourBoxes .box .boxBtn").click(function () {

        if ($(this).parent().hasClass('active')) {

            $("#fourBoxes .box").removeClass("active"); // remove active classes on all boxs
            $("#fourBoxes .box").stop().fadeTo(300, 1); // fade in all boxes
            $(".learnMoreBox").stop().fadeTo(400, 0);  // fade out all learn more boxes
            //$("#learnMoreWrapper").css("height", 0);
            $("#learnMoreWrapper").stop().animate({ height: 0 }, 500, function () { //height div up
                $(".learnMoreBox").css({ 'display': 'none' });
            });

            return false;

        } else {

            //$("#fourBoxes .box").stop().fadeTo(300, .5); //fade out boxes to half
            $(this).parent().stop().fadeTo(300, 1); //fade selected box to full
            $("#fourBoxes .box").removeClass("active"); //remove all active classes
            $(this).parent().addClass("active"); //add active class to current
            //$("#learnMoreWrapper").css("height", 172);
            $("#learnMoreWrapper").stop().animate({ height: 140 }, 500); //extend height of learn more box
            $(".learnMoreBox").stop().fadeTo(400, 0).hide(); //fade out all learn more boxes
            $(this).parent().find(".learnMoreBox").stop().fadeTo(800, 1).show(); //fade in current learn more boxes

            return false;
        }


    });

    $(".learnMoreClose").click(function () {
        $("#fourBoxes .box").removeClass("active"); // remove active classes on all boxs
        $("#fourBoxes .box").stop().fadeTo(300, 1); // fade in all boxes
        $(".learnMoreBox").stop().fadeTo(400, 0);  // fade out all learn more boxes
        //$("#learnMoreWrapper").css("height", 0);
        $("#learnMoreWrapper").stop().animate({ height: 0 }, 500, function () { //height div up
            $(".learnMoreBox").css({ 'display': 'none' });
        });
        return false;
    });

    ////////////////////////////////////////////////quickexit page method

    $('#quickExit').hover(function () {
        $(this).stop().animate({ width: 153 }, 500);
    }, function () {
        $(this).stop().animate({ width: 40 }, 500);
    });

    //    $('#quickExit').click(function () {
    //        window.location = "http://www.google.com";
    //    });

    $("#quickExit").click(function quickExit() {
        PageMethods.quickExit(OnSuccess);
    });

    function quickExit2() {
        PageMethods.quickExit(OnSuccess);
    }

    function OnSuccess(response, userContext, methodName) {
        //alert(response);
        window.location = "http://www.google.com";
    }

    ////////////////////////////////////////////////fade btns
    $('.fadeThis').append('<span class="hover"></span>').each(function () {
        var $span = $('> span.hover', this).css('opacity', 0);



        $(this).hover(function () {
            $span.stop().fadeTo(500, 1);
        }, function () {
            if ($(this).hasClass('.active')) {
            } else {
                $span.stop().fadeTo(500, 0);
            }
        });
    });


    ////////////////////////////////////////////////////////menu//////////////////////////
    function megaHoverOver() {
        //var ah = $(this).css('left'); //grab left of current LI hoverd
        var ah2 = $(this).find(".sub").height(); //grab height of submenu


        //bring current sub top 1

        $(this).find(".sub").css('z-index', '1000');
        //$(this).find(".sub2").css('top', 41);
        $(this).find("#mDivider").css('height', ah2); //adjust main divider to submenu's height
        //$(this).find(".sub2").css('left', ah); //adjust submenu's left position to current LI
        $(this).find(".sub").stop().fadeTo('fast', 1).show()
    }

    function megaHoverOut() {
        $(this).find(".sub").stop().fadeTo('fast', 0, function () {
            $(this).hide();
            $(this).css('z-index', '997');
        });

    }


    var config = {
        sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
        interval: 50, // number = milliseconds for onMouseOver polling interval    
        over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
        timeout: 50, // number = milliseconds delay before onMouseOut    
        out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
    };

    $("ul#mainNavLinks li .sub").css({ 'opacity': '0' });
    $("ul#mainNavLinks li .sub").css({ 'display': 'none' });
    $("ul#mainNavLinks li").hoverIntent(config);

    /////////////////anchor slide
    $(".scroll").click(function (event) {
        //prevent the default action for the click event
        event.preventDefault();

        //get the full url - like mysitecom/index.htm#home
        var full_url = this.href;

        //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
        var parts = full_url.split("#");
        var trgt = parts[1];

        //get the top offset of the target anchor
        var target_offset = $("#" + trgt).offset();
        var target_top = target_offset.top;

        //goto that anchor by setting the body scroll top to anchor top
        $('html, body').animate({ scrollTop: target_top }, 500);
    });

});

