jQuery(function($) {
		$('ul.malleria').galleria({
			history   : false, // activates the history object for bookmarking, back-button etc.
			clickNext : false, // helper for making the image clickable
			insert    : '#holder', // the containing selector for our main image
			onImage   : function(image,thumb) { // let's add some image effects for demonstration purposes
				$('#holder img.loading').remove();
				$().imgResize();		

				var _li = thumb.parents('li');
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				thumb.fadeTo('fast',1).addClass('selected');
				

			},
			onThumb : function(thumb) { // thumbnail effects goes here

				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); } // don't fade out if the parent is active
				)
			}
		});
	});
	

	var scaleImg = true;
	jQuery.fn.imgResize = function (image) {
		if (!image) image = $('#holder img');
		var dbsize={};
			dbsize.w=$(window).width();
			dbsize.h=$(window).height();
		var calcwidth=Math.max(dbsize.h* (image.width()/image.height())); 
		var newwidth = dbsize.w>calcwidth?dbsize.w:calcwidth;
		if(!scaleImg)
				image.css({width:newwidth, height:'auto'});
		 else
				image.css({width:calcwidth, height:'auto'}); 
					
		
					 
	 };
	
	jQuery($(document).keypress(function(e) {
		var tag=e.target.tagName.toLowerCase();
		if(tag!='textarea'&&!(tag=='input'&&(e.target.type=='text'||e.target.type=='password'))){ //are the user not writing?
			if(e.keyCode==32||e.keyCode==39||e.keyCode==40){ //Did he press any of the "scrolling-keys"? (down, right, and space key)
				if(e.preventDefault)e.preventDefault();
				else e.returnValue=false;
			}
		}
	}));
	
	$(document).scroll(function(e){ //this doesn't workmust find out how to stop sliding in opera
		if(e.preventDefault)e.preventDefault();
		else e.returnValue=false;
	});
	
	jQuery($(window).resize(function() { 
		$().imgResize(); 
						   
	}));
	
	var showComments = false;
	jQuery($(document).ready(function() {
	  $('div.exif, div.wpcomments, div.wpcontent, div#header, div#footer').hide();
		$('.right').click(function(){ $.galleria.next(); return false; });
		$('.left').click(function(){ $.galleria.prev(); return false; });
		$('.maInfo').toggle(function(){ $('.maInfoOut, div#sidebar').show(); $(this).find('a').addClass('active');},
							function(){$('.maInfoOut, div#sidebar').hide(); $(this).find('a').removeClass('active');});
		$('.maZoom').toggle(function(){ scaleImg = false; $().imgResize(); $(this).find('a').addClass('active'); },
						    function(){ scaleImg = true; $().imgResize();$(this).find('a').removeClass('active'); });
		$('.maPlay').toggle(function(){ slideShow = setInterval(function(){$.galleria.next()}, 3500); 
										$(this).find('a').addClass('active'); },
						    function(){ clearInterval(slideShow); $(this).find('a').removeClass('active'); });
		
		$('#sidebar ul.outflow').hide();
		$('#sidebar h2').click(function(){$('#sidebar ul.outflow').find('ul').slideToggle(20);$(this).next('ul').slideToggle(20); return false;});

		
		if ($('.navLeft').text() == '«') { 
				$('ul.galleria').css({left:45}); 
				$('.navRight').css({left:295});
		}
	}));
