﻿// perform JavaScript after the document is scriptable.
$(document).ready(function () {
	//always do
    $("h1,h2,h3,h4,h5").wrapInner("<span />");

    // Remove span from content ticker
    $("div#tickercontent h3 span").remove()

    // rotation
    var imagecount = 0;
    var count = 0;

    function rotateblocks(n, p) {
        var delay = p;
        var total = 0;

        n.find("a").each(function (i) {
            if (i != 0) $(this).hide();
            $(this).addClass("blockitem" + i);
            total++;
        });
        imagecount = total - 1;
        setInterval(doLoop, delay);
    }

    function doLoop() {
        var max = imagecount;
        if (count == 0) {
            $(".blockitem" + max).fadeOut(300);
        }
        $(".blockitem" + (count - 1)).fadeOut(300);
        $(".blockitem" + count).fadeIn(300);
        if (max == count) {
            count = 0;
        } else {
            count++;
        }
    };
    rotateblocks($("#tickercontent"), 7000);

	//only do when NOT logged in to OW
	if (typeof OneWeb.Admin === "undefined") {
		//accordions
		$('.toggler').click(function () {
			$(this).next().toggle(400);
			return false;
		}).next().hide();
		$("div").removeClass("tabs_content");
		// initialize scrollable
		if ($("#gallerycontainer").length > 0) {
			$("#gallerycontainer").scrollable({
				size: 4,
				items: '#gallerylist',
				next: "#next_fav",
				prev: "#prev_fav"
			});
		}
	}

	//only do when logged in to OW
	if (typeof OneWeb.Admin != "undefined") {
		$("div").removeClass("public");
		//$("h1,h2,h3,h4,h5,h6").css({ "display": "inline-block" });
	}
});

