$(document).ready(function() {

	  /* Apply fancybox to multiple items */

		$("a.grouped_images").fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	false
		});
		
		
		$('div.sliderGallery li img').click( function () {
			$('div#pMainPic a img').attr('src', $(this).attr('src').replace('thumbs/', '') );
			$('div#pMainPic a.grouped_images').not('.hidden').attr('href', $(this).attr('src').replace('thumbs/', '') );
			// TODO große versteckte bilder neu sortieren, zuerst die nach click und dann davor
		});

		var url = window.location.pathname;
		var filename = url.substring(url.lastIndexOf('/')+1);
		//filename = filename.substring(0, filename.lastIndexOf('.')).replace('-', ' ');
		$('a[href|="'+filename+'"]').addClass('active');
		
		var cat = $('li.activeCategory a').html();
		$('ul#menu li a').each(function(){
			if($(this).html() == cat) {
				$(this).addClass('active');
			}
		});

});

window.onload = function () {
            var container = $('div.sliderGallery');
            var ul = $('ul', container);
            
            var itemsWidth = ul.innerWidth() - container.outerWidth();
            
            container.css('overflow', 'hidden');  // move auto to noscript style to avoid flicker
            
            $('.slider', container).slider({
                min: 0,
                max: itemsWidth,
                handle: '.ui-slider-handle',
                stop: function (event, ui) {
                    ul.animate({'left' : ui.value * -1}, 337);
                },
                slide: function (event, ui) {
                    ul.css('left', ui.value * -1);
                }
            });
	       $(".btn-left").click(function(){
		       var elValue = $('.slider', container).slider('option', 'value');
		       // alert (elValue);
			       if(elValue > 0) {
			          elValue = elValue - 100;
			          if(elValue < 0) {
		             elValue = 0;
		          }
			     $(".sliderGallery .slider").slider('value', elValue);
		          $(".sliderGallery ul").animate({'left' : elValue * -1}, 337);
			       }
			});
			$(".btn-right").click(function(){
			  var elValue = $('.slider', container).slider('option', 'value');
		       // alert (elValue);
			       if(elValue < itemsWidth) {
			          elValue = elValue + 100; 
			          if(elValue > itemsWidth) {
		             elValue = itemsWidth;
		          }
		          $(".sliderGallery .slider").slider('value', elValue); 
		          $(".sliderGallery ul").animate({'left' : elValue * -1}, 337);
			       }
			
			});
			$("span.end").click(function(){
			  var elValue = $('.slider', container).slider('option', 'value');
		       // alert (elValue);
		             elValue = itemsWidth;
		          $(".sliderGallery .slider").slider('value', elValue); 
		          $(".sliderGallery ul").animate({'left' : elValue * -1}, 337);
			});
			$("span.start").click(function(){
			  var elValue = $('.slider', container).slider('option', 'value');
		       // alert (elValue);
		             elValue = 0;
		          $(".sliderGallery .slider").slider('value', elValue); 
		          $(".sliderGallery ul").animate({'left' : elValue * -1}, 337);
			});
        };

