jQuery(function($) 
{
		
		//$('.gallery_demo_unstyled').addClass('big_photos'); // adds new class name to maintain degradability
		
		$('ul.big_photos').galleria({
			history   : false, // activates the history object for bookmarking, back-button etc.
			clickNext : true, // helper for making the image clickable
			insert    : '#main_image', // the containing selector for our main image
			onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
				
				// 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.3);
				
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
				
				// add a title for the clickable image
				image.attr('title','Next image >>');
			},
			onThumb : function(thumb) { // thumbnail effects goes here
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.5';
				
				// 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.5); } // don't fade out if the parent is active
				)
			}
		});
	});
	
	$(document).ready(function()
	{
		
		$('#ulthumb a').click(function()
		{
			var dw = document.getElementById('ContentContainer');
			if(dw != null && dw != undefined) dw.scrollIntoView(true);
			var select = document.getElementsByTagName("SELECT");
			for(var i = 0; i < select.length; i++)
			{
					select[i].style.visibility = "hidden";
			}
			
			var _a = $(this).is('a') ? $(this) : false;
			var _img = $(this).children('img');
			var _src = _img ? _img.attr('src') : _a.attr('href');
			window.location = window.location.href.replace(/\#.*/,'') + '#' + _src;
			//onThumb
			$('#phg').css({left:"0px"});
			$.galleria.activate(_src);
			return false;
		})
		$("#ulthumb a").append("<em>Enlarge</em>");
		$("#ulthumb a").hover(function() 
		{
			
			
			var offset = $(this).offset();
			var x = offset.left;
			var y = offset.top;
			y1 = y - 100;
			y2 = y - 140;
			$(this).next("em").css('left', (x - 40)+"px");
			//alert(x + ' ' + $(this).next("em").css('left'));
			
			
		$(this).next("em").animate({opacity: "show", top: y1}, "slow");
		}, function() {
		$(this).next("em").animate({opacity: "hide", top: y2}, "fast");
		});

		
		$('#mainpic').click(function()
		{
			var dw = document.getElementById('ContentContainer');
			if(dw != null && dw != undefined) dw.scrollIntoView(true);
			var select = document.getElementsByTagName("SELECT");
			for(var i = 0; i < select.length; i++)
			{
					select[i].style.visibility = "hidden";
			}
			var _a = $(this).is('a') ? $(this) : false;
			var _img = $(this).children('img');
			var _src = _a ? _a.attr('href') : _img.attr('src');
			window.location = window.location.href.replace(/\#.*/,'') + '#' + _src;
			$('#phg').css({left:"0px"});
			$.galleria.activate(_src);
			return false;
		})
		//ContentContainer
		$('#mainpicj').click(function()
		{
			var dw = document.getElementById('ContentContainer');
			if(dw != null && dw != undefined) dw.scrollIntoView(true);
			var select = document.getElementsByTagName("SELECT");
			for(var i = 0; i < select.length; i++)
			{
					select[i].style.visibility = "hidden";
			}
			var _a = $(this).is('a') ? $(this) : false;
			var _img = $(this).children('img');
			var _src = _a.attr('href');// _a ? _a.attr('href') : _img.attr('src');
			window.location = window.location.href.replace(/\#.*/,'') + '#' + _src;
			$('#phg').css({left:"0px"});
			$.galleria.activate(_src);
			return false;
		})
		
		$('#bpicpre').click(function()
		{
			var dw = document.getElementById('ContentContainer');
			if(dw != null && dw != undefined) dw.scrollIntoView(true);
			var select = document.getElementsByTagName("SELECT");
			for(var i = 0; i < select.length; i++)
			{
					select[i].style.visibility = "hidden";
			}
			var _a = $(this).is('a') ? $(this) : false;
			var _img = $(this).children('img');
			var _src = _a.attr('href');// _a ? _a.attr('href') : _img.attr('src');
			window.location = window.location.href.replace(/\#.*/,'') + '#' + _src;
			$('#phg').css({left:"0px"});
			$.galleria.activate(_src);
			return false;
		});
		
		$('#iclose').click(function()
		{
			//var dw = document.getElementById('ContentContainer'); if(dw != null && dw != undefined) dw.scrollIntoView(true);
			var select = document.getElementsByTagName("SELECT");
			for(var i = 0; i < select.length; i++)
			{
					select[i].style.visibility = "visible";
			}
			$('#phg').css({left:"-3000px"});return false;
		});
		$('#aclose').click(function()
		{
			//var dw = document.getElementById('ContentContainer'); if(dw != null && dw != undefined) dw.scrollIntoView(true);
			var select = document.getElementsByTagName("SELECT");
			for(var i = 0; i < select.length; i++)
			{
					select[i].style.visibility = "visible";
			}
		$('#phg').css({left:"-3000px"});return false;
		});
		return false;
		
	})

