﻿
$(document).ready(function () {

    //    //On Hover Over
    //    function megaHoverOver() {
    //        $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
    //        (function ($) {
    //            //Function to calculate total width of all ul's
    //            jQuery.fn.calcSubWidth = function () {
    //                rowWidth = 0;
    //                //Calculate row
    //                $(this).find("ul").each(function () { //for each ul...
    //                    rowWidth += $(this).width(); //Add each ul's width together
    //                });
    //            };
    //        })(jQuery);

    //        if ($(this).find(".row").length > 0) { //If row exists...

    //            var biggestRow = 0;

    //            $(this).find(".row").each(function () {	//for each row...
    //                $(this).calcSubWidth(); //Call function to calculate width of all ul's
    //                //Find biggest row
    //                if (rowWidth > biggestRow) {
    //                    biggestRow = rowWidth;
    //                }
    //            });

    //            $(this).find(".sub").css({ 'width': biggestRow }); //Set width
    //            $(this).find(".row:last").css({ 'margin': '0' });  //Kill last row's margin

    //        } else { //If row does not exist...

    //            $(this).calcSubWidth();  //Call function to calculate width of all ul's
    //            $(this).find(".sub").css({ 'width': rowWidth }); //Set Width

    //        }
    //    }
    //    //On Hover Out
    //    function megaHoverOut() {
    //        $(this).find(".sub").stop().fadeTo('fast', 0, function () { //Fade to 0 opactiy
    //            $(this).hide();  //after fading, hide it
    //        });
    //    }

    //    //Set custom configurations
    //    var config = {
    //        sensitivity: 2, // 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#topnav li .sub").css({ 'opacity': '0' }); //Fade sub nav to 0 opacity on default
    //    $("ul#topnav li").hoverIntent(config); //Trigger Hover intent with custom configurations


    $("ul.sf-menu").superfish();
    //            $("#q").click(function () {
    //                $("#q").removeClass("google");
    //            });
    $('.slide-out-div').tabSlideOut({
        tabHandle: '.handle',                     //class of the element that will become your tab
        pathToTabImage: '/Content/images/Buttons/Follow-Us.jpg', //path to the image for the tab //Optionally can be set using css
        imageHeight: '122px',                     //height of tab image           //Optionally can be set using css
        imageWidth: '40px',                       //width of tab image            //Optionally can be set using css
        tabLocation: 'left',                      //side of screen where tab lives, top, right, bottom, or left
        speed: 300,                               //speed of animation
        action: 'click',                          //options: 'click' or 'hover', action to trigger animation
        topPos: '200px',                          //position from the top/ use if tabLocation is left or right
        leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
        fixedPosition: true                      //options: true makes it stick(fixed position) on scroll
    });

    $("#slideshow").cycle({
        speed: 1300,
        height: 350,
        pause: 1
    });

    $("#signUpSubmit").click(function () {
        var temp = $("#email").serializeObject()

        $.post("/Home/MailingList", temp, function (html) {
            if (html == "success") {
                $("#dialog").dialog('open');
            } else {
                $("#dialog2").dialog('open');
            }
        });
    });

    $("#email2").each(function () {

        this.value = $(this).attr('title');
        $(this).addClass('text-label');

        $(this).focus(function () {
            if (this.value == $(this).attr('title')) {
                this.value = '';
                $(this).removeClass('text-label');
            }
        });

        $(this).blur(function () {
            if (this.value == '') {
                this.value = $(this).attr('title');
                $(this).addClass('text-label');
            }
        });
    });

    $("#signUpSubmit2").click(function () {
        if ($("#email2").val() != "Enter Email") {
            var temp = $("#email2").serializeObject()

            $.post("/Home/MailingList", temp, function (html) {
                if (html == "success") {
                    $("#dialog").dialog('open');
                } else {
                    $("#dialog2").dialog('open');
                }
            });
        }
    });

    $.fn.serializeObject = function () {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function () {
            if (o[this.name]) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };

    $("#dialog").dialog({
        autoOpen: false,
        resizable: false,
        height: 140,
        modal: true,
        buttons: {
            "OK": function () {
                $(this).dialog("close");
            }
        }
    });

    $("#dialog2").dialog({
        autoOpen: false,
        resizable: false,
        height: 240,
        modal: true,

        buttons: {
            "OK": function () {
                $(this).dialog("close");
            }
        }
    });

});
