//Get window height and pass to absolut eletment in navigation

jQuery.fn.maxLength = function (max) {
    this.each(function () {
        //Get the type of the matched element  
        var type = this.tagName.toLowerCase();
        //If the type property exists, save it in lower case  
        var inputType = this.type ? this.type.toLowerCase() : null;
        //Check if is a input type=text OR type=password  
        if (type == "input" && inputType == "text" || inputType == "password") {
            //Apply the standard maxLength  
            this.maxLength = max;
        }
        //Check if the element is a textarea  
        else if (type == "textarea") {
            //Add the key press event  
            this.onkeypress = function (e) {
                //Get the event object (for IE)  
                var ob = e || event;
                //Get the code of key pressed  
                var keyCode = ob.keyCode;
                //Check if it has a selected text  
                var hasSelection = document.selection ? document.selection.createRange().text.length > 0 : this.selectionStart != this.selectionEnd;
                //return false if can't write more  
                return !(this.value.length >= max && (keyCode > 50 || keyCode == 32 || keyCode == 0 || keyCode == 13) && !ob.ctrlKey && !ob.altKey && !hasSelection);
            };
            //Add the key up event  
            this.onkeyup = function () {
                //If the keypress fail and allow write more text that required, this event will remove it  
                if (this.value.length > max) {
                    this.value = this.value.substring(0, max);
                }
            };
        }
    });
}; 

$(document).ready(function () {
    // slide
    $(".slide-wrap").fadeTransition({ pauseTime: 4000,
        transitionTime: 1000,
        ignore: "#introslide",
        delayStart: 4000,
        pauseOnMouseOver: true,
        createNavButtons: true
    });

    $('#txtName').watermark('your name');
    $('#txtEmail').watermark('your e-mail address');
    $("#form1").validate({
        rules: {
            ctl00$ctl00$ctl00$ContentPlaceHolderDefault$Body$ctl02$txtName: { required: true, maxlength: 50 },
            ctl00$ctl00$ctl00$ContentPlaceHolderDefault$Body$ctl02$txtEmail: { required: true, email: true, maxlength: 250 },
            ctl00$ctl00$ctl00$ContentPlaceHolderDefault$Body$ctl02$ddlCategory: { required: true },
            ctl00$ctl00$ctl00$ContentPlaceHolderDefault$Body$ctl02$txtMessage: { required: true, maxlength: 1000 }
        },
        messages: {
            ctl00$ctl00$ctl00$ContentPlaceHolderDefault$Body$ctl02$txtName: { required: "Name is required", maxlength: "Name cannot be longer than 50 characters" },
            ctl00$ctl00$ctl00$ContentPlaceHolderDefault$Body$ctl02$txtEmail: { required: "Email is required", email: "Invalid Email specified", maxlength: "Email cannot be longer than 250 characters" },
            ctl00$ctl00$ctl00$ContentPlaceHolderDefault$Body$ctl02$ddlCategory: "Category is required",
            ctl00$ctl00$ctl00$ContentPlaceHolderDefault$Body$ctl02$txtMessage: { required: "Message is required", maxlength: "Message cannot be longer than 250 charaters" }
        },
        errorContainer: ".errorContainer",
        errorLabelContainer: ".errorLabelContainer",
        errorElement: "li",
        focusInvalid: false,
        invalidHandler: $.watermark.showAll
    });

    //blurb fade in out
    $('#our-services').parent().hover(function () {
        $(".blurb").stop(true, true).fadeOut();
    }, function () {
        $(".blurb").stop(true, true).fadeIn();
    });

    $("#txtMessage").maxLength(1000);  
});

