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

		var left_indent = item_num * item_width;

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

		//cancel the link behavior
		return false;
	});
	
	// Portfolio viewer: Interaction
	$("#results-viewer .gallery-icon a").click(function() {
		var title = $(this).attr('title');
		_gaq.push(['_trackEvent', 'Portfolio', 'Clicked',title]);
		return false;
	});
	$("#results-viewer .gallery-caption a").click(function() {
		var title = $(this).html();
		title = title.substring(0,title.length - 25);
		alert(title);
		_gaq.push(['_trackEvent', 'Portfolio', 'Clicked',title]);
		return false;
	});
});