$(document).ready(function() {
    swapValues = [];
    $(".swap_value").each(function(i) {
        swapValues[i] = $(this).val();
        $(this).focus(function() {
            if ($(this).val() == swapValues[i]) {
                $(this).val("");
            }
        }).blur(function() {
            if ($.trim($(this).val()) == "") {
                $(this).val(swapValues[i]);
            }
        });
    });

    $("img.hover-swap").hover(function() {
        $(this).attr("src", $(this).attr("src").split(".").join("-hover."));
    }, function() {
        $(this).attr("src", $(this).attr("src").split("-hover.").join("."));
    });

    $("select").each(function() {
        if($(this).attr('class') != "month" && $(this).attr('class') != "nofancy") {
            $(this).selectbox();
        }
    });

    $(".month").monthselectbox();

    $("#login-form").submit(function(e) {
        e.preventDefault();
        data = $(this).serialize();

        $.ajax({
            'url'      : '/login',
            'type'     : 'post',
            'dataType' : 'html',
            'data'     : data,

            success: function(json) {
                window.location.href = '/home';
            },
            error: function(xhr) {
                $("#password").val("");
                if(xhr.responseText.length != 0) {
                    alert(xhr.responseText);
                } else {
                    alert("There was an error processing your login.  Please try again.");
                }
            }
        });
    });

   //below code is used to display registration form on modal window. Added by Gaurav Ahuja on 8.3.2011 ////

    var register = {
        message: null,
        init: function () {
            $("a.register").click(function(e) {
                e.preventDefault();
                // load the contact form using ajax
                $.post("/register", function(data) {
                    // create a modal dialog with the data
                    $(data).modal({
                        closeHTML: "<a href='#' title='Close' class='modal-close'>Close</a>",
                        position: ["15%",],
                        overlayId: 'register-overlay',
                        containerId: 'register-container',
                        onOpen: register.open,
                        onShow: register.show,
                        onClose: register.close,
                        zIndex: 99999
                    });
                });
            });
        },

        open: function(dialog) {
            $("#video iframe").fadeOut();
            dialog.overlay.fadeIn(function() {
                dialog.container.fadeIn(function() {
                    dialog.data.fadeIn();
                });
            });
        },

        close: function() {
            $.modal.close();
            $("#video iframe").show();
        }
    };
    register.init();

    if ($('#contact-form').length > 0) {
        $.get('contact/token', function(txt) {
            $('#contact-form').append('<input type="hidden" name="t" value="' + txt + '" />');
        });
    };

    $("#contact-form").submit(function(e) {
        e.preventDefault();
        data = $(this).serialize();

        $.ajax({
            'url'      : '/contact/post',
            'type'     : 'post',
            'dataType' : 'html',
            'data'     : data,

            success: function(html) {
                c = $("#contact");
                c.fadeOut('slow', function() {
                    c.html(html);
                });
                c.fadeIn();
            },
            error: function(xhr) {
                if(xhr.responseText.length != 0) {
                    alert(xhr.responseText);
                } else {
                    alert("There was an error validating your request, please try again.");
                }
            }
        });
    });
});
/*
jQuery.preloadImages = function() {
    for(var i = 0; i<arguments.length; i++) {
        jQuery("<img>").attr("src", arguments[i]);
    }
}
$.preloadImages("/images/nav-home.gif", "/images/nav-home-o.gif", "/images/nav-home-a.gif", "/images/nav-about-o.gif", "/images/nav-about.gif", "/images/nav-about-a.gif", "/images/nav-features-o.gif", "/images/nav-features-a.gif", "/images/nav-features.gif", "/images/nav-faq-o.gif", "/images/nav-faq.gif", "/images/nav-faq-a.gif", "/images/nav-demo-o.gif", "/images/nav-demo-a.gif", "/images/nav-demo.gif", "/images/login-btn-over.jpg", "/images/btn-submit-over.jpg", "/images/textField.gif", "/images/loginField.gif");

*/

