/// <reference path="libraries/jquery-vsdoc2.js" />

var runOnceScript = false;

function pageLoad() {

    $(document).ready(function () {

        if (!runOnceScript) {

            $('div#utility-panel input:submit').click(function () {
                ValidationItems();
                if ($('div#utility-panel div.sign-in fieldset div.validation-summary:visible').length > 1) {
                    $('div#utility-panel div.sign-in fieldset div.validation-summary:first').hide();
                }
                if (Page_IsValid) {
                    $('body').css('cursor', 'progress');
                };
            });

            if ($('div#utility-panel span.validation-item:visible')) {
                $('body').css('cursor', 'default');
            };

            // Hide forgotten password panel and toggle link
            $('div#utility-panel div.sign-in ul.secondary-link').prepend('<li><a href="/" id="forgotten-password-link">Password forgotten?</a></li>');
            $('div#utility-panel div.forgotten').hide();
            $('div#utility-panel div.sign-in a#forgotten-password-link').click(function (event) {
                event.preventDefault();
                if ($('div#utility-panel div.forgotten').is(':visible')) {
                    $('div#utility-panel div.forgotten').slideUp('slow');
                } else {
                    $('div#utility-panel div.forgotten').slideDown('slow');
                }
            });

            function ValidationItems() {
                $('div#utility-panel fieldset ul li').each(function () {
                    if ($('span.validation-item', this).is(':visible')) {
                        $('span.validation-item', this).text("");
                    } else {
                        $('span.validation-item', this).text("");
                    };
                });
            }

            // Use lightbox technique for popup elements
            $("div#standard-layout a.popup").mousedown(function (event) {
                event.preventDefault();
                var maintitle = this.title || $(this).text();
                $(this).lightBox({ iframeUrl: this.href, boxTitle: maintitle, iframeWidth: 700, iframeHight: 600 });
            });

            runOnceScript = true;

            // Create spy effect for winners comments panel
             $('.carousel').simpleSpy('6', '4000');
             $('div.spyWrapper').css('height', '546px').css('overflow', 'hidden');

                // Slide down effect for showing more text content        
                $('div#standard-layout div.introduction div.panel-container div.intro-description a.show-more').click(function (event) {
                    event.preventDefault();

                    if ($('div#standard-layout div.introduction div.panel-container div.intro-description div#show-more').css('display') == 'none') {
                        $('div#standard-layout div.introduction div.panel-container div.intro-description div#show-more').css("display", "block;").slideDown("slow");
                        $('div#standard-layout div.introduction div.panel-container div.intro-description a.show-more').text('Hide');
                    } else {
                        $('div#standard-layout div.introduction div.panel-container div.intro-description div#show-more').css("display", "none;").slideUp("slow");
                        $('div#standard-layout div.introduction div.panel-container div.intro-description a.show-more').text('Show More');
                    }
                });

        };

    });
};


