(function ($) {
	$.fn.lightBox = function (j) {
		j = jQuery.extend({
			overlayBgColor: '#000',
			overlayOpacity: 0.8,
			fixedNavigation: false,
			imageLoading: '/css/img/lightbox/lightbox-ico-loading.gif',
			imageBtnPrev: '/css/img/lightbox/lightbox-btn-prev.gif',
			imageBtnNext: '/css/img/lightbox/lightbox-btn-next.gif',
			imageBtnClose: '/css/img/lightbox/lightbox-btn-close.gif',
			imageBlank: '/css/img/lightbox/lightbox-blank.gif',
			containerBorderSize: 10,
			containerResizeSpeed: 400,
			txtImage: 'Image',
			txtOf: 'of',
			keyToClose: 'c',
			keyToPrev: 'p',
			keyToNext: 'n',
			imageArray: [],
			activeImage: 0,
			showNavigation: true,
			root: '/'
		},
		j);
		var k = this;

		function _initialize() {
			_start(this, k);
			return false
		}

		function _start(a, b) {
			$('embed, object, select, #y').css({
				'visibility': 'hidden'
			});
			_set_interface();
			j.imageArray.length = 0;
			j.activeImage = 0;
			if (b.length == 1) {
				j.imageArray.push(new Array(a.getAttribute('href'), a.getAttribute('title')))
			} else {
				for (var i = 0; i < b.length; i++) {
					j.imageArray.push(new Array(b[i].getAttribute('href'), b[i].getAttribute('title')))
				}
			}
			while (j.imageArray[j.activeImage][0] != a.getAttribute('href')) {
				j.activeImage++
			}
			if(j.showNavigation==false){
				j.imageArray.length = 1;
			}
			_set_image_to_view()
		}

		function _set_interface() {
			$('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="' + j.root + j.imageLoading + '"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="' + j.root + j.imageBtnClose + '"></a></div></div></div></div>');
			var c = ___getPageSize();
			$('#jquery-overlay').css({
				backgroundColor: j.overlayBgColor,
				opacity: j.overlayOpacity,
				width: c[0],
				height: c[1]
			}).fadeIn();
			var d = ___getPageScroll();
			$('#jquery-lightbox').css({
				top: d[1] + (c[3] / 10),
				left: d[0]
			}).show();
			$('#jquery-overlay,#jquery-lightbox').click(function () {
				_finish()
			});
			$('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function () {
				_finish();
				return false
			});
			$(window).resize(function () {
				var a = ___getPageSize();
				$('#jquery-overlay').css({
					width: a[0],
					height: a[1]
				});
				var b = ___getPageScroll();
				$('#jquery-lightbox').css({
					top: b[1] + (a[3] / 10),
					left: b[0],
					"padding-bottom": "50px"
				})
			});
			$(window).scroll(function () {
				$('#jquery-overlay').css({
					width: $(document).width(),
					height: $(document).height()
				});
				$('#jquery-lightbox').css({
					"padding-bottom": "50px"
				})
			})
		}

		function _set_image_to_view() {
			$('#lightbox-loading').show();
			if (j.fixedNavigation) {
				$('#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide()
			} else {
				$('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide()
			}
			var a = new Image();
			a.onload = function () {
				$('#lightbox-image').attr('src', j.imageArray[j.activeImage][0]);
				_resize_container_image_box(a.width, a.height);
				a.onload = function () {}
			};
			a.src = j.imageArray[j.activeImage][0]
		};

		function _resize_container_image_box(a, b) {
			var c = $('#lightbox-container-image-box').width();
			var d = $('#lightbox-container-image-box').height();
			var e = (a + (j.containerBorderSize * 2));
			var f = (b + (j.containerBorderSize * 2));
			var g = c - e;
			var h = d - f;
			$('#lightbox-container-image-box').animate({
				width: e,
				height: f
			},
			j.containerResizeSpeed, function () {
				_show_image()
			});
			if ((g == 0) && (h == 0)) {
				if ($.browser.msie) {
					___pause(250)
				} else {
					___pause(100)
				}
			}
			$('#lightbox-container-image-data-box').css({
				width: a
			});
			$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({
				height: b + (j.containerBorderSize * 2)
			})
		};

		function _show_image() {
			$('#lightbox-loading').hide();
			$('#lightbox-image').fadeIn(function () {
				_show_image_data();
				_set_navigation()
			});
			_preload_neighbor_images()
		};

		function _show_image_data() {
			$('#lightbox-container-image-data-box').slideDown('fast');
			$('#lightbox-image-details-caption').hide();
			if (j.imageArray[j.activeImage][1]) {
				$('#lightbox-image-details-caption').html(j.imageArray[j.activeImage][1]).show()
			}
			if (j.imageArray.length > 1) {
				$('#lightbox-image-details-currentNumber').html(j.txtImage + ' ' + (j.activeImage + 1) + ' ' + j.txtOf + ' ' + j.imageArray.length).show()
			}
		}

		function _set_navigation() {
			if(j.showNavigation)
				$('#lightbox-nav').show();
			$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({
				'background': 'transparent url(' + j.root + j.imageBlank + ') no-repeat'
			});
			if (j.activeImage != 0) {
				if (j.fixedNavigation) {
					$('#lightbox-nav-btnPrev').css({
						'background': 'url(' + j.root + j.imageBtnPrev + ') left 15% no-repeat'
					}).unbind().bind('click', function () {
						j.activeImage = j.activeImage - 1;
						_set_image_to_view();
						return false
					})
				} else {
					$('#lightbox-nav-btnPrev').unbind().hover(function () {
						$(this).css({
							'background': 'url(' + j.root + j.imageBtnPrev + ') left 15% no-repeat'
						})
					},


					function () {
						$(this).css({
							'background': 'transparent url(' + j.root + j.imageBlank + ') no-repeat'
						})
					}).show().bind('click', function () {
						j.activeImage = j.activeImage - 1;
						_set_image_to_view();
						return false
					})
				}
			}
			if (j.activeImage != (j.imageArray.length - 1)) {
				if (j.fixedNavigation) {
					$('#lightbox-nav-btnNext').css({
						'background': 'url(' + j.root + j.imageBtnNext + ') right 15% no-repeat'
					}).unbind().bind('click', function () {
						j.activeImage = j.activeImage + 1;
						_set_image_to_view();
						return false
					})
				} else {
					$('#lightbox-nav-btnNext').unbind().hover(function () {
						$(this).css({
							'background': 'url(' + j.root + j.imageBtnNext + ') right 15% no-repeat'
						})
					},


					function () {
						$(this).css({
							'background': 'transparent url(' + j.root + j.imageBlank + ') no-repeat'
						})
					}).show().bind('click', function () {
						j.activeImage = j.activeImage + 1;
						_set_image_to_view();
						return false
					})
				}
			}
			_enable_keyboard_navigation()
		}

		function _enable_keyboard_navigation() {
			$(document).keydown(function (a) {
				_keyboard_action(a)
			})
		}

		function _disable_keyboard_navigation() {
			$(document).unbind()
		}

		function _keyboard_action(a) {
			if (a == null) {
				keycode = event.keyCode;
				escapeKey = 27
			} else {
				keycode = a.keyCode;
				escapeKey = a.DOM_VK_ESCAPE
			}
			key = String.fromCharCode(keycode).toLowerCase();
			if ((key == j.keyToClose) || (key == 'x') || (keycode == escapeKey)) {
				_finish()
			}
			if ((key == j.keyToPrev) || (keycode == 37)) {
				if (j.activeImage != 0) {
					j.activeImage = j.activeImage - 1;
					_set_image_to_view();
					_disable_keyboard_navigation()
				}
			}
			if ((key == j.keyToNext) || (keycode == 39)) {
				if (j.activeImage != (j.imageArray.length - 1)) {
					j.activeImage = j.activeImage + 1;
					_set_image_to_view();
					_disable_keyboard_navigation()
				}
			}
		}

		function _preload_neighbor_images() {
			if ((j.imageArray.length - 1) > j.activeImage) {
				objNext = new Image();
				objNext.src = j.imageArray[j.activeImage + 1][0]
			}
			if (j.activeImage > 0) {
				objPrev = new Image();
				objPrev.src = j.imageArray[j.activeImage - 1][0]
			}
		}

		function _finish() {
			$('#jquery-lightbox').remove();
			$('#jquery-overlay').fadeOut(function () {
				$('#jquery-overlay').remove()
			});
			$('embed, object, select, #f').css({
				'visibility': 'visible'
			});
		}

		function ___getPageSize() {
			var a, yScroll;
			if (window.innerHeight && window.scrollMaxY) {
				a = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY
			} else if (document.body.scrollHeight > document.body.offsetHeight) {
				a = document.body.scrollWidth;
				yScroll = document.body.scrollHeight
			} else {
				a = document.body.offsetWidth;
				yScroll = document.body.offsetHeight
			}
			var b, windowHeight;
			if (self.innerHeight) {
				if (document.documentElement.clientWidth) {
					b = document.documentElement.clientWidth
				} else {
					b = self.innerWidth
				}
				windowHeight = self.innerHeight
			} else if (document.documentElement && document.documentElement.clientHeight) {
				b = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight
			} else if (document.body) {
				b = document.body.clientWidth;
				windowHeight = document.body.clientHeight
			}
			if (yScroll < windowHeight) {
				pageHeight = windowHeight
			} else {
				pageHeight = yScroll
			}
			if (a < b) {
				pageWidth = a
			} else {
				pageWidth = b
			}
			arrayPageSize = new Array(pageWidth, pageHeight, b, windowHeight);
			return arrayPageSize
		};

		function ___getPageScroll() {
			var a, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				a = self.pageXOffset
			} else if (document.documentElement && document.documentElement.scrollTop) {
				yScroll = document.documentElement.scrollTop;
				a = document.documentElement.scrollLeft
			} else if (document.body) {
				yScroll = document.body.scrollTop;
				a = document.body.scrollLeft
			}
			arrayPageScroll = new Array(a, yScroll);
			return arrayPageScroll
		};

		function ___pause(a) {
			var b = new Date();
			c = null;
			do {
				var c = new Date()
			} while (c - b < a)
		};
		return this.unbind('click').click(_initialize)
	}
})(jQuery);

//nF();
