jQuery(document).ready(function($) {

    // On page form validator
    function checkCustomerInfo(myform) {
        for(i=0;i<myform.elements.length;i++) {
            if(myform.elements[i].value=="") {
                alert("Please fill out all required fields.");
                myform.elements[i].focus();
                return false;
            }
        }
        if(!validate_email(myform.email_address)) {
            alert("Not a validate email address.");
            myform.email_address.focus();
            return false;
        }
        if(!validate_email(myform.password.value!=myform.password2.value)) {
            alert("Not same password.");
            myform.password.focus();
            return false;
        }
        return true;
    }

    function validate_email(field)
    {
        apos=field.value.indexOf("@")
        dotpos=field.value.lastIndexOf(".")
        if (apos<1||dotpos-apos<2)
        {
            return false
            }
        else {
            return true
            }
    }


    //Fade and Transition Effects in header, requires jquery

    $(function(){

        // Main navigation links will light up on hover and fade afterward
        $("#navigation a").hover(function(){
            $(this).fadeTo(200, 1.0); // Set opacity to 100% on hover
        },function(){
            $(this).fadeTo(200, 0.6); // Set the opacity back to 60% on mouseout
        });

        $("#.sub h2 a").hover(function(){
            $(this).fadeTo(200, 0.6); // Set opacity to 100% on hover
        },function(){
            $(this).fadeTo(200, 1.0); // Set the opacity back to 60% on mouseout
        });

        // My Account and My Cart links will light up on hover and fade back afterward
        $("#nav-support a").hover(function(){
            $(this).fadeTo(200, 0.6); // Set the opacity to 100% on hover
        },function(){
            $(this).fadeTo(200, 1.0); // Set the opacity back to 60% on mouseout
        });

        // Header Logo will fade on hover, and go back afterward
        $("#logo").hover(function(){
            $(this).fadeTo(200, 0.8); // Set the opacity to 80% on hover
        },function(){
            $(this).fadeTo(200, 1.0); // Set the opacity back to 100% on mouseout
        });

        $(".panel-overlay").hover(function(){
            $(".panel-overlay").animate({
                "height": "230px"
            }, {
                duration: "medium"
            });
        });


        $('#feature').hover(
            function() {
                $(".panel-overlay").animate({
                    height: "65px",
                    "opacity": "1"
                }, {
                    duration: "medium"
                });
            },
            function() {
                $(".panel-overlay").animate({
                    height: "0px",
                    "opacity": "0"
                }, {
                    duration: "slow"
                });
            }
            );

    });

    //Add the "active" class to sidemenu links representing current page
    $(function($) {
        var path = location.pathname.substring(1);
        $('.sidemenu a[href="'+path+'"]').addClass('active');
    });



    <!--  Mega Dropdown Menus  -->

    function megaHoverOver(){
        $(this).find(".sub").stop().fadeTo('fast', 1).show();
    }

    function megaHoverOut(){
        $(this).find(".sub").stop().fadeTo('fast', 0, function() {
            $(this).hide();
        });
    }

    var config = {
        sensitivity: 5, // number = sensitivity threshold (must be 1 or higher)
        interval: 100, // number = milliseconds for onMouseOver polling interval
        over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
        timeout: 500, // number = milliseconds delay before onMouseOut
        out: megaHoverOut // function = onMouseOut callback (REQUIRED)
    };

    $("ul.level-1 li .sub").css({
        'opacity':'0'
    });

    $("ul.level-1 li").hoverIntent(config);


    jQuery.noConflict();

});
