var slideshow = {

    rotationSpeed: 10000,
    transitionSpeed: 1000,

    rotateSlides: function (newslide) {
        $("#rotator > div:not('#rotator-nav')").fadeOut(slideshow.transitionSpeed);
        $("#rotator div#slide" + (newslide + 1)).fadeIn(slideshow.transitionSpeed);
        $("#rotator-nav li").removeClass("active");
        $("#rotator-nav li#nav" + newslide).addClass("active");
        currentslide = 0;
        slideid = newslide;
        if (newslide < slidecount - 1) {
            currentslide = newslide + 1;
        }
        rt = setTimeout("slideshow.rotateSlides(" + currentslide + ")", slideshow.rotationSpeed);
    },

    initializeNav: function () {
        $("#rotator-nav li").click(function () {
            clearTimeout(rt);
            var id = this.id.replace("nav", "");
            if (parseInt(slideid) !== parseInt(id)) {
                slideshow.rotateSlides(parseInt(id));
            } else {
                if (slideid < slidecount - 1) {
                    currentslide = slideid + 1;
                }
                rt = setTimeout("slideshow.rotateSlides(" + currentslide + ")", slideshow.rotationSpeed);
            }
        });
    },

    initialize: function () {
        var i = 0;
        var navcontainer = $("<div/>").attr("id", "rotator-nav").appendTo("#rotator");
        var nav = $("<ul/>").appendTo(navcontainer).css("display", "none");
        $("#rotator > div:not('#rotator-nav')").each(function () {
            var navitem = $("<li/>").attr("id", "nav" + i).html(i + 1).appendTo(nav);
            if (i > 0) {
                $(this).css("display", "none");
            } else {
                navitem.addClass("active");
            }
            $(this).css("position", "absolute");
            i++;
        });
        slidecount = i;
        slideid = 0;
		if (slidecount > 1) {
			nav.css("display", "block");
			slideshow.initializeNav();
			rt = setTimeout("slideshow.rotateSlides(1)", slideshow.rotationSpeed);
		}
    }

}

if ($("#rotator").length) {
    slideshow.initialize();
}

var preload = $('<img />').attr('src', '/wp-content/themes/ondine/images/dropdown-bg.png');
$(".nav li:not(.nav li li)").hover(function() {
	$(this).addClass("hover");
	$("ul", this).show().css("z-index", "1000");
}, function() {
	$(this).removeClass("hover");
	$("ul", this).hide();
});

if ($(".page").length && $("#press-release-nav").length === 0) {
	var target = $("#content").height() - 24;
	if (target > $(".page").height()) {
		$(".page").css("height", target + "px");
	}
}
var pto;
function showPressReleases(year) {
	clearTimeout(pto);
	$(".press-releases").hide();		
	$("#press-releases-" + year).show();
	$("#press-release-nav a").removeClass("active");
	$("#press-release-nav a#p" + year).addClass("active");
	pto = setTimeout("showPressReleases(" + year + ")", 250);
}

if ($("#press-release-nav").length) {
	var url = document.location.href.split("#");
	if (url.length < 2) {
		url = $("#press-release-nav a.active").attr("href").split("#");
	}
	showPressReleases(url[1]);
	$("#press-release-nav a").click(function() {
		var year = this.href.split("#");
		showPressReleases(year[1]);
	});
}

$(".nav ul li ul li:last-child").addClass("last");
