window.onload = function () {
    var container = $('div.sliderGallery');
    var ol = $('ol', container);
    var itemsWidth = ol.innerWidth() - container.outerWidth();
    $('.slider', container).slider({
        min: 0,
        max: itemsWidth,
        handle: '.handle',
        stop: function (event, ui) {
            ol.animate({'left' : ui.value * -1}, 500);
        },
        slide: function (event, ui) {
            ol.css('left', ui.value * -1);
        }
    });	
};
$().ready(function() {
	$("#tooltip").hide();
	$(".sliderGallery li a").prepend('<div class="overlay"></div>');
	$(".overlay").livequery(function() {
		$(this).html('<img src="http://builtbybarrette.com/assets/images/overlay.gif" />');
	});
	var xOffset = 0;
	var yOffset = 0;
	var elHeight = 0;
	$(".overlay").livequery("click", function(e) {
		$("#tooltip").hide();
		var ttContent = "";
		var imageSource = "";
		var year = "";
		var description = "";
		var textOnly = "false";
		ttContent = '<div class="top"></div><div class="bg clearfix">';
		if ($(this).parent().parent().hasClass("empty")) {
			textOnly = "true";
		}
		year = $(this).next().next().next().html();
		description = $(this).next().next().next().next().html();
		if (textOnly == "false") {
			imageSource = $(this).next().find('.trigger').next().attr('src');
			ttContent = ttContent + '<div class="photo"><img src="' + imageSource + '" alt="' + year + '" /></div>';
			ttContent = ttContent + '<div class="photoDescription">';
		} else {
			ttContent = ttContent + '<div class="photoDescription noImage">';
		}
		ttContent = ttContent + '<h3>' + year + '</h3>';
		ttContent = ttContent + '<p>' + description + '</p>';
		ttContent = ttContent + '</div><div class="bot"></div>';
		$("#tooltip").html(ttContent).css({'top':(e.pageY - 250) + "px",'left':(e.pageX - 250) + "px"}).fadeIn('fast');
		$(".overlay").mousemove(function(e){
			$("#tooltip").css({
					'top':(e.pageY - 250) + "px",
					'left':(e.pageX - 250) + "px"
			});
		});	
		$(".overlay").mouseout(function(e){
			$("#tooltip").fadeOut('fast');
    	});	
   	});
});