jQuery.noConflict();

jQuery(document).ready(
	function($)
	{
		/**
		 * Externe Links im neuen Fenster öffnen
		 */
		$('a[href^="http"]').click(function()
		{
			var nw = window.open(this.href, '_blank');
			if (nw)
			{
				if (nw.focus)
				{
					nw.focus();
				}
			}
			nw = null;
			return false;
		});
		
		if ($('#thumbnails').length > 0)
		{
			$('#thumbnails').scrollable( { size : Math.floor($(window).width() / 330) }).navigator().mousewheel();
			
			$(document).keyup(function(e)
			{
				if (e.keyCode == 27)
				{
					$('#gross').fadeOut(10);
					$('#grossBild,#grossInfo').empty();
				}
			});
		}
		
		if ($('#thumbnails').length > 0 || $('#ausstellungen').length > 0 || $('#veroeffentlichungen').length > 0)
		{
			window.numThumbs = 0;
			
			$('#thumbnails a,#ausstellungen a').not('.editor a').each(function()
			{
				$(this).attr( { id : 't' + window.numThumbs });
				window.numThumbs++;
			});
			
			$('.naviHolder,.prevPage,.nextPage').each(function()
			{
				$(this).css( { marginTop : $(window).height() - $(this).offset().top - 36 });
			});
			
			$('#thumbnails a,#ausstellungen a,#veroeffentlichungen a').not('.editor a').not('.admin a').click(
				function()
				{
					$this = $(this);
					
					$('body').append('<div id="startbild"></div>');
					$('body').append('<div id="gross"></div>');
					
					$('#gross').css( {
						height : $(window).height(),
						marginTop : $(window).scrollTop() }).hide().append('<div id="grossBild"> </div>').append(
						'<div id="grossNavi"></div>');
					
					$('#grossNavi').append('<a href="#" id="grossSchliessen">Schließen</a> ');
					$('#grossNavi').append('<a href="#" id="grossZurueck">&#x25c0;</a> ');
					$('#grossNavi').append('<a href="#" id="grossWeiter">&#x25b6;</a>');
					$('#grossNavi').append('<div id="grossInfo"></div>');
					
					if ($this.attr('id') == 't' + (window.numThumbs - 1) || $this.parent().next().length == 0)
					{
						$('#grossWeiter').css( { visibility : 'hidden' });
					}
					if ($this.attr('id') == 't0' || $this.parent().prev().length == 0)
					{
						$('#grossZurueck').css( { visibility : 'hidden' });
					}
					
					$('#grossSchliessen,#grossBild a').live('click', function()
					{
						$('#gross').fadeOut(10, function()
						{
							$('#gross,#startbild').remove();
						});
						return false;
					});
					
					$('#gross').fadeIn(10);
					
					$('#grossBild').append('<a href="#"><img src="" /></a>');
					$('#grossBild img').fadeTo(1, 0).attr( { height : h });
					
					var h = $('#grossBild').height();
					var w = $('#grossBild').width();
					
					$('#grossBild img').load(function()
					{
						if ($('#grossBild img').width() > w)
						{
							$('#grossBild img').removeAttr('height').attr( { width : w });
						}
						$('#grossBild img').css( {
							'marginTop' : -($('#grossBild img').height() / 2),
							'marginLeft' : -($('#grossBild img').width() / 2) }).fadeTo(200, 1);
					});
					
					$('#grossBild img').attr( { src : this.href });
					$('#grossInfo').html($this.find('.info').html());
					
					$('#grossWeiter').click(function()
					{
						if ($this.attr('id') != 't' + (window.numThumbs - 1))
						{
							$('#grossZurueck').css( { visibility : 'visible' });
							$('#gross').fadeOut(10, function()
							{
								$('#gross').remove();
								
								$next = $this.parent().next();
								
								while ($next.next().length > 0 && $next.children('a').length == 0)
								{
									$next = $next.next();
								}
								
								$next.children('a').trigger('click');
							});
						}
						return false;
					});
					
					$('#grossZurueck').click(function()
					{
						if ($this.attr('id') != 't0')
						{
							$('#gross').fadeOut(10, function()
							{
								$('#gross').remove();
								
								$prev = $this.parent().prev();
								
								while ($prev.prev().length > 0 && $prev.children('a').length == 0)
								{
									$prev = $prev.prev();
								}
								
								$prev.children('a').trigger('click');
							});
						}
						$('#grossWeiter').css( { visibility : 'visible' });
						return false;
					});
					
					return false;
				});
		}
	});