﻿$(document).ready(function () {
    $('.tabnav li').hover(function () {
        $(this).addClass('hover');
    }, function () {
        $(this).removeClass('hover');
    }).each(function () {
        var that = this;
        $(this).hover(function () {
            $('.tabnav li').each(function () {
                var e = $($(this).children()[0].getAttribute('rel')).removeClass('ui-tabs-selected');
                if (this === that) e.addClass('hover'); else e.removeClass('hover');
            });
        }, function () {
            $('.tabnav li').each(function () {
                var e = $($(this).children()[0].getAttribute('rel')).removeClass('hover');
                if ($(this).hasClass('ui-tabs-selected')) e.addClass('ui-tabs-selected');
            });
        });
    });

    // text box hinting
    var s = function () { if (this.value == '') { this.value = this.getAttribute('title'); $(this).addClass('hinting'); } };
    var r = function () { if (this.value == this.getAttribute('title')) { this.value = ''; $(this).removeClass('hinting'); } };
    $('input.hinted:text[title]').each(s).focus(r).blur(s).parents('form').submit(function () {
        $(this).children('input.hinting:text[title]').each(r);
    });

    // Home page
    $('.divisions li').hover(function () {
        $(this).find('h3').css('color', '#ffcc00');
        $(this).find('.feature .hover').clearQueue().fadeTo('fast', .85);
        //$(this).find('.feature').addClass('featureHover');
    }, function () {
        $(this).find('h3').css('color', '#ffffff');
        //$(this).find('.feature').removeClass('featureHover');
        $(this).find('.feature .hover').clearQueue().fadeTo('fast', 0);
    });

    $('p.poweredBySitefinityLogo').remove(); // HS 2010-07-19 - for demo purposes only - we have a real license for the real site... really.

    // Load and start carousel
    if ($("div#banners img").length > 1) {
        var b = $("div#banners");
        var f = function () { b.carousel({ loop: true, dispItems: 1, autoSlide: true, autoSlideInterval: 5000, effect: "fade", delayAutoSlide: 1 }); };
        if (b.carousel === undefined)
            $.getScript("/js/jquery.carousel.min.js", f);
        else
            f();
    }

    // $('ul.tabcontentnav li').each(function () { if ($(this).height() > 45) $(this).addClass('double'); });
    try { $.preloadCssImages(); } catch (x) { }

    $('input.btn[value=Find]').prev('input:text').keypress(function (e) { if (e.keyCode == 13) { e.preventDefault(); $(this).next('input.btn[value=Find]').click(); } });

    var p = $('div.photoArea img'); // .click(function () { alert('lightbox goes here'); });


    if (p.length > 0) {
        $.getScript("/js/thickbox-compressed.js");
        $('div.thumbs img').click(function () {
            // swap image urls(@s=)+alts for this and a
            var pi = p[0].src.lastIndexOf('&s=') + '&s='.length;
            var ti = this.src.lastIndexOf('&s=') + '&s='.length;

            var a = $(p[0]).parent('a.thickbox'); if (a.length > 0) { a[0].href = this.src.substr(ti); a[0].title = this.alt; }

            var s = p[0].src.substr(0, pi) + this.src.substr(ti);
            this.src = this.src.substr(0, ti) + p[0].src.substr(pi);
            p[0].src = s;

            s = p[0].alt; p[0].alt = this.alt; this.alt = s;
        });
    }
    if ($('.tabcontentnav').height() > $('.contentarea').height() + 115) $('.contentarea').height($('.tabcontentnav').height() - 115 + 'px');
});

if ($('div.tabdiv div.description div.text:visible').text() == '') $('div.tabdiv').css('height', '3px');
if ($('div.divisionContent').text().trim() == "") $('div.divisionContent').hide();
if ($('div.tabcontent').text().trim() == "Share this") $('div.tabcontent').hide();

