$(document).ready(function() {
	document.iratio = fitImg("#content-home");
	});

$(window).resize(function() {
	$("#content div:visible").each(function() { 
		fitImg("#"+this.id);
		});
	});

function swapImg(img,stat) {
	if (document.images)
		{
		((stat == "off") && ($(img).attr("active") != "1")) ? (newsrc = img.src.replace(/_on/g, "_off")) : (newsrc = img.src.replace(/_off/g, "_on"));
		img.src = newsrc;
		}
	}

function fix(img) {
	$("#hnav div img").attr("active", false);
	$(img).attr("active", "1");
	$("#hnav div img").trigger("mouseout");
	}

function fitImg(id) {
	cw = $("#content").width();
	ch = $("#content").height();
	var cratio = cw / ch;
	iw = $(id+" img:first").width();
	ih = $(id+" img:first").height();
	if(!document.iratio) {
		var iratio = iw / ih;
		} else {
			var iratio = document.iratio;
			}
	if(cw > 100 && ch > 100) {
		if(cratio > iratio) {
			cssh = $("#content").height();
			cssw = $("#content").height() * iratio;
			} else {
				cssw = $("#content").width();
				cssh = $("#content").width() / iratio;
				}
		}
	$(id+" img").attr({'width':cssw, 'height':cssh});
	return iratio;
	}

function show(id) {
	$("#lnav div").fadeOut("fast");
	$("#content div").fadeOut("fast");
	$("#lnav-"+id).fadeIn("slow");
	$("#content-"+id).fadeIn("slow");
	document.iratio = $("#content"+id+" img:first").width() / $("#content"+id+" img:first").height();
	fitImg("#content-"+id);
	}

function preloadImages()
	{
	if (document.images)
		{
		for (var i = 0; i < preloadImages.arguments.length; i++)
			{
			(new Image()).src = preloadImages.arguments[i];
			}
		}
	}

function showImprint()
	{
	imprint = window.open("./imprint.htm","imprint","'toolbars=0,location=0,scrollbars=1,statusbars=0,menubars=0,resizable=0,width=500,height=350,left=50,top=50");
	}

function load(pid)
	{
	w = screen.availWidth;
	h = screen.availHeight;
	if (pid != "home") { loc = "gallery.php?id=" + pid; } else { loc = "gallery.php"; }
	gal = window.open(loc, '', 'left=0,top=0,width='+w+',height='+h);
	}
