$(document).ready(function() {

	$("#navhide").hide();

	$("#nav1").mousemove( function() {
		$("#nav1").hide();
		$("#navhide").show();
	} );

	$("#navhide").mousemove( function() {
		$("#nav1").hide();
		$("#navhide").show();
	} );

	$("#navhide").mouseout( function() {
		$("#navhide").hide();
		$("#nav1").show();
	} );

	$('ul.imglist').galleria({
			history   : true,
			clickNext : true,
			insert    : '#main_image',
			onImage   : function(image,caption,thumb) {
				image.css('display','none').fadeIn(1000);
				caption.css('display','none').fadeIn(1000);
				var _li = thumb.parents('li');
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				thumb.fadeTo('fast',1).addClass('selected');
				image.attr('title','Next image >>');
			},
			onThumb : function(thumb) {
				var _li = thumb.parents('li');
				var _fadeTo = _li.is('.active') ? '1' : '0.3';
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				thumb.hover(
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.3); }
				)
			}
	});

});


function DrawImage(ImgD,FitWidth,FitHeight) {
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0) {
		if(image.width/image.height>= FitWidth/FitHeight) {
			if(image.width>FitWidth) {
				ImgD.width=FitWidth;
				ImgD.height=(image.height*FitWidth)/image.width;
			}
			else {
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}
		else {
			if(image.height>FitHeight) {
				ImgD.height=FitHeight;
				ImgD.width=(image.width*FitHeight)/image.height;
			}
			else {
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}
	}
}