﻿jQuery(document).ready(function () {
    $('#carousel').show();
    $('#carousel').cycle({
        speed: 'fast',
        timeout: 5000,
        pager: '#jcarousel-control',
        slideExpr: 'li',
        before: function () {
            hideAllHeros();
            hideVideo();
            hideVideoContainerThumbs();
            $("#heroBlackBackground").fadeOut();

        }
    });

    $('#quickFindZip').mask("99999");
    $("#txtZipCode").mask("99999");
    $("#txtPhone").mask("(999) 999-9999");
    $("#txtWeight").Watermark("weight in lbs.");
    $("#txtWeight").mask("999");

    $('#btnBMI').click(function () {
        var hasError = false;

        var weightVal = $('#txtWeight').val();
        if (weightVal == '') {
            $("#bmiFormError").append('<div>Please enter your weight.</div>');
            hasError = true;
        }

        if (hasError == true) { return false; }
    });

    $('#btn-signup').click(function () {
        $(".error").hide();
        $("#regFormError").empty();
        var hasError = false;

        var firstnameVal = $('#txtFirstName').val();
        var lastnameVal = $('#txtLastName').val();

        if (firstnameVal == '') {
            $("#regFormError").append('<div>Please enter your first name.</div>');
            hasError = true;
        }
        if (lastnameVal == '') {
            $("#regFormError").append('<div>Please enter your last name.</div>');
            hasError = true;
        }

        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

        var emailaddressVal = $("#txtEmail").val();
        if (emailaddressVal == '') {
            $("#regFormError").append('<div>Please enter your email address.</div>');
            hasError = true;
        }
        else if (!emailReg.test(emailaddressVal)) {
            $("#regFormError").append('<div>Enter a valid email address.</div>');
            hasError = true;
        }

        var zipcodeVal = $('#txtZipCode').val();

        if (zipcodeVal == '') {
            $("#regFormError").append('<div>Please enter your zipcode.</div>');
            hasError = true;
        }

        var phoneNumberVal = $('#txtPhone').val();

        if (phoneNumberVal == '') {
            $("#regFormError").append('<div>Please enter your phone number.</div>');
            hasError = true;
        }

        if (hasError == true) { return false; }

    });

    $('#heroNavVIPPass').click(function () {
        if ($('#hero7DayVIPPass').is(":visible") != true) {
            hideAllHeros();
            showHero();
            $('#hero7DayVIPPass').fadeIn();
        }
    });

    $('#heroNavGym').click(function () {
        if ($('#heroGym').is(":visible") != true) {
            hideAllHeros();
            showHero();
            $('#heroGym').fadeIn();
        }
    });

    $('#heroNavBMI').click(function () {
        if ($('#heroBMI').is(":visible") != true) {
            hideAllHeros();
            showHero();
            $('#heroBMI').fadeIn();
        }
    });

    $('#heroNavClasses').click(function () {
        if ($('#heroClasses').is(":visible") != true) {
            hideAllHeros();
            showHero();
            $('#heroClasses').fadeIn();
        }
    });

    $('#heroNavVideos').click(function () {
        if ($('#heroVideos').is(":visible") != true) {
            hideAllHeros();
            showHero(true);
            $('#regFormWrapper').css('z-index', '0');
            $('#heroVideos').fadeIn();
        }
    });

    function showHero(hideClose) {
        $("#heroBlackBackground").show();
        $('#carousel').cycle('pause');
        if (!hideClose) {
            $('#close').fadeIn();
            $('#regFormWrapper').attr('class', 'regFormWrapperBG');
        }
    }

    function hideAllHeros() {
        $('#hero7DayVIPPass').fadeOut();
        $('#heroGym').fadeOut();
        $('#heroBMI').fadeOut();
        $('#heroClasses').fadeOut();
        $('#heroVideos').fadeOut();
        $('#close').fadeOut();
        $('#regFormWrapper').css('z-index', '42');
        $('#regFormWrapper').attr('class', '');
    }

    $('#close').click(function () {
        hideAllHeros();
        $("#heroBlackBackground").fadeOut();
    });

    $('.vidStrongstories').hover(
            function () {
                $(this).attr('src', 'html/images/strongstories2.jpg');
            },
            function () {
                $(this).attr('src', 'html/images/strongstories.jpg');
            }
        ).click(function () {
        	
            if ($('#videoStrongstories').is(":visible") != true) {
                $("#videoContainer").fadeIn();
                $("#videosVertical").fadeIn();
                $("#videos").fadeOut();
                hideVideo();
                $("#videoStrongstories").fadeIn();
            }
        });

    $('.vidWearestrong').hover(
            function () {
                $(this).attr('src', 'html/images/wearestrong2.jpg');
            },
            function () {
                $(this).attr('src', 'html/images/wearestrong.jpg');
            }
        ).click(function () {

            if ($('#videoWearestrong').is(":visible") != true) {
                $("#videoContainer").fadeIn();
                $("#videosVertical").fadeIn();
                $("#videos").fadeOut();
                hideVideo();
                $("#videoWearestrong").fadeIn();
            }
        });

    $('.vidPat').hover(
            function () {
                $(this).attr('src', 'html/images/pat2.jpg');
            },
            function () {
                $(this).attr('src', 'html/images/pat.jpg');
            }
        ).click(function () {

            if ($('#videoPat').is(":visible") != true) {
                $("#videoContainer").fadeIn();
                $("#videosVertical").fadeIn();
                $("#videos").fadeOut();
                hideVideo();
                $("#videoPat").fadeIn();
            }
        });

    $('.vidErin').hover(
            function () {
                $(this).attr('src', 'html/images/erin2.jpg');
            },
            function () {
                $(this).attr('src', 'html/images/erin.jpg');
            }
        ).click(function () {

            if ($('#videoErin').is(":visible") != true) {
                $("#videoContainer").fadeIn();
                $("#videosVertical").fadeIn();
                $("#videos").fadeOut();
                hideVideo();
                $("#videoErin").fadeIn();
            }
        });

    $('.vidHarry').hover(
            function () {
                $(this).attr('src', 'html/images/harry2.jpg');
            },
            function () {
                $(this).attr('src', 'html/images/harry.jpg');
            }
        ).click(function () {

            if ($('#videoHarry').is(":visible") != true) {
                $("#videoContainer").fadeIn();
                $("#videosVertical").fadeIn();
                $("#videos").fadeOut();
                hideVideo();
                $("#videoHarry").fadeIn();
            }
        });


    function hideVideoContainerThumbs() {
        $("#videoContainer").fadeOut();
        $("#videosVertical").fadeOut();
        $("#videos").fadeIn();
    }

    function hideVideo() {
        $("#videoStrongstories").hide();
        $("#videoWearestrong").hide();
        $("#videoPat").hide();
        $("#videoErin").hide();
        $("#videoHarry").hide();
    }

    $('#closeVideos').click(function () {
        $("#videoContainer").fadeOut();
        $("#videosVertical").fadeOut();
        $("#videos").fadeIn();
        $("#closeVideos").fadeOut();
        $("#close").fadeIn();
    });
});

