$(document).ready( function () {
	$("div#centerer").css({
		left: $(document).width()/2-$("div#centerer").width()/2
	});
	$(window).resize( function () {
		$("div#centerer").css({
                	left: $(document).width()/2-$("div#centerer").width()/2
	        });
	});

	$("ul.gallery").galleria({
		history: true,
		insert : "#main_image",
		clickNext: false,

		onThumb : function ( thumb ) {
			var _li = thumb.parents( 'li' );
			var _fadeTo = _li.is( '.active' ) ? '1' : '0.3';
			thumb.css({display: 'none', opacity: _fadeTo}).fadeIn(500);
			thumb.hover(
				function() { thumb.fadeTo('fast',1); },
				function() { _li.not('.active').children('img').fadeTo('fast',0.3); }
			)
		},
		onImage   : function(image,caption,thumb) {
			image.css({ display: 'none'})
				.fadeIn(1000)
				.click( function() {
					var _src = $(this).attr( "src" );
					_src = _src.replace( /^[.\/]+/, "" );
					var _big = $("ul.gallery img[src$='"+_src+"']").attr( "big" );
					var _link = $("ul.gallery img[src$='"+_src+"']").attr( "link" );
					
					if ( typeof( _big ) != "undefined" )
					{
						$.slimbox( _big );
					}else if ( typeof( _link ) != "undefined" )
					{
						window.location = _link;
					}
				});
			caption.css('display','none').fadeIn(1000);
			var _li = thumb.parents('li');
			_li.siblings().children('img.selected').fadeTo(500,0.3);
			thumb.fadeTo('fast',1).addClass('selected');
		}
	});

	$("a#leftArrow").click( function( event ) {
		$.galleria.prev();
		return false;
	} );

	$("a#rightArrow").click( function( event ) {
		$.galleria.next();
		return false;
	} );

	if ( typeof( firstThumb ) != "undefined" )
	{	
		$.galleria.activate( firstThumb );
	}


	$("div.insideContent").jScrollPane({
		scrollbarWidth: 16,
		showArrows: true,
		scrollbarMargin: -10,
		wheelSpeed: 25
	});

	$("div.ekipa ul").jScrollPane({
		scrollbarWidth: 16,
		showArrows: true,
		wheelSpeed: 25
	});

	$("div#galleryList").jScrollPane({
                scrollbarWidth: 16,
                showArrows: true,
                scrollbarMargin: -10,
                wheelSpeed: 25
        });

	if ( !$.browser.msie )
	{
		$("#blog ol").jScrollPane({
			scrollbarWidth: 16,
			showArrows: true,
			scrollbarMargin: -10,
			wheelSpeed: 25
		});
	}

	$("#staticPage ol").jScrollPane({
		scrollbarWidth: 16,
		showArrows: true,
		scrollbarMargin: 0,
		wheelSpeed: 25
	});

	$("#staticPage div#textContent").jScrollPane({
		scrollbarWidth: 16,
		showArrows: true,
		scrollbarMargin: 0,
		wheelSpeed: 25
	});
});
