﻿function mainIndexSetup() {
	// Tabs
	$('#tabs').tabs({ fx: { opacity: 'toggle'} });

	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); },
		function() { $(this).removeClass('ui-state-hover'); }
	);

	// The homepage tabs and friends...
	$('#tabs').tabs({ fx: { opacity: 'toggle'} }).tabs('rotate', 10000); // 106000);
}

$(function() {

    $("ul.dropdown li").hover(function() {

        $(this).addClass("hover");
        $('ul:first', this).css('visibility', 'visible');

    }, function() {

        $(this).removeClass("hover");
        $('ul:first', this).css('visibility', 'hidden');

    });

    $("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");

    function rotateNewsItems() {
    	// Select the next item in the list, or the first item in the list if non items are currently selected
    	// or if there is no selected items for that list.
    	var nextItems = $('ol.rotate li.active + li, ol.rotate:not(:has(li.active + li)) li:first-child');
    	var previousItems = $('ol.rotate li.active');
    	previousItems.removeClass('active');
    	nextItems.addClass('active');

    	// update the items to match
    	var fadeTimeInMillis = 800;
    	var inactiveItems = $('ol.rotate li:not(.active)');
    	var itemCount = inactiveItems.length;
    	var currentCount = 0;
    	inactiveItems.fadeOut(fadeTimeInMillis, function() {
    		currentCount += 1;
    		if (currentCount == inactiveItems.length) {
    			$('ol.rotate li.active').fadeIn(fadeTimeInMillis);
    		}
    	});
    };

    setInterval(rotateNewsItems, 5000);

    $('#newsFeed li, #twitterBar li').css('display', 'block').hide();
    $('#newsFeed ol, #twitterBar ol').addClass('rotate').hover(
            function() { // mouse enter
            	$(this).removeClass('rotate');

            	$('li', this).stop(false, true);

            	$('li.active', this).fadeTo(1, 1);
            },
            function() { // mouse leave
            	$(this).addClass('rotate');
            }
        );

    rotateNewsItems();

});
