﻿$(document).ready(function () {
    // Wire-up navigation behaviour
    $('div.Navigation.Dropdown ul:first').ptMenu();
    $('div.Navigation.Accordian ul:first').ptMenu({ vertical: true });

    // Highlight current branch for navigation controls
    $('.Navigation li.current').parentsUntil('.Navigation').addClass('follow');
	
	$('#TopNavigationContainer ul.levelone>li:eq(0)').css('text-align', 'left');
	$('#TopNavigationContainer ul.levelone>li:eq(0)').css('width', '10%');
	$('#TopNavigationContainer ul.levelone>li:last').css('text-align', 'right');
	$('#TopNavigationContainer ul.levelone>li:last').css('width', '10%');
	

    $(function () {
        $('#slideshow IMG').css({ opacity: 0.0 });
        $('#slideshow IMG:first').css({ opacity: 1.0 });
        setInterval("slideSwitch()", 3000);
    });
	
	// Sort out category margins
    var categoryCount = 0;
    $('div.category').each(function () {
        categoryCount++;
        if (categoryCount % 3 == 0) {
            $(this).attr('style', 'margin-right: 0px;');
			$(this).after('<br style="clear:both;"/>');
        }
        else {
            $(this).attr('style', 'margin-right: 12px;');
        }
    });
	
	// Sort out person margins
    var personCount = 0;
    $('div.person').each(function () {
        personCount++;
        if (personCount % 3 == 0) {
            $(this).attr('style', 'margin-right: 0px;');
			$(this).after('<br style="clear:both;"/>');
        }
        else {
            $(this).attr('style', 'margin-right: 12px;');
        }
    });
});

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:first');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}


