jQuery(document).ready(function() {
	// Portfolio slider script
	var thumbs = jQuery("#results-thumbs img"); // thumbnail images
	var fulls  = jQuery("#results-viewer dl"); // full images and captions
	var item_width = 395;
	var left_value = item_width * (-1);
	thumbs.each(function(index) {
		jQuery(this).parent().attr("href","#full-id-"+index);
		//attr("class","full-id-"+index);
	});
	fulls.each(function(index) {
		jQuery(this).attr("id","full-id-"+index);
	});
	
	// 3x3 Thumbnails: Interaction
	jQuery("#results-thumbs .gallery a:first img").addClass("gallery-selected");
	jQuery("#results-thumbs .gallery a").click(function() {
		
		jQuery("#results-thumbs .gallery a img").removeClass("gallery-selected");
		jQuery(this).children().addClass("gallery-selected");
		var item_num = parseInt(jQuery(this).attr("href").substring(9)); // takes off #full-id-, converts to int

		var left_indent = item_num * item_width;

		jQuery("#results-viewer .gallery:not(:animated)").animate({"left" : -left_indent}, 400, function () {
			jQuery("#results-viewer .gallery").css({"left" : -left_indent});
		});

		//cancel the link behavior
		return false;
	});
	
	// Portfolio viewer: Interaction
	jQuery("#results-viewer .gallery-icon a").click(function() {
		var title = jQuery(this).attr('title');
		_gaq.push(['_trackEvent', 'Portfolio', 'Clicked',title]);
		return true;
	});
	jQuery("#results-viewer .gallery-caption a").click(function() {
		var title = jQuery(this).html();
		title = title.substring(0,title.length - 25);
		// alert(title);
		_gaq.push(['_trackEvent', 'Portfolio', 'Clicked',title]);
		return true;
	});
	
	jQuery("#results-thumbs .gallery-icon a").click(function() {
		var title = jQuery(this).attr('title');
		_gaq.push(['_trackEvent', 'Portfolio', 'Thumbnail',title]);
		return true;
	});
	
	// Trivia question: Click
	jQuery("a.trivia-answer-link").click(function() {
		_gaq.push(['_trackEvent', 'Trivia', 'Looked at answer']);
		return true;
	});
});

jQuery(document).ready(function() {	
	// Trivia script
	jQuery(".trivia-answer").hide();
	jQuery("a.trivia-answer-link").click(function() {
		jQuery(".trivia-answer").fadeIn();
		return false; // disable link
	});
	jQuery("a.trivia-answer-close").click(function() {
		jQuery(".trivia-answer").fadeOut();
		return false; // disable link
	});
	
	jQuery(".page-id-39 .gallery img").hide();
	jQuery(".page-id-39 .gallery a").mouseenter(function() {
		var name = jQuery(this).html();
		var name = name.substring(0,4); // To avoid problems with Carol's name
		var curr_image = jQuery(".page-id-39 .gallery img[title^="+name+"]");
		// alert(curr_image.attr("title"));
		curr_image.show();
	});
	jQuery(".page-id-39 .gallery a").mouseleave(function() {
		jQuery(".page-id-39 .gallery img").hide();
	});
});
