$(document).ready(function() {
	
	// get all images in the header fade div
	function getAllSlideImages(wrapper,tag){
		var slide_elements = document.getElementById(wrapper).getElementsByTagName(tag);
		var slide_src = new Array();
		for (var i = 0; i < slide_elements.length; i++) {
			slide_src[i] = slide_elements[i].src;
		}
		return slide_src;
	}
	
	// header image fader : preload and fade in
	$(function( $ ){
		$('.slide').css('opacity', 0.0);
		var urls = getAllSlideImages('header-images','img');
		$.preload( urls, {
			base:'',
			ext:'',
			onFinish:function(){
				startSlideShow();
				$('.slide').fadeTo('slow', 3.0);
			}
		});
	});
	
	// slideshow with callback
	function startSlideShow(){
		$('#header-images').slideShow({
			interval: 4,
			slideClick: function(slideShow) {
				if (slideShow.mouse.x > slideShow.options.slideSize.width / 2) {
					slideShow.next();
				} else {
					slideShow.previous();
				}
			},
			gotoSlide: function(slideShow, index) {
				$('.callBackSlideShowLog').html('goto slide index: ' + index);
			}
		});
	}

	// Image fader on several Sites
	$('.callbackSlideShow').slideShow({
		interval: 3,
		slideClick: function(slideShow) {
			if (slideShow.mouse.x > slideShow.options.slideSize.width / 2) {
				slideShow.next();
			} else {
				slideShow.previous();
			}
		},
		gotoSlide: function(slideShow, index) {
			$('.callBackSlideShowLog').html('goto slide index: ' + index);
		}
	});
	
	// jQuery gallery
	if(document.getElementById('nggallery')){
		$(".ngg-galleryoverview a").overlay({
			target: '#gallery',
			expose: {
					color: '#133E65',
					opacity: 0.3
					},
            closeOnClick: true
		}).gallery({
			opacity: 1.0,
			disabledClass: 'inactive'
		});
	}

	// jQuery gallery
	if(document.getElementById('wp-gallery')){
		$(".scrollable").scrollable({size: 5}).find("a").tooltip({
			tip: '#tooltip'
		}).overlay({
			target: '#gallery',
			expose: {
					color: '#133E65',
					opacity: 0.3
					},
            closeOnClick: true
		}).gallery({
			opacity:1.0,
			disabledClass: 'inactive'
		});
	}


	// jQuery single images on page enclosed in link tags with class "single_image"
	if(document.getElementById('content')){
		$("#content a.single_image").overlay({
			target: '#gallery',
			expose: {
					color: '#133E65',
					opacity: 0.3
					},
			closeOnClick: true
		}).gallery({
			opacity:1.0,
			disabledClass: 'inactive'
		})
	}
});

