﻿/// <reference path="jQuery/jquery-1.4.1-vsdoc.js" />

// main.js

var vh = {
    /**
    * Initializes script behavior.
    */
    init: function() {
        this.setNavigation();
        this.setTextReplacements();
        this.setExternalLinks();
        this.setColumns();

        // Home Page - Slideshow
        if ($j(".slideshow").length > 0) {
            this.slideshow.init();
        }

        // Events
        if ($j(".event-listing-page").length > 0) {
            // Set the color of the previous and next month links. This overrides
            // the inline style that the control is rendering with.
            $j("#ctl00_plcMain_calItems_calItems table td a").removeAttr("style");
            $j("#ctl00_plcMain_calItems_calItems table td a").css("color", "#fff");
        }
    },

    setColumns: function() {
    $j(".content").equalHeights(100,9000);
    },

    /**
    * Sets up the main navigation event handlers.
    */
    setNavigation: function() {
        $j("#primarynav > li").mouseover(function() {
            // Add "hover" class to the current LI.
            $j(this).addClass("hover");
            $j(this).css("z-index", 101);
            // Show the dropdown panel.
            var panel = $j(this).find(".panel");
            panel.css("z-index", 150);
            panel.show();
        });

        $j("#primarynav > li").mouseout(function() {
            // Remove "hover" class from the current LI.
            $j(this).removeClass("hover");
            $j(this).css("z-index", 100);
            // Hide the dropdown panel.
            var panel = $j(this).find(".panel");
            panel.css("z-index", 100);
            panel.hide();
        });
    },

    /**
    * Changes the click event of ".external" links - opens link in new window.
    */
    setExternalLinks: function() {
        $j("a.external").click(function() {
            window.open(this.href);
            return false;
        });
    },

    /**
    * Executes the text replacement, depends on "fontwriter" HTTP handler.
    */
    setTextReplacements: function() {
        // "fontWriterUrl" should be a relative path to the location of the 
        // FontWriter web handler file (.ashx).
        var fontWriterUrl = "/CMSTemplates/VadnaisHeights/FontWriter/fontwriter.ashx";

        // "fontsPath" should be a relative path (relative to the location of
        // the FontWriter web handler file (.ashx)) to the directory that 
        // contains the font files utilized by the FontWriter web handler.
        //var fontsPath = "../../../../VadnaisHeights.Fonts/";

        // RE: sizing the type in the image
        // Measure the type in the PSD, measuring from the top of the letterform
        // to the bottom, including the anti-aliasing. Set the "size" parameter
        // to this px dimension, and omit the "height" parameter.

        var isInternetExplorerLessThanVersion7 = false;
        if ($j.browser.msie && ($j.browser.version.substr(0, 1) < 7)) {
            isInternetExplorerLessThanVersion7 = true;
        }

        if (isInternetExplorerLessThanVersion7 == false) {
            // h1.fw - Trade Gothic Bold Conensed 28px/18px
            $j("h1.fw").each(function() {
                var text = $j(this).html().toUpperCase();
                if (text.length > 0) {
                    $j(this).html('<img src="' + fontWriterUrl + '?' +
                    'bcolor=transparent&color=ffffff&font=LTe50543.ttf&size=22&text=' +
                    escape(text) + '" alt="' + text + '"/>');
                }
            });

            // h2.fw - Trade Gothic Bold Condensed - 13px/15px
            $j("h2.fw").each(function() {
                var text = $j(this).html().toUpperCase();
                if (text.length > 0) {
                    $j(this).html('<img src="' + fontWriterUrl + '?' +
                    'bcolor=transparent&color=ffffff&font=LTe50543.ttf&size=13&text=' +
                    escape(text) + '" alt="' + text + '"/>');
                }
            });
        }
    }
}

/**
 * Object that handles the slideshow functionality
 */
vh.slideshow = {
    slides: new Array(),
    currentIndex: 0,
    numSlides: 0,
    slideDuration: "10s",

    /**
    * Initializes the in-page slideshow.
    */
    init: function() {
        this.slides = $j(".slide");
        this.numSlides = this.slides.length;
        // Remove ".slide-no-js" class. ".slide-no-js" is applied to all .slide
        // by default to ensure that if JavaScript is disabled, only the first
        // slide image will be visible.
        $j(".slide").removeClass("slide-no-js");
        // Hide all slides.
        $j(".slide").hide();
        // Show the first slide.
        $j(this.slides[this.currentIndex]).show();
        // Set reference to this scope.
        var that = this;
        // Set timer to change slides.
        $j(document).everyTime(that.slideDuration, function() { that.showNextSlide(); }, 0);
    },

    /**
    * Changes the slide that is displayed.
    */
    showNextSlide: function() {
        // Determine the next slide index.
        var nextIndex = this.currentIndex + 1;
        if (nextIndex === this.numSlides) {
            nextIndex = 0;
        }
        // Set reference to this scope.
        var that = this;
        // Hide and show slides.
        $j(this.slides[this.currentIndex]).fadeOut("slow", function() {
            $j(that.slides[nextIndex]).fadeIn(1000);
        });
        // Update the stored index.
        this.currentIndex = nextIndex;
    }
}

// With default configuration, jQuery and Prototype will conflict. If we are
// using Kentico's lightbox web part (which depends on Prototype), we must set
// jQuery to not take control of "$". Instead, use "$j" in place of "$".
var $j = jQuery.noConflict();

$j(document).ready(function() {
    vh.init();
});

// EOF
