$(document).ready(function(){
	$("#nav ul:first > li:odd").addClass("blue");
	$("#nav ul:first > li:even").addClass("green");

	//initialize slideshow if any
	if ($('#slideshow').length != 0) {
		var $length = $("#slideshow img").length;
		var $random = Math.floor(Math.random()*$length) + 1;
		$("#slideshow img:nth-child(" + $random + ")").addClass("active");
		setInterval( function() { slideSwitch("slideshow"); }, 4000 );
	}
		
	if ($('#partners-slideshow').length != 0) {
		$("#partners-slideshow a").css({opacity: 0.0, display: "block"});

		var $length = $("#partners-slideshow a").length;
		var $random = Math.floor(Math.random()*$length) + 1;
		$("#partners-slideshow a:nth-child(" + $random + ")").addClass("active");
	
		$("#partners-slideshow a:nth-child(" + $random + ")").css({opacity: 1.0});
		
		setInterval( function() { partnerSwitch("partners-slideshow"); }, 6000 );

	}
	
});

function highlightMenu(liParentId, liId) {
	if (liParentId != "") { $("#" + liParentId).addClass("selected"); };
	if (liId != "") { $("#" + liId).addClass("selected"); };
}	

function slideSwitch(id) {
    var $active = $('#' + id + ' img.active');

    if ( $active.length == 0 ) $active = $('#' + id + ' img:last');

    var $next =  $active.next().length ? $active.next()
        : $('#' + id + ' img:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function partnerSwitch(id) {
    var $active = $('#' + id + ' a.active');

    if ( $active.length == 0 ) $active = $('#' + id + 'a:last');

    var $next =  $active.next().length ? $active.next()
        : $('#' + id + ' a:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}


