jQuery(document).ready(function($) {
    // $() will work as an alias for jQuery() inside of this function

	// rollover image
	$("img.rollover").hover(
		function(){
			if($(this).attr("src").indexOf("_activ") == -1) {
				var newSrc = $(this).attr("src").replace(".jpg","_activ.jpg");
				$(this).attr("src",newSrc);
			}
		},
		function(){
			if($(this).attr("src").indexOf("_activ") != -1) {
				var oldSrc = $(this).attr("src").replace("_activ","");
				$(this).attr("src",oldSrc);
			}
		}
	);
	
	// active image
	$("img.active").each(
		function(){
			var newSrc = $(this).attr("src").replace(".jpg","_activ.jpg");
			$(this).attr("src",newSrc);
		}
	);

	// add first/last class to list
	$("li:first-child").addClass("first");
	$("li:last-child").addClass("last");
	
	// fancybox
	if (jQuery.fancybox) {
		$("a.fancybox").fancybox({
			'titlePosition' : 'over',
			'overlayShow'	: false,
			'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + '/' + currentArray.length + ' : '+title+'</span>';
			} 
		});

		// nextgen gallery widget
		$('#sidebar .ngg-widget a').fancybox({
			'titlePosition' : 'over',
			'overlayShow'	: false
		});
	}
	
	// scroll to anchor
	$("div#jump form select").change(
		function(event) {
			//$('#parutions-presse').scrollTo( $("a[name='"+$(this).val()+"']"), 1000);
			$("div#jump").next("div").scrollTo( $("a[name='"+$(this).val()+"']"), 1000);
			//$(location).attr('hash', '#'+$(this).val());
			//return false;
		}
	);
});

function showImage(imageTitle, imageURL)
{
	jQuery.noConflict().fancybox({
		'titlePosition' : 'over',
		'overlayShow'	: true,
		'href' : imageURL,
		'title' : imageTitle
	});
	//$('a#img'+imageID).trigger('click');
}
