
var itemsPerPage = 5;
var curPos = 0;
var basedir = "";
var uriYear;
var moveBy = 128;
var total_images;
var ajax_timeline = true;

//NOTEPAD: http://www.youtube.com/watch?v=imzkzTH0kao

$(document).ready(function(){
	//$('.tooltip').hide();
	doMouseHovers();
	doSliderButtons();
	doSliderClicks();
});

function toggleAjaxTimeline()
{
	ajax_timeline = !ajax_timeline;
	
	if (!ajax_timeline) alert("Ajax is now disabled on the timeline.");
	else alert("Ajax is now enabled on the timeline.");
}

var hoverMouseOut;

function doSliderButtons()
{
	var total = total_images;
	if (total > itemsPerPage && curPos < total-itemsPerPage) var nextButton = true;
	if (curPos > 0) var prevButton = true;
	
	if (prevButton) {
		$(".leftslider").removeClass('leftslideroff');
		$(".leftslider").unbind();
		$(".leftslider").click(function(){
			$("#widget").animate({"marginLeft": "+="+moveBy+"px"}, "fast");
			curPos--;
			showHideTilesPrev();
			doSliderButtons();
			doMouseHovers();
			return false;
		});
	} else {
		$(".leftslider").addClass('leftslideroff');
		$(".leftslider").unbind();
		$(".leftslider").click(function(){
			return false;
		});
	}
	
	if (nextButton) {
		$(".rightslider").removeClass('rightslideroff');
		$(".rightslider").unbind();
		$(".rightslider").click(function(){
			$("#widget").animate({"marginLeft": "-="+moveBy+"px"}, "fast");
			curPos++;
			showHideTilesNext();
			doSliderButtons();
			doMouseHovers();
			return false;
		});
	} else {
		$(".rightslider").addClass('rightslideroff');
		$(".rightslider").unbind();
		$(".rightslider").click(function(){
			return false;
		});
	}
	
}

function doSliderClicks()
{
	

		$(".timelinelink a").click(function(){
			
			var uri = $(this).attr('href');
			
			if (ajax_timeline)
			{
				
				$.get(uri,function(result){
					$('#content').removeClass('background').html(result);
					$('#content').get(0).focus();
					$('#content').attr("tabindex","-1");
				});
				return false;
			
			} else {
				window.open(uri);
				
				return false;
			}
			
		});
	

}

function showHideTilesNext()
{
		var max = curPos + itemsPerPage;
		$(".timelinelink:gt("+(max-1)+")").hide();
		$(".timelinelink:eq("+(max)+")").fadeIn();
}

function showHideTilesPrev()
{
	//nothing?
}

function doMouseHovers()
{
	$(".timelinelink").unbind();
	$(".timelinelink:lt("+(curPos+6)+")").mouseover(function(e){
		clearTimeout(hoverMouseOut);
		$('.tooltip').not(this).hide();
		var tooltip = $(this).find('.tooltip');
		$(tooltip).show();
		
		$(this).find('img').each(function(){
			var img = $(this);
			var nw = $(this).width() + 20;
			var nh = $(this).height() + 20;
			$(img).css('width',nw+'px').css('height',nh+'px').css('margin','-10px 0 0 -10px').css('position','absolute');
		});
	}).mouseout(function(){
		
		var tooltip = $(this).find('.tooltip');
		$(this).find('img').each(function(){
			var img = $(this);
			var nw = $(this).width() - 20;
			var nh = $(this).height() - 20;
			$(img).css('width',nw+'px').css('height',nh+'px').css('margin','0 0 0 0').css('position','static');
		});
		
		hoverMouseOut = setTimeout(function(){$(tooltip).hide();},100);
	});	
}


function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
win=window.open(mypage,myname,settings);}