﻿( function(jQuery) {
	jQuery.galleryUtility = {};
	jQuery.galleryUtility.centerImage = {};
	jQuery.galleryUtility.rightImage = {};
	jQuery.galleryUtility.leftImage = {};
	jQuery.galleryUtility.rightImageStorage = {};
	jQuery.galleryUtility.leftImageStorage = {};
	jQuery.galleryUtility.zoomImage = {};
	jQuery.galleryUtility.gallery = {};
	jQuery.galleryUtility.Options = {
		container : jQuery('#searchScroller'),
		Lheight : 250,
		Lwidth : 400,
		Lshrink : function(dimension) {
			return dimension * 0.75;
		},
		Lzoom : function(dimension) {
			return dimension * 2;
		},
		Pheight : 400,
		Pwidth : 300,
		Pshrink : function(dimension) {
			return dimension * 0.75;
		},
		Pzoom : function(dimension) {
			return dimension * 2;
		},
		defaultLayout : 'landscape',
		startClass : 'start',
		slideSpeed : 'normal',
		zoomSpeed : 'fast',
		gutterWidth : -40,
		captionUpPath : 'Images/SlidingGallery/captionUpArrow.png',
		captionUpWidth : 24,
		captionUpHeight : 17,
		captionUpID : 'captionArrowUp',
		captionDownPath : 'Images/SlidingGallery/captionDownArrow.png',
		captionDownWidth : 24,
		captionDownHeight : 17,
		captionDownID : 'captionArrowDown',
		captionHeight : function(zoomHeight) {
			return zoomHeight * 0.1;
		},
		captionStyle : 'background-color:white; color:black; opacity: 0.6; filter: alpha(opacity = 60); font-size: 16px; text-align:center;',
		captionClass : 'captionBox',
		captionID : 'activeCaption',
		captionTextAttribute : 'caption',
		useCaptions : false
	};
	jQuery.fn.slidingGallery1 = function(options) {
		jQuery.extend(jQuery.galleryUtility.Options, options);
		jQuery('body').css('overflow-x', 'hidden');
		var container = null;
		//alert(jQuery.galleryUtility.Options.container);
		if (!jQuery.galleryUtility.Options.container) {
			jQuery.galleryUtility.Options.container = jQuery('body');
		} else {
			jQuery.galleryUtility.Options.container.css('position', 'relative');
		}
		jQuery.galleryUtility.gallery = jQuery(this).css('cursor', 'pointer');
		jQuery.galleryUtility.definePositions();
		if (jQuery.galleryUtility.Options.useCaptions) {
			jQuery.galleryUtility.Options.container.append(
					'<img src="' + jQuery.galleryUtility.Options.captionUpPath
							+ '" style="width: '
							+ jQuery.galleryUtility.Options.captionUpWidth
							+ '; display: none; border-width:0px;"' + 'id="'
							+ jQuery.galleryUtility.Options.captionUpID + '" />')
					.append(
							'<img src="'
									+ jQuery.galleryUtility.Options.captionDownPath
									+ '" style="width: '
									+ jQuery.galleryUtility.Options.captionDownWidth
									+ '; display: none; border-width:0px;"'
									+ 'id="'
									+ jQuery.galleryUtility.Options.captionDownID
									+ '" />');
			jQuery(
					'#' + jQuery.galleryUtility.Options.captionUpID + ',#'
							+ jQuery.galleryUtility.Options.captionDownID).css(
					'cursor', 'help');
		}
		var lastIndex = 0;
		var gallerySize = jQuery.galleryUtility.gallery.each(
				function(i) {
					jQuery(this).attr( {
						'index' : i,
						'prev' : (i - 1),
						'next' : (i + 1)
					}).css('position', 'absolute');
					if ((jQuery(this).attr('layout') !== 'portrait')
							&& (jQuery(this).attr('layout') !== 'landscape')) {
						jQuery(this).attr('layout',
								jQuery.galleryUtility.Options.defaultLayout);
					}
					lastIndex = i;
				}).hide().size();
		gallerySize--;
		var currIndex = 0;
		while (gallerySize < 8) {
			var jQueryclone = jQuery.galleryUtility.gallery.filter(
					'[index=' + currIndex + ']').clone().attr( {
				'index' : lastIndex + 1,
				'prev' : lastIndex,
				'next' : lastIndex + 2
			}).removeClass(jQuery.galleryUtility.Options.startClass);
			jQuery.galleryUtility.gallery.filter('[index=' + (lastIndex) + ']')
					.after(jQueryclone);
			jQuery.galleryUtility.gallery = jQuery.galleryUtility.gallery
					.add('img[index=' + (lastIndex + 1) + ']');
			lastIndex++;
			currIndex++;
			gallerySize++;
		}
		jQuery.galleryUtility.gallery.filter('[index=' + lastIndex + ']').attr(
				'next', 0);
		jQuery.galleryUtility.gallery.filter('[index=0]').attr('prev', lastIndex);
		jQuery.galleryUtility.setCenter(jQuery.galleryUtility.gallery.filter(
				'.' + jQuery.galleryUtility.Options.startClass).show());
		jQuery.galleryUtility.setLeft(jQuery.galleryUtility.gallery
				.filter(
						'[index=' + jQuery.galleryUtility.centerImage.image
								.attr('prev') + ']').show());
		jQuery.galleryUtility.setRight(jQuery.galleryUtility.gallery
				.filter(
						'[index=' + jQuery.galleryUtility.centerImage.image
								.attr('next') + ']').show());
		jQuery.galleryUtility.setLeftStorage(jQuery.galleryUtility.gallery
				.filter('[index=' + jQuery.galleryUtility.leftImage.image
						.attr('prev') + ']'));
		jQuery.galleryUtility.setRightStorage(jQuery.galleryUtility.gallery
				.filter('[index=' + jQuery.galleryUtility.rightImage.image
						.attr('next') + ']'));
		/*jQuery.galleryUtility.leftImage.image.one('click',
				jQuery.galleryUtility.slideRight);
		jQuery.galleryUtility.rightImage.image.one('click',
				jQuery.galleryUtility.slideLeft);
		jQuery.galleryUtility.centerImage.image
				.one('click', jQuery.galleryUtility.zoomIn);*/
		jQuery(window)
				.resize(
						function() {
							jQuery.galleryUtility.definePositions();
							jQuery.galleryUtility
									.setCenter(jQuery.galleryUtility.centerImage.image);
							jQuery.galleryUtility
									.setLeft(jQuery.galleryUtility.leftImage.image);
							jQuery.galleryUtility
									.setRight(jQuery.galleryUtility.rightImage.image);
							jQuery.galleryUtility
									.setLeftStorage(jQuery.galleryUtility.leftImageStorage.image);
							jQuery.galleryUtility
									.setRightStorage(jQuery.galleryUtility.rightImageStorage.image);
						});
		return jQuery(this);
	};
	jQuery.galleryUtility.slideRight = function() {
		var liLeft = jQuery.galleryUtility.leftImage.left(
				jQuery.galleryUtility.leftImageStorage.image,
				jQuery.galleryUtility.leftImage.image);
		var riLeft = jQuery.galleryUtility.rightImage
				.left(jQuery.galleryUtility.leftImage.image);
		var risLeft = jQuery.galleryUtility.rightImageStorage
				.left(jQuery.galleryUtility.centerImage.image);
		if (jQuery.galleryUtility.leftImageStorage.image.attr('layout') === 'landscape') {
			
			jQuery.galleryUtility.leftImageStorage.image.animate( {
				/// 'top' : jQuery.galleryUtility.leftImage.Ltop+54,        ////    1111
				'top' : 230,
				'left' : liLeft,
				'height' : jQuery.galleryUtility.leftImage.Lheight,
				'width' : jQuery.galleryUtility.leftImage.Lwidth,
				'opacity' : 'show'
			}, jQuery.galleryUtility.Options.slideSpeed, 'linear', function() {
				jQuery(this).one('click', jQuery.galleryUtility.slideRight);
			});
		} else {
			jQuery.galleryUtility.leftImageStorage.image.animate( {
				'top' : jQuery.galleryUtility.leftImage.Ptop,
				'left' : liLeft,
				'height' : jQuery.galleryUtility.leftImage.Pheight,
				'width' : jQuery.galleryUtility.leftImage.Pwidth,
				'opacity' : 'show'
			}, jQuery.galleryUtility.Options.slideSpeed, 'linear', function() {
				// jQuery(this).one('click', jQuery.galleryUtility.slideRight);
			});
		}
		if (jQuery.galleryUtility.leftImage.image.attr('layout') === 'landscape') {
			//alert(jQuery.galleryUtility.leftImage.Ltop);
			jQuery.galleryUtility.leftImage.image.unbind().animate( {
				//'top' : jQuery.galleryUtility.centerImage.Ltop+59,   //////////Middle on Scrool   ... 111
				'top' : 210,
				'left' : jQuery.galleryUtility.centerImage.Lleft,
				'height' : jQuery.galleryUtility.centerImage.Lheight,
				'width' : jQuery.galleryUtility.centerImage.Lwidth
			}, jQuery.galleryUtility.Options.slideSpeed, 'linear', function() {
				jQuery(this).one('click', jQuery.galleryUtility.zoomIn);
			});
		} else {
			jQuery.galleryUtility.leftImage.image.unbind().animate( {
				'top' : jQuery.galleryUtility.centerImage.Ptop,
				'left' : jQuery.galleryUtility.centerImage.Pleft,
				'height' : jQuery.galleryUtility.centerImage.Pheight,
				'width' : jQuery.galleryUtility.centerImage.Pwidth
			}, jQuery.galleryUtility.Options.slideSpeed, 'linear', function() {
				jQuery(this).one('click', jQuery.galleryUtility.zoomIn);
			});
		}
		if (jQuery.galleryUtility.centerImage.image.attr('layout') === 'landscape') {
				
			jQuery.galleryUtility.centerImage.image.unbind().animate( {
				//'top' : jQuery.galleryUtility.rightImage.Ltop+54,    ////////////////Right 111
				'top' : 230,
				'left' : riLeft,
				'height' : jQuery.galleryUtility.rightImage.Lheight,
				'width' : jQuery.galleryUtility.rightImage.Lwidth
			}, jQuery.galleryUtility.Options.slideSpeed, 'linear', function() {
				// jQuery(this).one('click', jQuery.galleryUtility.slideLeft);
			});
		} else {
			jQuery.galleryUtility.centerImage.image.unbind().animate( {
				'top' : jQuery.galleryUtility.rightImage.Ptop,
				'left' : riLeft,
				'height' : jQuery.galleryUtility.rightImage.Pheight,
				'width' : jQuery.galleryUtility.rightImage.Pwidth
			}, jQuery.galleryUtility.Options.slideSpeed, 'linear', function() {
				//jQuery(this).one('click', jQuery.galleryUtility.slideLeft);
			});
		}
		if (jQuery.galleryUtility.rightImage.image.attr('layout') === 'landscape') {
			
			jQuery.galleryUtility.rightImage.image.unbind().animate( {
				//'top' : jQuery.galleryUtility.rightImageStorage.Ltop,
                'top' : jQuery.galleryUtility.rightImageStorage.Ltop,
				'left' : risLeft,
				'height' : jQuery.galleryUtility.rightImageStorage.Lheight,
				'width' : jQuery.galleryUtility.rightImageStorage.Lwidth,
				'opacity' : 'hide'
			}, jQuery.galleryUtility.Options.slideSpeed, 'linear');
		} else {
			jQuery.galleryUtility.rightImage.image.unbind().animate( {
				'top' : jQuery.galleryUtility.rightImageStorage.Ptop,
				'left' : risLeft,
				'height' : jQuery.galleryUtility.rightImageStorage.Pheight,
				'width' : jQuery.galleryUtility.rightImageStorage.Pwidth,
				'opacity' : 'hide'
			}, jQuery.galleryUtility.Options.slideSpeed, 'linear');
		}
		jQuery.galleryUtility.rightImageStorage.image = jQuery.galleryUtility.rightImage.image;
		jQuery.galleryUtility.rightImage.image = jQuery.galleryUtility.centerImage.image;
		jQuery.galleryUtility.centerImage.image = jQuery.galleryUtility.leftImage.image;
		jQuery.galleryUtility.leftImage.image = jQuery.galleryUtility.leftImageStorage.image;
		jQuery.galleryUtility.setLeftStorage(jQuery.galleryUtility.gallery
				.filter('[index=' + jQuery.galleryUtility.leftImageStorage.image
						.attr('prev') + ']'));
	};
	jQuery.galleryUtility.slideLeft = function() {
		var riLeft = jQuery.galleryUtility.rightImage
				.left(jQuery.galleryUtility.rightImage.image);
		var liLeft = jQuery.galleryUtility.leftImage.left(
				jQuery.galleryUtility.centerImage.image,
				jQuery.galleryUtility.rightImage.image);
		var lisLeft = jQuery.galleryUtility.leftImageStorage.left(
				jQuery.galleryUtility.leftImage.image,
				jQuery.galleryUtility.centerImage.image,
				jQuery.galleryUtility.rightImage.image);
		if (jQuery.galleryUtility.rightImageStorage.image.attr('layout') === 'landscape') {
			jQuery.galleryUtility.rightImageStorage.image.animate( {
				'top' : 230,
				'left' : riLeft,
				'height' : jQuery.galleryUtility.rightImage.Lheight,
				'width' : jQuery.galleryUtility.rightImage.Lwidth,
				'opacity' : 'show'
			}, jQuery.galleryUtility.Options.slideSpeed, 'linear', function() {
				jQuery(this).one('click', jQuery.galleryUtility.slideLeft);
			});
		} else {
			jQuery.galleryUtility.rightImageStorage.image.animate( {
				'top' : jQuery.galleryUtility.rightImage.Ptop,
				'left' : riLeft,
				'height' : jQuery.galleryUtility.rightImage.Pheight,
				'width' : jQuery.galleryUtility.rightImage.Pwidth,
				'opacity' : 'show'
			}, jQuery.galleryUtility.Options.slideSpeed, 'linear', function() {
				//jQuery(this).one('click', jQuery.galleryUtility.slideLeft);
			});
		}
		if (jQuery.galleryUtility.rightImage.image.attr('layout') === 'landscape') {
			jQuery.galleryUtility.rightImage.image.unbind().animate( {
				'top' : 210,
				'left' : jQuery.galleryUtility.centerImage.Lleft,
				'height' : jQuery.galleryUtility.centerImage.Lheight,
				'width' : jQuery.galleryUtility.centerImage.Lwidth
			}, jQuery.galleryUtility.Options.slideSpeed, 'linear', function() {
				jQuery(this).one('click', jQuery.galleryUtility.zoomIn);
			});
		} else {
			jQuery.galleryUtility.rightImage.image.unbind().animate( {
				'top' : jQuery.galleryUtility.centerImage.Ptop,
				'left' : jQuery.galleryUtility.centerImage.Pleft,
				'height' : jQuery.galleryUtility.centerImage.Pheight,
				'width' : jQuery.galleryUtility.centerImage.Pwidth
			}, jQuery.galleryUtility.Options.slideSpeed, 'linear', function() {
				jQuery(this).one('click', jQuery.galleryUtility.zoomIn);
			});
		}
		if (jQuery.galleryUtility.centerImage.image.attr('layout') === 'landscape') {
			jQuery.galleryUtility.centerImage.image.unbind().animate( {
				'top' : 230,
				'left' : liLeft,
				'height' : jQuery.galleryUtility.leftImage.Lheight,
				'width' : jQuery.galleryUtility.leftImage.Lwidth
			}, jQuery.galleryUtility.Options.slideSpeed, 'linear', function() {
				//jQuery(this).one('click', jQuery.galleryUtility.slideRight);
			});
		} else {
			jQuery.galleryUtility.centerImage.image.unbind().animate( {
				'top' : jQuery.galleryUtility.leftImage.Ptop,
				'left' : liLeft,
				'height' : jQuery.galleryUtility.leftImage.Pheight,
				'width' : jQuery.galleryUtility.leftImage.Pwidth
			}, jQuery.galleryUtility.Options.slideSpeed, 'linear', function() {
				//jQuery(this).one('click', jQuery.galleryUtility.slideRight);
			});
		}
		if (jQuery.galleryUtility.leftImage.image.attr('layout') === 'landscape') {
					
			jQuery.galleryUtility.leftImage.image.unbind().animate( {
				'top' : jQuery.galleryUtility.leftImageStorage.Ltop,
				'left' : lisLeft,
				'height' : jQuery.galleryUtility.leftImageStorage.Lheight,
				'width' : jQuery.galleryUtility.leftImageStorage.Lwidth,
				'opacity' : 'hide'
			}, jQuery.galleryUtility.Options.slideSpeed, 'linear');
		} else {
			jQuery.galleryUtility.leftImage.image.unbind().animate( {
				'top' : jQuery.galleryUtility.leftImageStorage.Ptop,
				'left' : lisLeft,
				'height' : jQuery.galleryUtility.leftImageStorage.Pheight,
				'width' : jQuery.galleryUtility.leftImageStorage.Pwidth,
				'opacity' : 'hide'
			}, jQuery.galleryUtility.Options.slideSpeed, 'linear');
		}
		jQuery.galleryUtility.leftImageStorage.image = jQuery.galleryUtility.leftImage.image;
		jQuery.galleryUtility.leftImage.image = jQuery.galleryUtility.centerImage.image;
		jQuery.galleryUtility.centerImage.image = jQuery.galleryUtility.rightImage.image;
		jQuery.galleryUtility.rightImage.image = jQuery.galleryUtility.rightImageStorage.image;
		jQuery.galleryUtility.setRightStorage(jQuery.galleryUtility.gallery
				.filter('[index=' + jQuery.galleryUtility.rightImageStorage.image
						.attr('next') + ']'));
	};
	jQuery.galleryUtility.zoomIn = function() {     ///////// This Function is use for Zoom 
		jQuery.galleryUtility.gallery.unbind();
		if (jQuery.galleryUtility.centerImage.image.attr('layout') === 'landscape') {
			jQuery.galleryUtility.centerImage.image
					.css('z-index', '99')
					.animate(
							{
								'top' : jQuery.galleryUtility.zoomImage.Ltop+59,
								'left' : jQuery.galleryUtility.zoomImage.Lleft,
								'height' : jQuery.galleryUtility.zoomImage.Lheight,
								'width' : jQuery.galleryUtility.zoomImage.Lwidth
							},
							jQuery.galleryUtility.Options.zoomSpeed,
							'linear',
							function() {
								jQuery.galleryUtility.centerImage.image.one('click',
										jQuery.galleryUtility.zoomOut);
								if (jQuery.galleryUtility.Options.useCaptions) {
									
									jQuery(
											'#' + jQuery.galleryUtility.Options.captionDownID)
											.css(
													{
														'height' : 0,
														'top' : jQuery.galleryUtility.zoomImage.Ltop
																+ parseInt(
																		jQuery.galleryUtility.centerImage.image
																				.css('borderTopWidth'),
																		10),
														'left' : jQuery.galleryUtility.zoomImage.Lleft
																+ (jQuery.galleryUtility.zoomImage.Lwidth - jQuery.galleryUtility.Options.captionDownWidth)
																+ parseInt(
																		jQuery.galleryUtility.centerImage.image
																				.css('borderLeftWidth'),
																		10),
														'z-index' : 1000,
														'position' : 'absolute'
													})
											.show()
											.animate(
													{
														'height' : jQuery.galleryUtility.Options.captionDownHeight
													},
													'fast',
													'linear',
													function() {
														jQuery(
																'#' + jQuery.galleryUtility.Options.captionDownID)
																.one(
																		'click',
																		jQuery.galleryUtility.LcaptionDown);
													});
								}
							});
		} else {
			jQuery.galleryUtility.centerImage.image
					.css('z-index', '99')
					.animate(
							{
								'top' : jQuery.galleryUtility.zoomImage.Ptop,
								'left' : jQuery.galleryUtility.zoomImage.Pleft,
								'height' : jQuery.galleryUtility.zoomImage.Pheight,
								'width' : jQuery.galleryUtility.zoomImage.Pwidth
							},
							jQuery.galleryUtility.Options.zoomSpeed,
							'linear',
							function() {
								jQuery.galleryUtility.centerImage.image.one('click',
										jQuery.galleryUtility.zoomOut);
								if (jQuery.galleryUtility.Options.useCaptions) {
									jQuery(
											'#' + jQuery.galleryUtility.Options.captionDownID)
											.css(
													{
														'height' : 0,
														'top' : jQuery.galleryUtility.zoomImage.Ptop
																+ parseInt(
																		jQuery.galleryUtility.centerImage.image
																				.css('borderTopWidth'),
																		10),
														'left' : jQuery.galleryUtility.zoomImage.Pleft
																+ (jQuery.galleryUtility.zoomImage.Pwidth - jQuery.galleryUtility.Options.captionDownWidth)
																+ parseInt(
																		jQuery.galleryUtility.centerImage.image
																				.css('borderLeftWidth'),
																		10),
														'z-index' : 100,
														'position' : 'absolute'
													})
											.show()
											.animate(
													{
														'height' : jQuery.galleryUtility.Options.captionDownHeight
													},
													'fast',
													'linear',
													function() {
														jQuery(
																'#' + jQuery.galleryUtility.Options.captionDownID)
																.one(
																		'click',
																		jQuery.galleryUtility.PcaptionDown);
													});
								}
							});
		}
	};
	jQuery.galleryUtility.LcaptionDown = function() {
		jQuery.galleryUtility.centerImage.image.unbind();
		jQuery.galleryUtility.Options.container.append('<span id="'
				+ jQuery.galleryUtility.Options.captionID
				+ '" style="'
				+ jQuery.galleryUtility.Options.captionStyle
				+ '" class="'
				+ jQuery.galleryUtility.Options.captionClass
				+ '">'
				+ jQuery.galleryUtility.centerImage.image
						.attr(jQuery.galleryUtility.Options.captionTextAttribute)
				+ '</span>');
		jQuery('#' + jQuery.galleryUtility.Options.captionID).css(
				{
					'top' : jQuery.galleryUtility.zoomImage.Ltop
							+ parseInt(jQuery.galleryUtility.centerImage.image
									.css('borderTopWidth'), 10),
					'left' : jQuery.galleryUtility.zoomImage.Lleft
							+ parseInt(jQuery.galleryUtility.centerImage.image
									.css('borderLeftWidth'), 10),
					'width' : jQuery.galleryUtility.zoomImage.Lwidth,
					'height' : 0,
					'position' : 'absolute',
					'z-index' : '100'
				}).animate(
				{
					'height' : Math.round(jQuery.galleryUtility.Options
							.captionHeight(jQuery.galleryUtility.zoomImage.Lheight))
				}, 'normal', 'linear');
		jQuery('#' + jQuery.galleryUtility.Options.captionDownID)
				.animate(
						{
							'height' : 0,
							'top' : jQuery.galleryUtility.zoomImage.Ltop
									+ (Math
											.round(jQuery.galleryUtility.Options
													.captionHeight(jQuery.galleryUtility.zoomImage.Lheight)))
									+ parseInt(
											jQuery.galleryUtility.centerImage.image
													.css('borderTopWidth'), 10)
						},
						'normal',
						'linear',
						function() {
							jQuery('#' + jQuery.galleryUtility.Options.captionDownID)
									.hide();
						});
		jQuery('#' + jQuery.galleryUtility.Options.captionUpID)
				.css(
						{
							'top' : jQuery.galleryUtility.zoomImage.Ltop
									+ jQuery.galleryUtility.Options.captionDownHeight
									+ parseInt(
											jQuery.galleryUtility.centerImage.image
													.css('borderTopWidth'), 10),
							'left' : jQuery.galleryUtility.zoomImage.Lleft
									+ (jQuery.galleryUtility.zoomImage.Lwidth - jQuery.galleryUtility.Options.captionUpWidth)
									+ parseInt(
											jQuery.galleryUtility.centerImage.image
													.css('borderLeftWidth'), 10),
							'height' : 0,
							'position' : 'absolute',
							'z-index' : '100'
						})
				.show()
				.animate(
						{
							'top' : jQuery.galleryUtility.zoomImage.Ltop
									+ (Math
											.round(jQuery.galleryUtility.Options
													.captionHeight(jQuery.galleryUtility.zoomImage.Lheight)))
									+ parseInt(
											jQuery.galleryUtility.centerImage.image
													.css('borderTopWidth'), 10),
							'height' : jQuery.galleryUtility.Options.captionUpHeight
						},
						'normal',
						'linear',
						function() {
							jQuery('#' + jQuery.galleryUtility.Options.captionUpID).one(
									'click', function() {
										jQuery.galleryUtility.LcaptionUp(false);
									});
							jQuery.galleryUtility.centerImage.image.one('click',
									function() {
										jQuery.galleryUtility.LcaptionUp(true);
									});
						});
	};
	jQuery.galleryUtility.PcaptionDown = function() {
		jQuery.galleryUtility.centerImage.image.unbind();
		jQuery.galleryUtility.Options.container.append('<span id="'
				+ jQuery.galleryUtility.Options.captionID
				+ '" style="'
				+ jQuery.galleryUtility.Options.captionStyle
				+ '" class="'
				+ jQuery.galleryUtility.Options.captionClass
				+ '">'
				+ jQuery.galleryUtility.centerImage.image
						.attr(jQuery.galleryUtility.Options.captionTextAttribute)
				+ '</span>');
		jQuery('#' + jQuery.galleryUtility.Options.captionID).css(
				{
					'top' : jQuery.galleryUtility.zoomImage.Ptop
							+ parseInt(jQuery.galleryUtility.centerImage.image
									.css('borderTopWidth'), 10),
					'left' : jQuery.galleryUtility.zoomImage.Pleft
							+ parseInt(jQuery.galleryUtility.centerImage.image
									.css('borderLeftWidth'), 10),
					'width' : jQuery.galleryUtility.zoomImage.Pwidth,
					'height' : 0,
					'position' : 'absolute',
					'z-index' : '100'
				}).animate(
				{
					'height' : Math.round(jQuery.galleryUtility.Options
							.captionHeight(jQuery.galleryUtility.zoomImage.Pheight))
				}, 'normal', 'linear');
		jQuery('#' + jQuery.galleryUtility.Options.captionDownID)
				.animate(
						{
							'height' : 0,
							'top' : jQuery.galleryUtility.zoomImage.Ptop
									+ (Math
											.round(jQuery.galleryUtility.Options
													.captionHeight(jQuery.galleryUtility.zoomImage.Pheight)))
									+ parseInt(
											jQuery.galleryUtility.centerImage.image
													.css('borderTopWidth'), 10)
						},
						'normal',
						'linear',
						function() {
							jQuery('#' + jQuery.galleryUtility.Options.captionDownID)
									.hide();
						});
		jQuery('#' + jQuery.galleryUtility.Options.captionUpID)
				.css(
						{
							'top' : jQuery.galleryUtility.zoomImage.Ptop
									+ jQuery.galleryUtility.Options.captionDownHeight
									+ parseInt(
											jQuery.galleryUtility.centerImage.image
													.css('borderTopWidth'), 10),
							'left' : jQuery.galleryUtility.zoomImage.Pleft
									+ (jQuery.galleryUtility.zoomImage.Pwidth - jQuery.galleryUtility.Options.captionUpWidth)
									+ parseInt(
											jQuery.galleryUtility.centerImage.image
													.css('borderLeftWidth'), 10),
							'height' : 0,
							'position' : 'absolute',
							'z-index' : '100'
						})
				.show()
				.animate(
						{
							'top' : jQuery.galleryUtility.zoomImage.Ptop
									+ (Math
											.round(jQuery.galleryUtility.Options
													.captionHeight(jQuery.galleryUtility.zoomImage.Pheight)))
									+ parseInt(
											jQuery.galleryUtility.centerImage.image
													.css('borderTopWidth'), 10),
							'height' : jQuery.galleryUtility.Options.captionUpHeight
						},
						'normal',
						'linear',
						function() {
							jQuery('#' + jQuery.galleryUtility.Options.captionUpID).one(
									'click', function() {
										jQuery.galleryUtility.PcaptionUp(false);
									});
							jQuery.galleryUtility.centerImage.image.one('click',
									function() {
										jQuery.galleryUtility.PcaptionUp(true);
									});
						});
	};
	jQuery.galleryUtility.LcaptionUp = function(unzoom) {
		jQuery('#' + jQuery.galleryUtility.Options.captionID).animate( {
			'height' : 0
		}, 'normal', 'linear', function() {
			jQuery('#' + jQuery.galleryUtility.Options.captionID).remove();
		});
		jQuery('#' + jQuery.galleryUtility.Options.captionUpID).animate(
				{
					'top' : jQuery.galleryUtility.zoomImage.Ltop
							+ jQuery.galleryUtility.Options.captionDownHeight
							+ parseInt(jQuery.galleryUtility.centerImage.image
									.css('borderTopWidth'), 10),
					'height' : 0
				}, 'normal', 'linear', function() {
					jQuery('#' + jQuery.galleryUtility.Options.captionUpID).hide();
				});
		jQuery('#' + jQuery.galleryUtility.Options.captionDownID).show().animate(
				{
					'height' : jQuery.galleryUtility.Options.captionDownHeight,
					'top' : jQuery.galleryUtility.zoomImage.Ltop
							+ parseInt(jQuery.galleryUtility.centerImage.image
									.css('borderTopWidth'), 10)
				},
				'normal',
				'linear',
				function() {
					if (unzoom) {
						jQuery('#' + jQuery.galleryUtility.Options.captionUpID).unbind();
						jQuery.galleryUtility.zoomOut();
					} else {
						jQuery('#' + jQuery.galleryUtility.Options.captionDownID).one(
								'click', jQuery.galleryUtility.LcaptionDown);
						jQuery.galleryUtility.centerImage.image.one('click',
								jQuery.galleryUtility.zoomOut);
					}
				});
	};
	jQuery.galleryUtility.PcaptionUp = function(unzoom) {
		jQuery('#' + jQuery.galleryUtility.Options.captionID).animate( {
			'height' : 0
		}, 'normal', 'linear', function() {
			jQuery('#' + jQuery.galleryUtility.Options.captionID).remove();
		});
		jQuery('#' + jQuery.galleryUtility.Options.captionUpID).animate(
				{
					'top' : jQuery.galleryUtility.zoomImage.Ptop
							+ jQuery.galleryUtility.Options.captionDownHeight
							+ parseInt(jQuery.galleryUtility.centerImage.image
									.css('borderTopWidth'), 10),
					'height' : 0
				}, 'normal', 'linear', function() {
					jQuery('#' + jQuery.galleryUtility.Options.captionUpID).hide();
				});
		jQuery('#' + jQuery.galleryUtility.Options.captionDownID).show().animate(
				{
					'height' : jQuery.galleryUtility.Options.captionDownHeight,
					'top' : jQuery.galleryUtility.zoomImage.Ptop
							+ parseInt(jQuery.galleryUtility.centerImage.image
									.css('borderTopWidth'), 10)
				},
				'normal',
				'linear',
				function() {
					if (unzoom) {
						jQuery('#' + jQuery.galleryUtility.Options.captionUpID).unbind();
						jQuery.galleryUtility.zoomOut();
					} else {
						jQuery('#' + jQuery.galleryUtility.Options.captionDownID).one(
								'click', jQuery.galleryUtility.PcaptionDown);
						jQuery.galleryUtility.centerImage.image.one('click',
								jQuery.galleryUtility.zoomOut);
					}
				});
	};
	jQuery.galleryUtility.zoomOut = function() {
		if (jQuery.galleryUtility.Options.useCaptions) {
			jQuery('#' + jQuery.galleryUtility.Options.captionDownID).animate( {
				'height' : 0
			}, 50, 'linear', jQuery.galleryUtility.zoomOutBody).unbind();
		} else {
			jQuery.galleryUtility.zoomOutBody();
		}
	};
	jQuery.galleryUtility.zoomOutBody = function() {
		if (jQuery.galleryUtility.centerImage.image.attr('layout') === 'landscape') {
			jQuery.galleryUtility.centerImage.image.animate( {
				'top' : jQuery.galleryUtility.centerImage.Ltop,
				'left' : jQuery.galleryUtility.centerImage.Lleft,
				'height' : jQuery.galleryUtility.centerImage.Lheight,
				'width' : jQuery.galleryUtility.centerImage.Lwidth
			}, jQuery.galleryUtility.Options.zoomSpeed, 'linear', function() {
				/*jQuery(this).css('z-index', '0').one('click',
						jQuery.galleryUtility.zoomIn);
				jQuery.galleryUtility.leftImage.image.one('click',
						jQuery.galleryUtility.slideRight);
				jQuery.galleryUtility.rightImage.image.one('click',
						jQuery.galleryUtility.slideLeft);*/
			});
		} else {
			jQuery.galleryUtility.centerImage.image.animate( {
				'top' : jQuery.galleryUtility.centerImage.Ptop,
				'left' : jQuery.galleryUtility.centerImage.Pleft,
				'height' : jQuery.galleryUtility.centerImage.Pheight,
				'width' : jQuery.galleryUtility.centerImage.Pwidth
			}, jQuery.galleryUtility.Options.zoomSpeed, 'linear', function() {
				/*jQuery(this).css('z-index', '0').one('click',
						jQuery.galleryUtility.zoomIn);
				jQuery.galleryUtility.leftImage.image.one('click',
						jQuery.galleryUtility.slideRight);
				jQuery.galleryUtility.rightImage.image.one('click',
						jQuery.galleryUtility.slideLeft);*/
			});
		}
	};
	jQuery.galleryUtility.setRightStorage = function(image) {
		jQuery.galleryUtility.rightImageStorage.image = image;
		if (jQuery.galleryUtility.rightImageStorage.image.attr('layout') === 'landscape') {
			jQuery.galleryUtility.rightImageStorage.image.hide().css( {
				'top' : jQuery.galleryUtility.rightImageStorage.Ltop,
				'height' : jQuery.galleryUtility.rightImageStorage.Lheight,
				'width' : jQuery.galleryUtility.rightImageStorage.Lwidth
			});
		} else {
			jQuery.galleryUtility.rightImageStorage.image.hide().css( {
				'top' : jQuery.galleryUtility.rightImageStorage.Ptop,
				'height' : jQuery.galleryUtility.rightImageStorage.Pheight,
				'width' : jQuery.galleryUtility.rightImageStorage.Pwidth
			});
		}
		jQuery.galleryUtility.rightImageStorage.image.css('left',
				jQuery.galleryUtility.rightImageStorage
						.left(jQuery.galleryUtility.rightImage.image));
	};
	jQuery.galleryUtility.setLeftStorage = function(image) {
		jQuery.galleryUtility.leftImageStorage.image = image;
		if (jQuery.galleryUtility.leftImageStorage.image.attr('layout') === 'landscape') {

			jQuery.galleryUtility.leftImageStorage.image.hide().css( {
				'top' : jQuery.galleryUtility.leftImageStorage.Ltop,  
				'height' : jQuery.galleryUtility.leftImageStorage.Lheight,
				'width' : jQuery.galleryUtility.leftImageStorage.Lwidth
			});
		} else {
			jQuery.galleryUtility.leftImageStorage.image.hide().css( {
				'top' : jQuery.galleryUtility.leftImageStorage.Ptop,
				'height' : jQuery.galleryUtility.leftImageStorage.Pheight,
				'width' : jQuery.galleryUtility.leftImageStorage.Pwidth
			});
		}
		jQuery.galleryUtility.leftImageStorage.image.css('left',
				jQuery.galleryUtility.leftImageStorage.left(
						jQuery.galleryUtility.leftImageStorage.image,
						jQuery.galleryUtility.leftImage.image,
						jQuery.galleryUtility.centerImage.image));
	};
	jQuery.galleryUtility.setCenter = function(image) {
		jQuery.galleryUtility.centerImage.image = image;
		if (jQuery.galleryUtility.centerImage.image.attr('layout') === 'landscape') {
			jQuery.galleryUtility.centerImage.image.css( {
				//'top' : jQuery.galleryUtility.rightImage.Ltop+34,   ///////222    Use For Middle
				'top' : 210,   
				'left' : jQuery.galleryUtility.centerImage.Lleft,
				'height' : jQuery.galleryUtility.centerImage.Lheight,
				'width' : jQuery.galleryUtility.centerImage.Lwidth
			});
		} else {
			jQuery.galleryUtility.centerImage.image.css( {
				'top' : jQuery.galleryUtility.centerImage.Ptop,
				'left' : jQuery.galleryUtility.centerImage.Pleft,
				'height' : jQuery.galleryUtility.centerImage.Pheight,
				'width' : jQuery.galleryUtility.centerImage.Pwidth
			});
		}
	};
	jQuery.galleryUtility.setRight = function(image) {
		jQuery.galleryUtility.rightImage.image = image;
		if (jQuery.galleryUtility.rightImage.image.attr('layout') === 'landscape') {
			
			jQuery.galleryUtility.rightImage.image.css( {
				//'top' : jQuery.galleryUtility.rightImage.Ltop+54,    //////222
				'top' : 230,    
				'height' : jQuery.galleryUtility.rightImage.Lheight,
				'width' : jQuery.galleryUtility.rightImage.Lwidth
			});
		} else {
			jQuery.galleryUtility.rightImage.image.css( {
				'top' : jQuery.galleryUtility.rightImage.Ptop,
				'height' : jQuery.galleryUtility.rightImage.Pheight,
				'width' : jQuery.galleryUtility.rightImage.Pwidth
			});
		}
		jQuery.galleryUtility.rightImage.image.css('left',
				jQuery.galleryUtility.rightImage
						.left(jQuery.galleryUtility.centerImage.image));
	};
	jQuery.galleryUtility.setLeft = function(image) {
		jQuery.galleryUtility.leftImage.image = image;
		if (jQuery.galleryUtility.leftImage.image.attr('layout') === 'landscape') {
			jQuery.galleryUtility.leftImage.image.css( {
				//'top' : jQuery.galleryUtility.leftImage.Ltop +54,   //////222
				'top' : 230,   
				'height' : jQuery.galleryUtility.leftImage.Lheight,
				'width' : jQuery.galleryUtility.leftImage.Lwidth
			});
		} else {
			jQuery.galleryUtility.leftImage.image.css( {
				'top' : jQuery.galleryUtility.leftImage.Ptop,
				'height' : jQuery.galleryUtility.leftImage.Pheight,
				'width' : jQuery.galleryUtility.leftImage.Pwidth
			});
		}
		jQuery.galleryUtility.leftImage.image.css('left', jQuery.galleryUtility.leftImage
				.left(jQuery.galleryUtility.leftImage.image,
						jQuery.galleryUtility.centerImage.image));
	};
	jQuery.galleryUtility.definePositions = function() {
		var container = jQuery.galleryUtility.Options.container;
		//if (container[0] && container[0].tagName == 'BODY') 
		{
			container = jQuery(window);
		}
		var Gheight = container.height();
		var Gwidth = container.width();
		jQuery.galleryUtility.centerImage.Lheight = Math
				.round(jQuery.galleryUtility.Options.Lheight);
		jQuery.galleryUtility.centerImage.Lwidth = Math
				.round(jQuery.galleryUtility.Options.Lwidth);
		jQuery.galleryUtility.centerImage.Ltop = Math.round(Gheight / 2)
				- (jQuery.galleryUtility.centerImage.Lheight / 2);
		jQuery.galleryUtility.centerImage.Lleft = Math.round(Gwidth / 2)
				- (jQuery.galleryUtility.centerImage.Lwidth / 2);
		jQuery.galleryUtility.centerImage.Pheight = Math
				.round(jQuery.galleryUtility.Options.Pheight);
		jQuery.galleryUtility.centerImage.Pwidth = Math
				.round(jQuery.galleryUtility.Options.Pwidth);
		jQuery.galleryUtility.centerImage.Ptop = Math.round((Gheight / 2)
				- (jQuery.galleryUtility.centerImage.Pheight / 2));
		jQuery.galleryUtility.centerImage.Pleft = Math.round((Gwidth / 2)
				- (jQuery.galleryUtility.centerImage.Pwidth / 2));
		jQuery.galleryUtility.zoomImage.Lheight = Math
				.round(jQuery.galleryUtility.Options
						.Lzoom(jQuery.galleryUtility.centerImage.Lheight));
		jQuery.galleryUtility.zoomImage.Lwidth = Math.round(jQuery.galleryUtility.Options
				.Lzoom(jQuery.galleryUtility.centerImage.Lwidth));
		jQuery.galleryUtility.zoomImage.Ltop = Math.round((Gheight / 2)
				- (jQuery.galleryUtility.zoomImage.Lheight / 2));
		jQuery.galleryUtility.zoomImage.Lleft = Math.round((Gwidth / 2)
				- (jQuery.galleryUtility.zoomImage.Lwidth / 2));
		jQuery.galleryUtility.zoomImage.Pheight = Math
				.round(jQuery.galleryUtility.Options
						.Pzoom(jQuery.galleryUtility.centerImage.Pheight));
		jQuery.galleryUtility.zoomImage.Pwidth = Math.round(jQuery.galleryUtility.Options
				.Pzoom(jQuery.galleryUtility.centerImage.Pwidth));
		jQuery.galleryUtility.zoomImage.Ptop = Math.round((Gheight / 2)
				- (jQuery.galleryUtility.zoomImage.Pheight / 2));
		jQuery.galleryUtility.zoomImage.Pleft = Math.round((Gwidth / 2)
				- (jQuery.galleryUtility.zoomImage.Pwidth / 2));
		jQuery.galleryUtility.leftImage.Lheight = Math
				.round(jQuery.galleryUtility.Options
						.Lshrink(jQuery.galleryUtility.centerImage.Lheight));
		jQuery.galleryUtility.leftImage.Lwidth = Math.round(jQuery.galleryUtility.Options
				.Lshrink(jQuery.galleryUtility.centerImage.Lwidth));
		jQuery.galleryUtility.leftImage.Ltop = Math
				.round(jQuery.galleryUtility.centerImage.Ltop
						+ ((jQuery.galleryUtility.centerImage.Lheight - jQuery.galleryUtility.leftImage.Lheight) / 2));
		jQuery.galleryUtility.leftImage.left = function(left, center) {
			if (center.attr('layout') === 'landscape') {
				if (left.attr('layout') === 'landscape') {
					return Math
							.round(jQuery.galleryUtility.centerImage.Lleft
									- (jQuery.galleryUtility.leftImage.Lwidth + jQuery.galleryUtility.Options.gutterWidth));
				} else {
					return Math
							.round(jQuery.galleryUtility.centerImage.Lleft
									- (jQuery.galleryUtility.leftImage.Pwidth + jQuery.galleryUtility.Options.gutterWidth));
				}
			} else {
				if (left.attr('layout') === 'landscape') {
					return Math
							.round(jQuery.galleryUtility.centerImage.Pleft
									- (jQuery.galleryUtility.leftImage.Lwidth + jQuery.galleryUtility.Options.gutterWidth));
				} else {
					return Math
							.round(jQuery.galleryUtility.centerImage.Pleft
									- (jQuery.galleryUtility.leftImage.Pwidth + jQuery.galleryUtility.Options.gutterWidth));
				}
			}
		};
		jQuery.galleryUtility.leftImage.Pheight = Math
				.round(jQuery.galleryUtility.Options
						.Pshrink(jQuery.galleryUtility.centerImage.Pheight));
		jQuery.galleryUtility.leftImage.Pwidth = Math.round(jQuery.galleryUtility.Options
				.Pshrink(jQuery.galleryUtility.centerImage.Pwidth));
		jQuery.galleryUtility.leftImage.Ptop = Math
				.round(jQuery.galleryUtility.centerImage.Ptop
						+ ((jQuery.galleryUtility.centerImage.Pheight - jQuery.galleryUtility.leftImage.Pheight) / 2));
		jQuery.galleryUtility.rightImage.Lheight = Math
				.round(jQuery.galleryUtility.Options
						.Lshrink(jQuery.galleryUtility.centerImage.Lheight));
		jQuery.galleryUtility.rightImage.Lwidth = Math
				.round(jQuery.galleryUtility.Options
						.Lshrink(jQuery.galleryUtility.centerImage.Lwidth));
		jQuery.galleryUtility.rightImage.Ltop = Math
				.round(jQuery.galleryUtility.centerImage.Ltop
						+ ((jQuery.galleryUtility.centerImage.Lheight - jQuery.galleryUtility.rightImage.Lheight) / 2));
		jQuery.galleryUtility.rightImage.left = function(center) {
			if (center.attr('layout') === 'landscape') {
				return Math
						.round(jQuery.galleryUtility.centerImage.Lleft
								+ (jQuery.galleryUtility.centerImage.Lwidth + jQuery.galleryUtility.Options.gutterWidth));
			} else {
				return Math
						.round(jQuery.galleryUtility.centerImage.Pleft
								+ (jQuery.galleryUtility.centerImage.Pwidth + jQuery.galleryUtility.Options.gutterWidth));
			}
		};
		jQuery.galleryUtility.rightImage.Pheight = Math
				.round(jQuery.galleryUtility.Options
						.Pshrink(jQuery.galleryUtility.centerImage.Pheight));
		jQuery.galleryUtility.rightImage.Pwidth = Math
				.round(jQuery.galleryUtility.Options
						.Pshrink(jQuery.galleryUtility.centerImage.Pwidth));
		jQuery.galleryUtility.rightImage.Ptop = Math
				.round(jQuery.galleryUtility.centerImage.Ptop
						+ ((jQuery.galleryUtility.centerImage.Pheight - jQuery.galleryUtility.leftImage.Pheight) / 2));
		jQuery.galleryUtility.leftImageStorage.Lheight = Math
				.round(jQuery.galleryUtility.Options
						.Lshrink(jQuery.galleryUtility.leftImage.Lheight));
		jQuery.galleryUtility.leftImageStorage.Lwidth = Math
				.round(jQuery.galleryUtility.Options
						.Lshrink(jQuery.galleryUtility.leftImage.Lwidth));
		jQuery.galleryUtility.leftImageStorage.Ltop = Math
				.round(jQuery.galleryUtility.leftImage.Ltop
						+ ((jQuery.galleryUtility.leftImage.Lheight - jQuery.galleryUtility.leftImageStorage.Lheight) / 2));
		jQuery.galleryUtility.leftImageStorage.left = function(leftStorage, left,
				center) {
			if (leftStorage.attr('layout') === 'landscape') {
				return Math
						.round(jQuery.galleryUtility.leftImage.left(left, center)
								- (jQuery.galleryUtility.leftImageStorage.Lwidth + jQuery.galleryUtility.Options.gutterWidth));
			} else {
				return Math
						.round(jQuery.galleryUtility.leftImage.left(left, center)
								- (jQuery.galleryUtility.leftImageStorage.Pwidth + jQuery.galleryUtility.Options.gutterWidth));
			}
		};
		jQuery.galleryUtility.leftImageStorage.Pheight = Math
				.round(jQuery.galleryUtility.Options
						.Pshrink(jQuery.galleryUtility.leftImage.Pheight));
		jQuery.galleryUtility.leftImageStorage.Pwidth = Math
				.round(jQuery.galleryUtility.Options
						.Pshrink(jQuery.galleryUtility.leftImage.Pwidth));
		jQuery.galleryUtility.leftImageStorage.Ptop = Math
				.round(jQuery.galleryUtility.leftImage.Ptop
						+ ((jQuery.galleryUtility.leftImage.Pheight - jQuery.galleryUtility.leftImageStorage.Pheight) / 2));
		jQuery.galleryUtility.rightImageStorage.Lheight = Math
				.round(jQuery.galleryUtility.Options
						.Lshrink(jQuery.galleryUtility.rightImage.Lheight));
		jQuery.galleryUtility.rightImageStorage.Lwidth = Math
				.round(jQuery.galleryUtility.Options
						.Lshrink(jQuery.galleryUtility.rightImage.Lwidth));
		jQuery.galleryUtility.rightImageStorage.Ltop = Math
				.round(jQuery.galleryUtility.rightImage.Ltop
						+ ((jQuery.galleryUtility.rightImage.Lheight - jQuery.galleryUtility.rightImageStorage.Lheight) / 2));
		jQuery.galleryUtility.rightImageStorage.left = function(right) {
			if (right.attr('layout') === 'landscape') {
				return Math
						.round(jQuery.galleryUtility.rightImage.left(right)
								+ (jQuery.galleryUtility.rightImage.Lwidth + jQuery.galleryUtility.Options.gutterWidth));
			} else {
				return Math
						.round(jQuery.galleryUtility.rightImage.left(right)
								+ (jQuery.galleryUtility.rightImage.Pwidth + jQuery.galleryUtility.Options.gutterWidth));
			}
		};
		jQuery.galleryUtility.rightImageStorage.Pheight = Math
				.round(jQuery.galleryUtility.Options
						.Pshrink(jQuery.galleryUtility.rightImage.Pheight));
		jQuery.galleryUtility.rightImageStorage.Pwidth = Math
				.round(jQuery.galleryUtility.Options
						.Pshrink(jQuery.galleryUtility.rightImage.Pwidth));
		jQuery.galleryUtility.rightImageStorage.Ptop = Math
				.round(jQuery.galleryUtility.rightImage.Ptop
						+ ((jQuery.galleryUtility.rightImage.Pheight - jQuery.galleryUtility.rightImageStorage.Pheight) / 2));
	};
})(jQuery);