Gallery={
	nav:$('#nav a:not(.btn)'),
	img:$('#cont img'),
	win:$(window),
	size:function(){
		var iw=parseInt(Gallery.img[0].getAttribute('width'));
		var ih=parseInt(Gallery.img[0].getAttribute('height'));
		var ww=Gallery.win.width();
		var wh=Gallery.win.height();

		if(iw<ih)nh=wh,nw=Math.round(iw*(nh/ih));
		else nw=ww+60,nh=Math.round(ih*(nw/iw));

		Gallery.img.css({
			marginLeft:Math.round((ww-nw)/2),
			marginTop:Math.round((wh-nh)/2)-20,
			width:nw,
			height:nh
		});
	},
	key:function(e){
		var key=e.keyCode,next=key>38;
		if(key==27)window.location=Gallery.nav.last().next().attr('href');
		if(key>36&&key<41){
			var el=Gallery.nav.filter('.cur')[next?'next':'prev']('a:not(.btn)');
			if(!el.length)el=Gallery.nav[next?'first':'last']();
			window.location=el.attr('href');
		}
	}
}

Gallery.win.keyup(Gallery.key);
Gallery.win.resize(Gallery.size);
Gallery.size();
try{window.focus()}
catch(e){}
