$(document).ready(function() {
	var lastID = 0;
	
	if ($("#content").width() < 850) alert('Your display size may cause problems with this site.');
	
	if (window.opera && ($("#imagerow").length > 0)) { var adj = window.setInterval("adjust()", 1000); }
	
	$("#imagerow div.menu, #imagerow div.menu *").css("width",$("#imagerow").width()/5);

	$("#imagerow .menu, #navrow .menu").hover(
		function() {
			$(this).find(".menurefs").fadeIn("fast");
			},
			function() {
				$(this).find(".menurefs").fadeOut("fast");
				}
		);
	$("#imagerow .menu .menurefs .menuitem img, #navrow .menu .menurefs .menuitem img").click(
		function() {
			$(".menu .menurefs").fadeOut("fast");
			});
	});

$(window).resize(function() {
	$("#imagerow div.menu, #imagerow div.menu *").css("width",$("#imagerow").width()/5);
	});

function thumbConf() {
	ww=eval($("#thumbwin").width()); // thumb div width
	tw=eval($("#thumbs").width()); // width of all thumbs
	if ((tw-ww) < 0) {
		$("#thumbwin").css({left:'0px', right:'0px'});
		$("#thumbnav-left, #thumbnav-right").css("display","none");
		}
	}

function thumbnav(d) {
	r=eval($("#thumbwin").width()); // thumb div width
	l=eval($("#thumbs").css("left").match(/.*\d+/)); // left position
	w=eval($("#thumbs").width()); // width of all thumbs
	p=eval(w+l); // left hangover
	if (w>r) {
		if ((d=='left') && (l<0)) {
			$("#thumbs").animate({left: '+='+r}, 1000, function() {
					newl=$("#thumbs").css("left").match(/.*\d+/);
					$("#thumbnav-right").css({ "background-position":"-40px", "cursor":"pointer" });
					if (newl>=0) {
						$("#thumbnav-left").css({ "background-position":"0px", "cursor":"default" });
						}
				});
			}
			else if ((d=='right') && (p>r)) {
				$("#thumbs").animate({left: '-='+r}, 1000, function() {
					newp=eval(w+$("#thumbs").css("left").match(/.*\d+/));
					$("#thumbnav-left").css({ "background-position":"-20px", "cursor":"pointer" });
					if (newp<=r) {
						$("#thumbnav-right").css({ "background-position":"-60px", "cursor":"default" });
						}
					});
				}
		}
	}
			
function home() {
	self.location.href = "./";
	}
			
function nav(cat,oID) {
	self.location.href = "./project.php?nav=" + cat + "&id=" + oID;
	}
			
function adjust() {
	$("#imagerow div.menu, #imagerow div.menu *").css("width",$("#imagerow").width()/5);
	}

function menu(menID) {
	$("#" + menID).toggle();
	if (menID !== document.lastID) {
		document.lastID = menID;
		$(".menu .menuitem").css("height","25px");
		$(".menutitle").removeClass('blue');
		}
	}

function hideMenues() {
	$("#imagerow menurefs").css("display","none");
	}

function showPic(pID) {
	$(".menu .menuitem").animate({height:'25px'},'slow');
	$("#" + pID).animate({height:'100%'},'slow');
	$(".menutitle").removeClass('blue');
	$("#" + pID + " .menutitle").addClass('blue');
	}

function showImprint() {
	$("#imprint").modal({opacity : 75});
	}

function loadImg(pid,image,ratio,desc,e) {
	$("#thumbs img").addClass("inactive");
	$(e).removeClass("inactive");
	$('#imgarea').fadeOut("slow", function() {
		this.ratio = $('#imgarea').width()/$('#imgarea').height();
		//$('#imgarea img').attr('src','img/projects/'+pid+'/images/'+image);
		$('#imgarea').html('<img src=\"img/projects/'+pid+'/images/'+image+'\" />');
		if(this.ratio<ratio) {
			$('#imgarea img').attr({width:$('#imgarea').width(),height:$('#imgarea').width()/ratio});
			}
			else {
				$('#imgarea img').attr({height:$('#imgarea').height(),width:$('#imgarea').height()*ratio});
				}
		});
	$('#imgarea').fadeIn("slow", function() {$('#imagedesc').html(desc);});
	}

function resizeImg() {
	$('#imgarea img').hide();
	oratio = $('#imgarea').width()/$('#imgarea').height();
	iratio = $('#imgarea img:first').attr('width')/$('#imgarea img:first').attr('height');
	if(oratio<iratio) {
		$('#imgarea img').attr({width:$('#imgarea').width(),height:$('#imgarea').width()/iratio});
		}
		else {
			$('#imgarea img').attr({height:$('#imgarea').height(),width:$('#imgarea').height()*iratio});
			}
	$('#imgarea img').show();
	}

