var maxp = 2; 										// number of pages minus 1
var p = Math.ceil(Math.random() * (maxp + 1)) - 1; 	// This is a random page...
var x = Math.ceil(Math.random() * 6) + (p*6); 		// This is a random image on that page

function getProfile(ls, youtubeID) {
	$("#profile").fadeOut(150, function () {
		$("#profile").load(ls, function () {
			$("#profile").fadeIn(500, function () {
				if (youtubeID.length > 0) {
					$("#mediabg").show();
					$("#media").fadeTo(150, 0.01, function() {
						swfobject.embedSWF("http://www.youtube.com/v/"+youtubeID+"&amp;hl=en&amp;fs=1&amp;ap=%2526fmt%3D18&amp;enablejsapi=1&amp;playerapiid=vp", "vp", "455", "283", "8", null, null, params, atts);
						window.setTimeout(function() {
							$("#media").fadeTo("fast", 1);
						}, 700);
					});
				} else {
					$("#media").fadeTo("fast", 0, function() {
						$("#mediabg").hide();
					});
				};
			});
		});
	});
}

function checkLimits() {
	$(".btn_dir").fadeIn(150);
	if 		(p == 0) $("#btn_left").fadeOut(150);
	else if (p == maxp) $("#btn_right").fadeOut(150);	
}

function moveThumbs() {
	var pixels = p * 324;
	$("#thumbspane").animate({
		left: "-" + pixels + "px"
	}, 500);
	checkLimits();
}

$(document).ready(function(){
	$("#mediabg").hide();
	$("#media").fadeTo("fast", 0);
	$(".btnthumb").each(function(i) {

		$(this).click(function() {
			getProfile("profiles.cfm #p" + (i + 1), $(this).attr('id'));
			return false;
		});
	});
	
	// Add positioning class to list divs
	$("#listnames div").addClass("positioned");
	
	// code to set up the department links and position their lists correctly
	var curr = $("#l1");
	var lastlink = $("#listdepartments a");
	$("#listdepartments a").each(function(i) {
		$(this).click(function() {
			lastlink.css({'font-weight':'normal', 'color':'#678aa2'});
			$(this).css({'font-weight':'bold', 'color':'#7a003c'});
			lastlink = $(this);
			curr.animate({left: '700px'}, 300); 
			$('#l' + (i + 1)).css({'top' : $(this).offset().top - (493 + $("#copymainintro").height())});
			curr = $('#l' + (i + 1)).animate({left: '338px'}, 300);
			return false;
		});
	});
	
	moveThumbs();
	
	$("#profile").load("profiles.cfm #p" + x);
	
	$("#btn_right").click(function() {
		p++;
		moveThumbs();
	});
	
	$("#btn_left").click(function() {
		p--;
		moveThumbs();
	});
	
	
	
	
	
});

