	$(document).ready(function(){
		
		$('.gallery_demo_unstyled').addClass('gallery_demo items'); // adds new class name to maintain degradability
		
		$('ul.gallery_demo').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
				
			var w = Math.ceil( image.width() / 550);

			var h = Math.ceil(   image.height()/400 );

			if (h < w) {image.css('height', 'auto');
					image.css('width','550px');
			} 
			else { image.css('width','auto');
				image.css('height','400px');
			}

				// fade in the image & caption
				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);
				var path = image.attr('src');
				var paths = path.split('/');
  				var filename = paths[paths.length-1];
				var names = filename.split('.');
				var name = names[0];
				$("#imageInfo").attr("href","imageinfo.php?id=" + name);
				$("#imageInfo").attr("onmouseover","ajax_showTooltip('imageajax.php?id=" + name + "',this);return false");
				$("#imageInfo").attr("onmouseout","ajax_hideTooltip()");
				$("#imagemail").attr("href","mail.php?id=" + name);
				// 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.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
				)
			}
		});

		$("img.thumbflash").addClass("notselect");
		$("img.thumbflash").css("opacity", "0.3");
		$("img.thumbflash.selected").css("opacity", "1");
		$("img.thumbflash.hovered").css("opacity", "1");
		$("img.thumbflash").hover(
			function() {
				$(this).addClass("hovered");
				$("img.thumbflash").css("opacity", "0.3");
				$("img.thumbflash.selected").css("opacity", "1");
				$("img.thumbflash.hovered").fadeTo(100, "1");
				},
			function() {
				$(this).removeClass("hovered");
				$("img.thumbflash.notselect").fadeTo(100, "0.3");
				$("img.thumbflash.selected").css("opacity", "1");
				$("img.thumbflash.hovered").css("opacity", "1");
			}
		);
		$("img.thumbflash").click(
			function() {
				$("img.thumbflash").removeClass("selected");
				$("img.thumbflash").addClass("notselect");
				$(this).removeClass("notselect");
				$(this).addClass("selected");
				$("img.thumbflash.notselect").fadeTo("fast", "0.3");
				$("img.thumbflash.selected").css("opacity", "1");
				var swffile = $(this).attr('alt');
				changeFlash(swffile);
				
			}
		);

		$(".default .jCarouselLite").jCarouselLite({
		    btnNext: ".next",
		    btnPrev: ".prev",
		    mouseWheel: true,
		    visible:5,
		    easing:"bounceout",
		    speed: 1000,
		    circular: false

		});

	});

function changeFlash(url){
var d=document;
(d.all)? d.all("flashMov1").movie = url :
d.embeds["flashMov2"].src = url;
}

