$(document).ready(function() {
	(function() {
		var fadeSpeed = 200, fadeTo = 0.5, topDistance = 30;
		var topbarME = function() { $('#uberbar').fadeTo(fadeSpeed,1); }, topbarML = function() { $('#uberbar').fadeTo(fadeSpeed,fadeTo); };
		var inside = false;
		//do
		$(window).scroll(function() {
			position = $(window).scrollTop();
			if(position > topDistance && !inside) {
				//add events
				topbarML();
				$('#uberbar').bind('mouseenter',topbarME);
				$('#uberbar').bind('mouseleave',topbarML);
				inside = true;
			}
			else if (position < topDistance){
				topbarME();
				$('#uberbar').unbind('mouseenter',topbarME);
				$('#uberbar').unbind('mouseleave',topbarML);
				inside = false;
			}
		});
	})();
});

$(document).ready(function() {
        $("img.reflect").each(function(){
                $(this).load( 
                        function(){ 
                                $(this).reflect({height: 0.3, opacity: 0.6} );
                        }
                );
        });

	$('#photosets_content').load('photos_content.php?p=1');
	$('ul#portfolio').innerfade({speed: 1000, timeout: 5000, type: 'sequence', containerheight: '220px'});
});

jQuery(function($) {
	$('ul.gallery').galleria({
		history   : false, // activates the history object for bookmarking, back-button etc.
		clickNext : false, // 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
			if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
				image.css('display','none').fadeIn(1000); // fade in the image & caption
				$("#main_image img").css("max-width",(window.innerWidth)-300);
				$("#main_image img").css("max-height",(window.innerHeight)-300);
			}
			caption.css('display','none').fadeIn(1000);
			var _li = thumb.parents('li'); // fetch the thumbnail container
			_li.siblings().children('img.selected').fadeTo(500,0.3); // fade out inactive thumbnail
			thumb.fadeTo('fast',1).addClass('selected'); // fade in active thumbnail
		},
		onThumb : function(thumb) { // thumbnail effects goes here
			var _li = thumb.parents('li'); // fetch the thumbnail container
			var _fadeTo = _li.is('.active') ? '1' : '0.3'; // if thumbnail is active, fade all the way.
			thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500); // fade in the thumbnail when finnished loading
			thumb.hover( // hover effects
				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 firstItem = $('ul.galleria li:first').addClass('active').find('img').addClass('selected');
	$.galleria.activate(firstItem.attr('src'));
});

//$("#main_image img").css("max-width",(window.innerWidth-400));
//$("#main_image img").css("max-height",(window.innerHeight-400));

