﻿
App = function() {

    /* Private */

    /* Properties */

    var cmp = {};





    /* Methods */

    var init = function() {

        /* Constructor */

        TVI.Forms.handlerURL = '/handlers/'; 
        TVI.Data.defaultURL = '/handlers/Data.aspx/query';

        // Watermark for the newsletter signup
        $('#newsletterForm-email INPUT').focus(function() {
            if ($(this).val() == 'Email Address...') {
                $(this).val('');
            }
        });
        $('#newsletterForm-email INPUT').blur(function() {
            if ($(this).val() == '') {
                $(this).val('Email Address...');
            }
        });


        // Create newsletter signup form
        App.newsletterForm = new TVI.Form({
            ID: 'newsletterForm',
            buttons: [{

                selector: '.submit A',
                enter: true,
                handler: function() {

                    submitNewsletterEmail();

                }

}]

            });

            /* To fix IE6 z-index bug (reverse stack order */
            var i = 1000;
            $('#mainMenu LI').each(function() {

                $(this).css('z-index', i);

                i--;
            });

            /* show/hide dropdown */
            $('#mainMenu LI').mouseenter(function() {

                if ($(this).find('UL LI').length > 0) {
                    $(this).find('UL').show();

                    $(this).mouseleave(function() {

                        $(this).find('UL').hide();

                    });
                }

            });

        };


        var submitNewsletterEmail = function() {

            // Submit the Form
            App.newsletterForm.submit({

                query: 'insertNewsletterEmail',
                success: function() {

                    App.newsletterForm.el.find('.fields').hide();
                    $('#newsletterSignup').css({ 'background': 'url(i/newsletterThanksBack.jpg)' });

                }

            });

        };




        /* Public */

        TVI.apply(cmp, {

            /* Properties */

            test: 'test',

            /* Methods */

            test: function() {

                /* Test function  */

            }

        });


        TVI.ready(init);


        return cmp;


    } ();
