var currentImageID = "image1";

function loadThumbs(year, project) {	
	if (currentYear != year) {
		currentYear = year;
		$('#imageOuterContainer').fadeOut(500, function() {
			$('#imageOuterContainer').empty();
			$('#imageOuterContainer').load("large.php?year=" + year + "&project=" + project, function() {
				$('#imageOuterContainer').fadeIn(500);	
				currentImageID = "image1";
			});
		});	
		$(".thumbNav img").hide();
		$('#thumbContainer').slideUp(function() {
			$('#thumbOuter').css('backgroundImage','url(images/ajax-loader.gif)');	
			$('#thumbOuter').css('backgroundRepeat','no-repeat');
			$('#thumbOuter').css('backgroundPosition', 'center center');
			$('#thumbSlider').empty();			
			$('#thumbSlider').css("width", "auto");
			$('#thumbSlider').css("left", "0px");
			$('#thumbSlider').load("thumbs.php?year=" + year + "&project=" + project, function() {
				$('#thumbSlider').fadeIn(function() {	
					$('#thumbOuter').css('backgroundImage','');
					$('#thumbContainer').slideDown(1000, "easeOutBounce");
					if ($('#thumbSlider').width() <= $('#thumbContainer').width()) {	
						$('#thumbSlider').width($('#thumbContainer').width());
						$(".thumbNav img").hide();
						$(".thumbNav").hide();
						$('#thumbOuter').css("width", "558px");							  
					} else {
						$('#thumbOuter').css("width", "598px");
						$(".thumbNav img").show();
						$(".thumbNav").fadeIn();
					}
				});	
			});		
		});	
	}
	
}

/*function fadeThumb(number, total) {
	totalImages = total;
	currentImage = number;
	if (number <= total) {
		$('#thumbSlider img:nth-child(' + currentImage + ')').fadeIn(100, function() {
			currentImage++;
			fadeThumb(currentImage, totalImages)
		});
	}
}*/


var sliding = false;

function slideImage(imageID, margRightVal) {
	if (sliding == false) {
		if (currentImageID != imageID) {
			sliding = true;
			margRightValStop = $("#" + currentImageID).css("marginRight");
			margRightValStop = margRightValStop.replace("px","")
			margRightValStop = parseInt(margRightValStop);
			margRightValStop = margRightValStop - $("#" + imageID).width();
			if (($.browser.mozilla == true) && (jQuery.browser.version.substr(0,3) == "1.8")) {
				$("#" + imageID).animate({"right": "50%", "marginRight": margRightVal}, 800, "easeOutCirc");
				newRight = $("#" + currentImageID).width();
				$("#" + currentImageID).animate({"right": "100%", "marginRight":  "" + newRight + "px"}, 800, function(){	
					$(this).css({"right": "-" + newRight + "px", "marginRight":  "0px"});
					currentImageID = imageID;
					sliding = false;
				});
			} else {
				$("#" + imageID).animate({"right": "50%", "marginRight": margRightValStop}, 300, "linear", function(){
					$("#" + imageID).animate({"right": "50%", "marginRight": margRightVal}, 800, "easeOutCirc", function(){
							 
					});
					newRight = $("#" + currentImageID).width() + 1;
					$("#" + currentImageID).animate({"right": "100%", "marginRight":  "" + newRight + "px"}, 800, function(){	
						$(this).css({"right": "-" + newRight + "px", "marginRight":  "0px"});
						currentImageID = imageID;
						sliding = false;
					});
				});
			}
		}
	}		
}


$('#thumbSlider img').livequery(function(){ 
$(this).hover(function() { 
	$(this).fadeTo(100, 0.5);
}, function() { 
	$(this).fadeTo(100, 1.0);
}); 
}, function() { 
	$(this).unbind('mouseover').unbind('mouseout'); 
});


$(window).load(function() {
if ($.browser.safari == true) {
	if (jQuery.browser.version < 500) {
		window.location = "browsererror.php";
	}
} else if ($.browser.mozilla == true) {
	if (jQuery.browser.version.substr(0,3) == "1.7") {
		window.location = "browsererror.php";
	}	
}							   
						

var moving = false;
					
$("#move_right").mousehold(function(){		
	var left = $("#thumbSlider").css("left");	
	var width = $('#thumbSlider').width();
	var containerWidth = $("#thumbContainer").width();
			
	left = left.replace("px","")
	left = parseInt(left)
	
	var maxLeft = width - containerWidth;
		
	maxLeft = maxLeft - (maxLeft*2);
		
	var nextLeft = left - 450;

	if (nextLeft < maxLeft) {			
		nextLeft = maxLeft;
	}
	
	if (moving == false) {			
		if (width > containerWidth) {				
			moving = true;
			$("#thumbSlider").animate({"left": nextLeft}, 500,function(){
				 moving = false;			 
			});
		}	
	}
});	

$("#move_left").mousehold(function(){
	var left = $("#thumbSlider").css("left");	
	left = left.replace("px","")	
	left = parseInt(left)
		
	maxLeft = 0;
	
	var nextLeft = left + 450;
	
	if (nextLeft > maxLeft) {		
		nextLeft = maxLeft;	
	}
	
	if ((left < 0) && (moving == false)) {
		moving = true;
		$("#thumbSlider").animate({"left": nextLeft}, 500,function(){
			 moving = false;
		});
	}	

});	

$(".menu img").each(function (i) {
	$(this).removeAttr("title");
	$(this).removeAttr("alt");
});

$("a.menuLink").livequery('click', function(event) { 
	$("a.menuLinkClicked").each(function (i) {
		$(this).removeClass('menuLinkClicked').addClass('menuLink');
	});							
	$(this).removeClass('menuLink').addClass('menuLinkClicked');
});



	
}); 