$(document).ready(function() {

	// adds js class
	$('body').addClass('js');
	
	$('.slideshow').cycle({ 
    	random:1
	});
	
	// randomly order homepage logos
	$('#ourClients ul').reorder();
	
	$("#toggleClientLogos").click(function(){
		$("#clientLogos").slideToggle();
		$(this).html(($(this).html()=="hide")?"show":"hide");
		return false;
	});
	
	if($("#apollobanner").length==1)
		setInterval("nextApolloImage()",5000);
		
		
	$("li#t8").hover(function(){
		$("#topNav").css({backgroundImage:'url(../../images/nav/nav_bg_right_on.gif)'});
	},function(){
		if(location.href.indexOf("contact")==-1 && location.href.indexOf("location")==-1){	//don't remove highlight when on contact/location page
			$("#topNav").css({backgroundImage:'url(../../images/nav/nav_bg_right.gif)'});
		}
	});
});

function nextApolloImage(){
	$(".apolloVisible").fadeOut(function(){
		if($(this).next().is("img"))
			$(this)
				.removeClass("apolloVisible")
				.addClass("apolloHidden")
				.next()
					.fadeIn()
					.addClass("apolloVisible")
					.removeClass("apolloHidden");
		else
			$(this)
				.removeClass("apolloVisible")
				.addClass("apolloHidden")
				.siblings(":first")
					.fadeIn()
					.addClass("apolloVisible")
					.removeClass("apolloHidden");
		
	});
}

$.fn.reorder = function() {
	
	function randOrd() {
		return(Math.round(Math.random())-0.5);
	}
	
	return($(this).each(function() {
		var $this = $(this);
		var $children = $this.children();
		var childCount = $children.length;
	
		if (childCount > 1) {
			$children.remove();
			var indices = new Array();
			for (i=0;i<childCount;i++) {
				indices[indices.length] = i;
			}
			indices = indices.sort(randOrd);
			$.each(indices,function(j,k) {
				$this.append($children.eq(k));
			});
		}
	}));
}
