$(document).ready(function () {

    var isIE6 = ($.browser.msie && $.browser.version.substr(0, 1) < 7);
    
    // This is the simplified img hover script
    $('img[hvr]').hover(function () {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hvr'));
        $(this).attr('hvr', currentImg);
    }, function () {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hvr'));
        $(this).attr('hvr', currentImg);
    });

    // This adds a watermark to the textbox using the ToolTip attribute for <asp:TextBox or the Title attribute on input.
    $("input[title]").each(function () {
        if ($(this).attr('title') != '') {
            $(this).val($(this).attr('title'));
            $(this).addClass("water");
        }
    }).focus(function () {
        if ($(this).val() == $(this).attr('title')) {
            $(this).val("");
            $(this).removeClass("water");
        }
    }).blur(function () {
        if ($.trim($(this).val()) == "") {
            $(this).val($(this).attr('title'));
            $(this).addClass("water");
        }
    });

    // Autocreate captions for images.
    $("img[longdesc]").each(function () {

        $(this).wrap('<div class="autoImage" />');
        $(this).after('<div class="autoImageCaption">' + $(this).attr('longdesc') + '</div>');
        $(this).parent().attr('style', $(this).attr('style')).attr('class', $(this).attr('class'));
        $(this).removeAttr("style").removeAttr("class");

    });


});


;var DDSPEED = 10;
var DDTIMER = 15;

// main function to handle the mouse events //
function ddMenu(id, d) {
    var h = document.getElementById(id + '-ddheader');
    var c = document.getElementById(id + '-ddcontent');
    clearInterval(c.timer);
    if (d == 1) {
        
        showRainbow(); // show the bar

        clearTimeout(h.timer);
        if (c.maxh && c.maxh <= c.offsetHeight) { return }
        else if (!c.maxh) {
            c.style.display = 'block';
            c.style.height = 'auto';
            c.maxh = c.offsetHeight;
            c.style.height = '0px';
        }
        c.timer = setInterval(function () { ddSlide(c, 1) }, DDTIMER);
    } else {

        hideRainbow(); // hide rainbow bar;

        h.timer = setTimeout(function () { ddCollapse(c) }, 50);
    }
}

// collapse the menu //
function ddCollapse(c) {
    c.timer = setInterval(function () { ddSlide(c, -1) }, DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id) {
    var h = document.getElementById(id + '-ddheader');
    var c = document.getElementById(id + '-ddcontent');
    clearTimeout(h.timer);
    clearInterval(c.timer);
    if (c.offsetHeight < c.maxh) {
        c.timer = setInterval(function () { ddSlide(c, 1) }, DDTIMER);
    }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c, d) {
    var currh = c.offsetHeight;
    var dist;
    
    if (d == 1) { // if we're growing
        //   dist = (Math.round((c.maxh - currh) / DDSPEED));]
        dist = Math.round(c.maxh - currh);
        var height = currh + (dist * d) + 'px';
        c.style.height = height;
        c.style.opacity = 100;
        

    } else { // if we're shrinking

        if (dist != 0) {
            // dist = (Math.round(currh / DDSPEED));
            dist = 0;
            c.style.opacity = 100;
            c.style.height = 0;
        }

    }

    if (dist <= 1 && d == 1) {
        dist = 1;
    }


    
    if ((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)) {
        clearInterval(c.timer);
    }
}



function showRainbow() {

    
    $("#RainbowBar").children().removeClass("hidden");

}

function hideRainbow() {

    
    $("#RainbowBar").children().addClass("hidden");

};//jQuery, jCycle slideshow.
$(document).ready(function() {
    $('.slideshow').cycle({
        fx: 'fade',
        speed: '4000',
        sync: true
	});
});
//end slideshow js
