$(document).ready(function() {
						   
	 var viewportwidth;
	 var viewportheight;
	 
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 
	 if (typeof window.innerWidth != 'undefined')
	 {
		  viewportwidth = window.innerWidth,
		  viewportheight = window.innerHeight
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	 else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
		   viewportwidth = document.documentElement.clientWidth,
		   viewportheight = document.documentElement.clientHeight
	 }
	 
	 // older versions of IE
	 
	 else
	 {
		   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		   viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }	
		
	//$('ul.gallery').addClass('gallery'); // adds new class name to maintain degradability
	
	$('ul.gallery').galleria({
		history   : 0, // activates the history object for bookmarking, back-button etc.
		clickNext : true, // helper for making the image clickable
		onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes				   
			
			var foot_height = $('.galleria').height() + 90;
			
			var win_height = (viewportheight - foot_height);
			$('.galleria_container').css('height',(win_height + 10));
			
			var max_height = win_height;
			var cur_height = image.height();
			
			if(cur_height > max_height){
				image.attr('height',max_height);
			} 
			
			if (cur_height < max_height) {
				var marginTop = ((max_height - cur_height)/2);
				image.css('marginTop',marginTop);
			}
			if(! ($.browser.safari)){
				// fade in the image & caption
				if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
					image.css('display','none').fadeIn(1000);
				}
				caption.css('display','none').fadeIn(1000);
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// fade out inactive thumbnail
				_li.siblings().children('img.selected').fadeTo(500,0.5);
				
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
			} else {image.css('display','none').fadeIn(1000);}
			// add a title for the clickable image
			image.attr('title','Next image >>');
		},
		onThumb : function(thumb) { // thumbnail effects goes here
			if(! ($.browser.safari)){
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.3';
				
				// fade in the thumbnail when finnished loading
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				
				// hover effects
				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
				)
			}
		}
	});
$('.gallery').removeClass('gallery');
$('#loader').remove();
$('#magicbox').slideDown('medium');
});