/**
 * jQuery lightBox plugin
 * This jQuery plugin was inspired and based on Lightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/lightbox2/)
 * and adapted to me for use like a plugin from jQuery.
 * @name lightbox
 * @author Leandro Vieira Pinho - http://leandrovieira.com
 * @author Felix Hekhorn <felixhekhorn@creffect.net>
 * @version 0.5
 * @date Mai 02, 2009
 * @category jQuery plugin
 * @copyright (c) 2008 Leandro Vieira Pinho (leandrovieira.com)
 * @license CC Attribution-No Derivative Works 2.5 Brazil - http://creativecommons.org/licenses/by-nd/2.5/br/deed.en_US
 * @example Visit http://leandrovieira.com/projects/jquery/lightbox/ for more informations about this jQuery plugin
 */

//Einstellungen speichern
if (typeof LightboxGlobalSettings === 'undefined')
{
	LightboxGlobalSettings = new Object();
	LightboxGlobalNextTriggerId = 0;
}

// Offering a Custom Alias suport - More info: http://docs.jquery.com/Plugins/Authoring#Custom_Alias
(function($) {
	
	/**
	 * $ is an alias to jQuery object
	 *
	 */
	$.fn.lightBox = function(UserSettings)
	{
		// DefaultVorgaben
		var DefaultSettings = $.fn.lightBox.LightboxDefaultSettings;

		// Settings to configure the jQuery lightBox plugin how you like
		var settings = jQuery.extend({},DefaultSettings, UserSettings);

		// Einstellungen laden
		if (UserSettings && typeof UserSettings != 'string')
		{
			if (UserSettings.Overlay)
				settings.Overlay = jQuery.extend({},DefaultSettings.Overlay,UserSettings.Overlay);
			if (UserSettings.Navigation)
			{
				settings.Navigation = jQuery.extend({},DefaultSettings.Navigation,UserSettings.Navigation);
				if (UserSettings.Navigation.Slideshow)
					settings.Navigation.Slideshow = jQuery.extend({},DefaultSettings.Navigation.Slideshow,UserSettings.Navigation.Slideshow);
			}
			if (UserSettings.Images)
				settings.Images = jQuery.extend({},DefaultSettings.Images,UserSettings.Images);
			if (UserSettings.Container)
				settings.Container = jQuery.extend({},DefaultSettings.Container,UserSettings.Container);
			if (UserSettings.Txt)
				settings.Txt = jQuery.extend({},DefaultSettings.Txt,UserSettings.Txt);
			if (UserSettings.Key)
				settings.Key = jQuery.extend({},DefaultSettings.Key,UserSettings.Key);
			if (UserSettings.Code)
				settings.Code = jQuery.extend({},DefaultSettings.Code,UserSettings.Code);
			if (UserSettings.Callback)
				settings.Callback = jQuery.extend({},DefaultSettings.Callback,UserSettings.Callback);
		}		
		
		// Caching the jQuery object with all elements matched
		var jQueryMatchedObj = this; // This, in this context, refer to jQuery object

		// Speichern
		if (typeof UserSettings != 'string')
		{
			LightboxGlobalSettings[jQueryMatchedObj.selector] = settings;
		}

		// Einstellungen laden
		settings = LightboxGlobalSettings[jQueryMatchedObj.selector];
		
		// SlideShow abspielen?
		if (typeof UserSettings == 'string' && UserSettings.indexOf('slideshow_play') == 0)
		{
			var CurTrigger = UserSettings.substr(('slideshow_play').length+1);
			CurTrigger = parseInt(CurTrigger);
			_slideshow_play(CurTrigger);
			return;
		}
		
		/**
		 * Initializing the plugin calling the start function
		 *
		 * @return boolean false
		 */
		function _initialize()
		{
			_start(this,jQueryMatchedObj); // This, in this context, refer to object (link) which the user have clicked
			return false; // Avoid the browser following the link
		};
		
		/**
		 * Start the jQuery lightBox plugin
		 *
		 * @param object objClicked The object (link) whick the user have clicked
		 * @param object jQueryMatchedObj The jQuery object with all elements matched
		 */
		function _start(objClicked,jQueryMatchedObj)
		{
			// Unset total images in imageArray
			settings.Core.imageArray.length = 0;
			// Unset image active information
			settings.Core.activeImage = 0;
			// We have an image set? Or just an image? Let´s see it.
			if ( jQueryMatchedObj.length == 1 )
			{
				settings.Core.imageArray.push({pos: 0, src: objClicked.getAttribute('href'), title: objClicked.getAttribute('title')});
			} else {
				// Add an Array (as many as we have), with href and title atributes, inside the Array that storage the images references		
				for ( var i = 0; i < jQueryMatchedObj.length; ++i ) 
				{
					if (jQueryMatchedObj[i].getAttribute('name') == 'NoImage') continue;
					settings.Core.imageArray.push({pos: i, src: jQueryMatchedObj[i].getAttribute('href'), title: jQueryMatchedObj[i].getAttribute('title')});
				}
			}
			while ( settings.Core.imageArray[settings.Core.activeImage].src != objClicked.getAttribute('href') )
				settings.Core.activeImage++;
			
			++LightboxGlobalNextTriggerId;
			
			// Callback aufrufen
			var Callback = settings.Callback.OnStart(settings.Core.imageArray[settings.Core.activeImage]);
			if (Callback === false) return;
			// Hime some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
			$('embed, object, select').css({ 'visibility' : 'hidden' });
			// Call the function to create the markup structure; style some elements; assign events in some elements.
			_set_interface();
			// Call the function that prepares image exibition
			if (settings.Navigation.Panel == 'slideshow' && settings.Navigation.Slideshow.AutoStart)
			{
				--settings.Core.activeImage;
				settings.Core.Slideshow.Loop = true;
				_slideshow_play(LightboxGlobalNextTriggerId);
			}
			else
				_slide_to_pos(settings.Core.activeImage);
		};
		
		/**
		 * Create the jQuery lightBox plugin interface
		 */
		function _set_interface()
		{
			// Apply the HTML markup into body tag
			$('body').append(
				'<div id="jquery-overlay"></div>'+
				'<div id="jquery-lightbox">'+
					'<div id="lightbox-container-image-box" class="lightbox-all lightbox-container-image-box" >'+
						settings.Code.PreImage +
						'<div id="lightbox-container-image" class="lightbox-all lightbox-container-image" >'+
							'<img id="lightbox-image" src="" />'+
							'<div id="lightbox-nav" >'+
								'<a href="#" id="lightbox-nav-btnPrev" ></a>'+
								'<a href="#" id="lightbox-nav-btnNext" ></a>'+
							'</div>'+
							'<div id="lightbox-loading" class="lightbox-all lightbox-loading" >'+
								'<a href="#" id="lightbox-loading-link" class="lightbox-all lightbox-loading-link" >'+
									'<img src="' + settings.Images.Loading + '">'+
								'</a>'+
							'</div>'+
						'</div>'+
						settings.Code.PostImage +
					'</div>'+
					'<div id="lightbox-container-image-data-box" class="lightbox-all lightbox-container-image-data-box" >'+
						'<div id="lightbox-container-image-data" class="lightbox-all lightbox-container-image-data" >'+
							settings.Code.PreCaption +
							'<div id="lightbox-image-details" class="lightbox-all lightbox-image-details" >'+
								'<span id="lightbox-image-details-caption" class="lightbox-all lightbox-image-details-caption"></span>'+
							'</div>'+
							settings.Code.PostCaption +
							'<div id="lightbox-panel" class="lightbox-all lightbox-panel">'+
							_get_panel()+
							'</div>'+
							settings.Code.PreFoot +
							'<div id="lightbox-foot" class="lightbox-all lightbox-foot" >'+
								'<div id="lightbox-container-currentNumber" class="lightbox-all lightbox-container-currentNumber" >'+
									'<span id="lightbox-image-details-currentNumber" class="lightbox-all lightbox-image-details-currentNumber" ></span>'+
								'</div>'+
								'<div id="lightbox-secNav" class="lightbox-all lightbox-secNav" >'+
									'<a href="#" id="lightbox-secNav-btnClose" class="lightbox-all lightbox-secNav-btnClose" >'+
										'<img src="' + settings.Images.BtnClose + '" />'+
									'</a>'+
								'</div>'+
							'</div>'+
							settings.Code.PostFoot +
						'</div>'+
					'</div>'+
				'</div>');
			// Style overlay and show it
			$('#jquery-overlay').css({
				backgroundColor:	settings.Overlay.BgColor,
				opacity:			settings.Overlay.Opacity,
				width:				$(document).width() - 20,
				height:				$(document).height()
			}).fadeIn();
			// Calculate top and left offset for the jquery-lightbox div object and show it
			$('#jquery-lightbox').css({
				top:	$(window).scrollTop()+50,
				left:	$(window).scrollLeft()
			}).show();
			// Assigning click events in elements to close overlay
			$('#jquery-overlay,#jquery-lightbox').click(function() {
				_finish();	
				return false;								
			});
			// Assign the _finish function to lightbox-loading-link and lightbox-secNav-btnClose objects
			$('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function() {
				_finish();
				return false;
			});
			$('#lightbox-container-image-data-box').click(function(){return false;});
			// If window was resized, calculate the new overlay dimensions
			$(window).resize(function() {
				// Style overlay and show it
				$('#jquery-overlay').css({
					width:		$(document).width() - 20,
					height:		$(document).height()
				});
				// Get page scroll
				// Calculate top and left offset for the jquery-lightbox div object and show it
				$('#jquery-lightbox').css({
					top:	$(window).scrollTop()+50,
					left:	$(window).scrollLeft()
				});
			});
			// UserKlassen anfügen
			if (typeof settings.AddClassPrefix == 'string')
				_add_classes(true);
		}
		
		/**
		 * Fügt bzw. löscht die UserKlassen
		 * @param bool flag falls true einfügen, sonst löschen
		 */
		function _add_classes(flag)
		{
			var Elems = ['lightbox-container-image-box','lightbox-container-image',
	             'lightbox-loading','lightbox-loading-link',
	             'lightbox-container-image-data-box','lightbox-container-image-data',
	             'lightbox-image-details','lightbox-image-details-caption',
	             'lightbox-panel',
	             'lightbox-container-panel-classic-pre','lightbox-panel-classic-pre','lightbox-container-panel-classic-next','lightbox-panel-classic-next',
	             'lightbox-container-panel-slideshow-first','lightbox-panel-slideshow-first',
	             'lightbox-container-panel-slideshow-prev','lightbox-panel-slideshow-prev',
	             'lightbox-container-panel-slideshow-play','lightbox-panel-slideshow-play',
	             'lightbox-container-panel-slideshow-next','lightbox-panel-slideshow-next',
	             'lightbox-container-panel-slideshow-last','lightbox-panel-slideshow-last',
	             'lightbox-foot','lightbox-container-currentNumber','lightbox-image-details-currentNumber',
	             'lightbox-secNav','lightbox-secNav-btnClose'];
			if (flag)
			{
				for (var i in Elems)
				{
					$('#'+Elems[i]).addClass(settings.AddClassPrefix+'lightbox-all').addClass(settings.AddClassPrefix+Elems[i]);
				}
			}
			else
			{
				for (var i in Elems)
					$('#'+Elems[i]).removeClass(settings.AddClassPrefix+'lightbox-all').removeClass(settings.AddClassPrefix+Elems[i]);
			}
		}
		
		/**
		 * Gibt den HTMLCode für das richtige Panel zurück
		 */
		function _get_panel()
		{
			switch (settings.Navigation.Panel)
			{
			case 'none': return ''; break;
			case 'classic':
				return '<div id="lightbox-container-panel-classic-pre" class="lightbox-all lightbox-container-panel-classic-pre" >'+
						'<a id="lightbox-panel-classic-pre" href="#" class="lightbox-all lightbox-panel-classic-pre" >'+settings.Txt.PanelClassic.Back+'</a>'+
					'</div>'+
					'<div id="lightbox-container-panel-classic-next" class="lightbox-all lightbox-container-panel-classic-next" >'+
						'<a id="lightbox-panel-classic-next" href="#" class="lightbox-all lightbox-panel-classic-pre" >'+settings.Txt.PanelClassic.Prev+'</a>'+
					'</div>';
				break;
			case 'slideshow':
				return '<div id="lightbox-container-panel-slideshow-first" class="lightbox-all lightbox-container-panel-slideshow-first" >'+
						'<a id="lightbox-panel-slideshow-first" href="#" class="lightbox-all lightbox-panel-slideshow-first" >'+settings.Txt.PanelSlideshow.First+'</a>'+
					'</div>'+
					'<div id="lightbox-container-panel-slideshow-prev" class="lightbox-all lightbox-container-panel-slideshow-prev" >'+
						'<a id="lightbox-panel-slideshow-prev" href="#" class="lightbox-all lightbox-panel-slideshow-prev" >'+settings.Txt.PanelSlideshow.Back+'</a>'+
					'</div>'+
					'<div id="lightbox-container-panel-slideshow-play" class="lightbox-all lightbox-container-panel-slideshow-play" >'+
						'<a id="lightbox-panel-slideshow-play" href="#" class="lightbox-all lightbox-panel-slideshow-play" >'+settings.Txt.PanelSlideshow.Play+'</a>'+
					'</div>'+
					'<div id="lightbox-container-panel-slideshow-next" class="lightbox-all lightbox-container-panel-slideshow-next" >'+
						'<a id="lightbox-panel-slideshow-next" href="#" class="lightbox-all lightbox-panel-slideshow-next" >'+settings.Txt.PanelSlideshow.Prev+'</a>'+
					'</div>'+
					'<div id="lightbox-container-panel-slideshow-last" class="lightbox-all lightbox-container-panel-slideshow-last" >'+
						'<a id="lightbox-panel-slideshow-last" href="#" class="lightbox-all lightbox-panel-slideshow-last" >'+settings.Txt.PanelSlideshow.Last+'</a>'+
					'</div>';
				break;
			}
			return '';
		}
		
		/**
		 * Bindet die KlickFunktionen ans Panel
		 */
		function _update_panel()
		{
			switch (settings.Navigation.Panel)
			{
			case 'none': break;
			case 'classic':
				// Show the prev button, if not the first image in set
				if ( settings.Core.activeImage != 0 )
				{
					$('#lightbox-panel-classic-pre').unbind().css({'visibility': 'visible'}).bind('click',function() {
						_slide_to_pos(settings.Core.activeImage - 1);
						return false;
					});
				}
				else
					{$('#lightbox-panel-classic-pre').unbind().css({'visibility': 'hidden'});}
				
				// Show the next button, if not the last image in set
				if ( settings.Core.activeImage != ( settings.Core.imageArray.length -1 ) )
				{
					$('#lightbox-panel-classic-next').unbind().css({'visibility': 'visible'}).bind('click',function() {
						_slide_to_pos(settings.Core.activeImage + 1);
						return false;
					});
				}
				else
					{$('#lightbox-panel-classic-next').unbind().css({'visibility': 'hidden'});}
				break;
			case 'slideshow':
				
				// Show the prev button, if not the first image in set
				if ( settings.Core.activeImage > 0 )
				{
					$('#lightbox-panel-slideshow-prev').unbind('click').css({'visibility': 'visible'}).bind('click',function() {
						_slide_to_pos(settings.Core.activeImage - 1);
						return false;
					});

					// Zum Anfang springen
					$('#lightbox-panel-slideshow-first').unbind('click').css({'visibility': 'visible'}).bind('click',function() {
						_slide_to_pos(0);
						return false;
					});
				}
				else
				{
					$('#lightbox-panel-slideshow-prev').unbind('click').css({'visibility': 'hidden'});
					$('#lightbox-panel-slideshow-first').unbind('click').css({'visibility': 'hidden'});
				}
				
				// PlayButton
				if (settings.Core.Slideshow.Loop)
				{
					$('#lightbox-panel-slideshow-play').unbind('click').html(settings.Txt.PanelSlideshow.Stop).bind('click',function() {
						settings.Core.Slideshow.Loop = false;
						$(this).unbind('click').html(settings.Txt.PanelSlideshow.Play).bind('click',function() {
							settings.Core.Slideshow.Loop = true;
							_slideshow_play(LightboxGlobalNextTriggerId);
							return false;
						});
						return false;
					});
				}
				else
				{
					$('#lightbox-panel-slideshow-play').unbind('click').html(settings.Txt.PanelSlideshow.Play).bind('click',function() {
						settings.Core.Slideshow.Loop = true;
						_slideshow_play(LightboxGlobalNextTriggerId);
						return false;
					});
				}
				
				// Show the next button, if not the last image in set
				if ( settings.Core.activeImage < ( settings.Core.imageArray.length -1 ) )
				{
					$('#lightbox-panel-slideshow-next').unbind('click').css({'visibility': 'visible'}).bind('click',function() {
						_slide_to_pos(settings.Core.activeImage + 1);
						return false;
					});
					
					// Zum Ende springen
					$('#lightbox-panel-slideshow-last').unbind('click').css({'visibility': 'visible'}).bind('click',function() {
						_slide_to_pos(settings.Core.imageArray.length -1);
						return false;
					});
				}
				else
				{
					$('#lightbox-panel-slideshow-next').unbind('click').css({'visibility': 'hidden'});
					$('#lightbox-panel-slideshow-last').unbind('click').css({'visibility': 'hidden'});
				}
						
				break;
			}
		}
		
		/**
		 * Wechselt zum Bild mit der Nummer pos
		 * @param int pos neue IndexPosition
		 * @param bool StopSlideshow soll die Slideshow gestoppt werden?
		 */
		function _slide_to_pos(pos, StopSlideshow)
		{
			// Callback aufrufen
			var Callback = settings.Callback.OnSlide(settings.Core.imageArray[settings.Core.activeImage], pos);
			if (Callback === false) return;
			else if (Callback === true)	settings.Core.activeImage = pos;
			else if (typeof Callback == 'number')
			{
				if (Callback == settings.Core.activeImage) return;
				else settings.Core.activeImage = Callback;
			}			
			_set_image_to_view(StopSlideshow);
		}
		
		/**
		 * Spielt die Slideshow ab
		 * @param int Trigger auslösender Aufruf
		 */
		function _slideshow_play(Trigger)
		{
			// Beenden?
			if (settings.Navigation.Panel != 'slideshow') return;
			if (!settings.Core.Slideshow.Loop) return;
			if (Trigger !== LightboxGlobalNextTriggerId) return;
			// nächstes Bild
			if (settings.Core.activeImage >= ( settings.Core.imageArray.length -1 ))
			{
				// Schleife?
				if (!settings.Navigation.Slideshow.Loop)
				{
					settings.Core.Slideshow.Loop = false;
					$('#lightbox-panel-slideshow-play').unbind().html(settings.Txt.PanelSlideshow.Play).bind('click',function() {
						settings.Core.Slideshow.Loop = true;
						_slideshow_play();
						return false;
					});
					return;
				}
				_slide_to_pos(0, false);
			}
			else
				_slide_to_pos(settings.Core.activeImage +1, false);
			window.setTimeout('$("'+jQueryMatchedObj.selector+'").lightBox("slideshow_play|'+Trigger+'");',parseInt(settings.Navigation.Slideshow.Duration));
		}
		
		/**
		 * Prepares image exibition; doing a image´s preloader to calculate it´s size
		 * @param bool StopSlideshow soll die Slideshow gestoppt werden? default: true
		 */
		function _set_image_to_view(StopSlideshow)
		{
			// Slideshow stoppen
			if (StopSlideshow == undefined) StopSlideshow = true;
			if (StopSlideshow) settings.Core.Slideshow.Loop = false;
			// Show the loading #lightbox-image,
			if ($('#lightbox-image').attr('src') !== "")
			{
				$('#lightbox-image').fadeOut(parseInt(settings.Container.ImgFadingSpeed), function(){_set_load_new_image();});
				$('#lightbox-loading').css({ 'background' : 'transparent url(' + settings.Images.Blank + ') no-repeat' });
			}
			else
				$('#lightbox-image').hide();
			$('#lightbox-loading').show();
			if ( settings.Navigation.FixHover ) {
				$('#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();
			} else {
				// Hide some elements
				$('#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();
			}
			// Image preload process
			if ($('#lightbox-image').attr('src') === "")
				_set_load_new_image();
		};
		
		function _set_load_new_image()
		{
			// Image preload process
			var objImagePreloader = new Image();
			objImagePreloader.onload = function()
			{
				$('#lightbox-image').attr('src',settings.Core.imageArray[settings.Core.activeImage].src);
				// Perfomance an effect in the image container resizing it
				_resize_container_image_box(objImagePreloader.width,objImagePreloader.height);
				//	clear onLoad, IE behaves irratically with animated gifs otherwise
				objImagePreloader.onload=function(){};
			};
			objImagePreloader.src = settings.Core.imageArray[settings.Core.activeImage].src;
		};
		
		/**
		 * Perfomance an effect in the image container resizing it
		 *
		 * @param integer intImageWidth The image´s width that will be showed
		 * @param integer intImageHeight The image´s height that will be showed
		 */
		function _resize_container_image_box(intImageWidth,intImageHeight)
		{
			BorderSize = parseInt(settings.Container.BorderSize);
			// Get current width and height
			var intCurrentWidth = $('#lightbox-container-image-box').width();
			var intCurrentHeight = $('#lightbox-container-image-box').height();
			// Get the width and height of the selected image plus the padding
			var intWidth = (intImageWidth + (BorderSize * 2)); // Plus the image´s width and the left and right padding value
			var intHeight = (intImageHeight + (BorderSize * 2)); // Plus the image´s height and the left and right padding value
			// Diferences
			var intDiffW = intCurrentWidth - intWidth;
			var intDiffH = intCurrentHeight - intHeight;
			// Perfomance the effect
			$('#lightbox-container-image-box').animate({ width: intWidth, height: intHeight },parseInt(settings.Container.ResizeSpeed), function() { _show_image(); });
			$('#lightbox-container-image-data-box').css({ width: intImageWidth });
			$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ height: intImageHeight + (BorderSize * 2) });
		};
		
		/**
		 * Show the prepared image
		 *
		 */
		function _show_image()
		{
			$('#lightbox-loading').hide();
			$('#lightbox-image').fadeIn(parseInt(settings.Container.ImgFadingSpeed), function() {
				_show_image_data();
				_set_navigation();
			});
			_preload_neighbor_images();
		};
		
		/**
		 * Show the image information
		 *
		 */
		function _show_image_data()
		{
			$('#lightbox-container-image-data-box').slideDown('fast');
			$('#lightbox-image-details-caption').hide();
			if ( settings.Core.imageArray[settings.Core.activeImage].title ) {
				$('#lightbox-image-details-caption').html(settings.Core.imageArray[settings.Core.activeImage].title).show();
			}
			// If we have a image set, display 'Image X of X'
			if ( settings.Core.imageArray.length > 1 ) {
				$('#lightbox-image-details-currentNumber').html(settings.Txt.Image + ' ' + ( settings.Core.activeImage + 1 ) + ' ' + settings.Txt.Of + ' ' + settings.Core.imageArray.length).show();
			}		
		};
		
		/**
		 * Display the button navigations
		 *
		 */
		function _set_navigation()
		{
			$('#lightbox-nav').show();

			// Instead to define this configuration in CSS file, we define here. And it´s need to IE. Just.
			$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ 'background' : 'transparent url(' + settings.Images.Blank + ') no-repeat' });
			
			// Show the prev button, if not the first image in set
			if ( settings.Core.activeImage != 0 )
			{
				if ( settings.Navigation.FixHover )
				{
					$('#lightbox-nav-btnPrev').css({ 'background' : 'url(' + settings.Images.BtnPrev + ') left 15% no-repeat' })
						.unbind()
						.bind('click',function() {
							_slide_to_pos(settings.Core.activeImage - 1);
							return false;
						});
				} else {
					// Show the images button for Next buttons
					$('#lightbox-nav-btnPrev').unbind().hover(function() {
						$(this).css({ 'background' : 'url(' + settings.Images.BtnPrev + ') left 15% no-repeat' });
					},function() {
						$(this).css({ 'background' : 'transparent url(' + settings.Images.Blank + ') no-repeat' });
					}).show().bind('click',function() {
						_slide_to_pos(settings.Core.activeImage - 1);
						return false;
					});
				}
			}
			else
				{$('#lightbox-nav-btnPrev').unbind().bind('click',function() {return false;});}
			
			// Show the next button, if not the last image in set
			if ( settings.Core.activeImage != ( settings.Core.imageArray.length -1 ) )
			{
				if ( settings.Navigation.FixHover )
				{
					$('#lightbox-nav-btnNext').css({ 'background' : 'url(' + settings.Images.BtnNext + ') right 15% no-repeat' })
						.unbind()
						.bind('click',function() {
							_slide_to_pos(settings.Core.activeImage + 1);
							return false;
						});
				} else {
					// Show the images button for Next buttons
					$('#lightbox-nav-btnNext').unbind().hover(function() {
						$(this).css({ 'background' : 'url(' + settings.Images.BtnNext + ') right 15% no-repeat' });
					},function() {
						$(this).css({ 'background' : 'transparent url(' + settings.Images.Blank + ') no-repeat' });
					}).show().bind('click',function() {
						_slide_to_pos(settings.Core.activeImage + 1);
						return false;
					});
				}
			}
			else
				{$('#lightbox-nav-btnNext').unbind().bind('click',function() {return false;});}
			
			// Panel updaten
			_update_panel();
			// Enable keyboard navigation
			_enable_keyboard_navigation();
		};
		
		/**
		 * Enable a support to keyboard navigation
		 *
		 */
		function _enable_keyboard_navigation()
		{
			$(document).keydown(function(objEvent) {
				_keyboard_action(objEvent);
			});
		};
		
		/**
		 * Disable the support to keyboard navigation
		 *
		 */
		function _disable_keyboard_navigation()
		{
			$(document).unbind();
		};
		
		/**
		 * Perform the keyboard actions
		 *
		 */
		function _keyboard_action(objEvent)
		{
			// To ie
			if ( objEvent == null ) {
				keycode = event.keyCode;
				escapeKey = 27;
			// To Mozilla
			} else {
				keycode = objEvent.keyCode;
				escapeKey = objEvent.DOM_VK_ESCAPE;
			}
			// Get the key in lower case form
			key = String.fromCharCode(keycode).toLowerCase();
			// Verify the keys to close the ligthBox
			if ( ( key == settings.Key.Close ) || ( key == 'x' ) || ( keycode == escapeKey ) ) {
				_finish();
			}
			// Verify the key to show the previous image
			if ( ( key == settings.Key.Prev ) || ( keycode == 37 ) ) {
				// If we´re not showing the first image, call the previous
				if ( settings.Core.activeImage != 0 ) {
					_slide_to_pos(settings.Core.activeImage - 1);
					_disable_keyboard_navigation();
				}
			}
			// Verify the key to show the next image
			if ( ( key == settings.Key.Next ) || ( keycode == 39 ) ) {
				// If we´re not showing the last image, call the next
				if ( settings.Core.activeImage != ( settings.Core.imageArray.length - 1 ) ) {
					_slide_to_pos(settings.Core.activeImage + 1);
					_disable_keyboard_navigation();
				}
			}
		};
		
		/**
		 * Preload prev and next images being showed
		 *
		 */
		function _preload_neighbor_images()
		{
			if ( (settings.Core.imageArray.length -1) > settings.Core.activeImage ) {
				objNext = new Image();
				objNext.src = settings.Core.imageArray[settings.Core.activeImage + 1].src;
			}
			if ( settings.Core.activeImage > 0 ) {
				objPrev = new Image();
				objPrev.src = settings.Core.imageArray[settings.Core.activeImage -1].src;
			}
		};
		
		/**
		 * Remove jQuery lightBox plugin HTML markup
		 *
		 */
		function _finish()
		{
			// Callback aufrufen
			var Callback = settings.Callback.OnClose(settings.Core.imageArray[settings.Core.activeImage]);
			if (Callback === false) return;
			
			// UserKlassen entfernen
			if (typeof settings.AddClassPrefix == 'string')
				_add_classes(false);
			// Slideshow stoppen
			settings.Core.Slideshow.Loop = false;
			
			$('#jquery-lightbox').remove();
			$('#jquery-overlay').fadeOut(function() { $('#jquery-overlay').remove(); });
			// Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
			$('embed, object, select').css({ 'visibility' : 'visible' });
		};
		
		// Return the jQuery object for chaining. The unbind method is used to avoid click conflict when the plugin is called more than once
		return this.unbind('click').click(_initialize);
	};
	
	$.fn.lightBox.LightboxDefaultSettings = 
	{
		// Configuration related to overlay
		Overlay:
		{
			BgColor: 		'#000',			// (string) Background color to overlay; inform a hexadecimal value like: #RRGGBB. Where RR, GG, and BB are the hexadecimal values for the red, green, and blue values of the color.
			Opacity:		0.8				// (integer) Opacity value to overlay; inform: 0.X. Where X are number from 0 to 9
		},
		// Configuration related to navigation
		Navigation:
		{
			FixHover:		false,		// (boolean) Boolean that informs if the navigation (next and prev button) will be fixed or not in the interface.
			Panel:			'classic',	// (string) Welches Panel soll gezeigt werden? classic|slideshow|none
			Slideshow:
			{
				Duration: 	3000,		// (integer) Standzeit eines Bildes
				AutoStart: 	false,		// (boolean) Soll die Slideshow beim Öffnen gestartet werden
				Loop:		true		// (boolean) Soll am Ende von vorne begonnen werden?
			}
		},
		// Configuration related to images
		Images :
		{
			Loading:			'../../Resources/jquery/lightbox/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
			BtnPrev:			'../../Resources/jquery/lightbox/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
			BtnNext:			'../../Resources/jquery/lightbox/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
			BtnClose:			'../../Resources/jquery/lightbox/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
			Blank:				'../../Resources/jquery/lightbox/lightbox-blank.gif'				// (string) Path and the name of a blank image (one pixel)
		},
		// Configuration related to container image box
		Container :
		{
			BorderSize:		10,			// (integer) If you adjust the padding in the CSS for the container, #lightbox-container-image-box, you will need to update this value
			ResizeSpeed:	400,		// (integer) Specify the resize duration of container image. These number are miliseconds. 
			ImgFadingSpeed: 600			// (integer) Specify the resize duration of the images. These number are miliseconds.
		},
		// Configuration related to texts in caption. For example: Image 2 of 8. You can alter either "Image" and "of" texts.
		Txt :
		{
			Image:				'Bild',		// (string) Specify text "Image"
			Of:					'von',		// (string) Specify text "of"
			PanelClassic: {					// Classic-Panel
				Back:			'&lt;&lt; Zur&uuml;ck',		// (string) Zurück
				Prev:			'Weiter &gt;&gt;'			// (string) Vorwärts
			},
			PanelSlideshow: {				// Slideshow-Panel
				First:			'|&lt;&lt;',		// (string) Anfang
				Back:			'&lt;&lt;',			// (string) Zurück
				Play:			'&gt;',				// (string) Play
				Stop:			'||',				// (string) Stopp
				Prev:			'&gt;&gt;',			// (string) Vorwärts
				Last:			'&gt;&gt;|'			// (string) Ende
			}
		},			
		// Configuration related to keyboard navigation
		Key :
		{
			Close:				'c',		// (string) (c = close) Letter to close the jQuery lightBox interface. Beyond this letter, the letter X and the ESCAPE key is used to.
			Prev:				'p',		// (string) (p = previous) Letter to show the previous image
			Next:				'n'			// (string) (n = next) Letter to show the next image.
		},
		// Zusätzlicher (HTML-)Code
		Code :
		{
			PreImage: 			'',			// (string) HTMLCode vor dem Bild
			PostImage:			'',			// (string) HTMLCode nach dem Bild
			PreCaption:			'',			// (string) HTMLCode vor der Überschrift
			PostCaption:		'',			// (string) HTMLCode nach der Überschrift
			PreFoot:			'',			// (string) HTMLCode vor der Fußzeile (Bildnummer+SchließenBtn)
			PostFoot:			''			// (string) HTMLCode nach der Fußzeile (Bildnummer+SchließenBtn)
		},
		AddClassPrefix: 	false,			// (string) falls gegeben, wird zu allen Elementen eine Klasse mit [AddClassPrefix]-lightbox-all sowie [AddClassPrefix]-[bisherige Klasse]
		Callback: 
		{
			OnStart:	function(CurPic){			// (function) wird vor dem Start aufgerufen;
				// @param object CurPic aktuelles Bildobjekt mit [pos],[src],[title]
				// falls false zurückgegeben wird, wird die Anzeige unterdrückt; 
				return true;},
			OnSlide:	function(CurPic, Target){ 	// (function) wird vor dem Bildwechsel aufgerufen;
					// @param object CurPic aktuelles Bildobjekt mit [pos],[src],[title]
					// @param int Target ZielIndexnummer
					// falls false zurückgegeben wird, wird der Wechsel unterdrückt,
					// falls true zurückgegeben wird, wird zur gegebenen Position gewechselt,
					// sonst kann eine Zahl als ZielIndexnummer zurückgegebenw werden
					return true;},
			OnClose:	function(CurPic){ 			// (function) wird vor dem Beenden aufgerufen;
					// @param object CurPic aktuelles Bildobjekt mit [pos],[src],[title]
					// falls false zurückgegeben wird, bleibt die Anzeige erhalten;
					return true;}
		},
		// Variablen für den internen Gebrauch
		Core :
		{
			// Don´t alter these variables in any way
			imageArray:				[],		// (array) Beinhaltet alle Bilder als Objekte mit [pos],[src],[title]
			activeImage:			0,		// (integer) Aktuelle Bildnummer
			Slideshow: 
			{
				Loop:			false,		// (boolean) läuft gerade die Slideshow?
				Trigger:		0			// (integer) Trigger nur für den aktuellen Aufruf auslösen
			}
		}
	};
	
	
})(jQuery); // Call and execute the function immediately passing the jQuery object
