/*
*       Developed by Justin Mead
*       ©2009 MeadMiracle
*		www.meadmiracle.com / meadmiracle@gmail.com
*		MultiImages Mod: ©2010 www.expandi.net
*       Version 1.0
*       Testing: IE7/Windows XP
*                Firefox/Windows XP
*       Licensed under the Creative Commons GPL http://creativecommons.org/licenses/GPL/2.0/
*
*       OPTIONS LISTING:
*           *Lheight, Lwidth            - the height and width to use for the center image (landscape)
*           *Lshrink                    - the function to use when shrinking an image to a smaller size.  must take in and return an integer value. (landscape)
*           *Lzoom                      - the function to use when enlarging an image for the zoom view.  must take in and return an integer value. (landscape)
*           *Pheight, Pwidth            - the height and width to use for the center image (portrait)
*           *Pshrink                    - the function to use when shrinking an image to a smaller size.  must take in and return an integer value. (portrait)
*           *Pzoom                      - the function to use when enlarging an image for the zoom view.  must take in and return an integer value. (portrait)
*           *defaultLayout              - the layout attribute to apply when the image has no layout attribute
*           *startClass                 - the class label of the image to place in the center slot at the start of the gallery
*           *slideSpeed                 - the animation speed of sliding. use jQuery animation speed values
*           *zoomSpeed                  - the animation speed of zooming. use jQuery animation speed values
*           *gutterWidth                - the horizontal distance between each of the images. use a pixel value
*           *captionUpPath              - the path of the image to use for the "caption up" button
*           *captionUpWidth             - the pixel width of the "caption up" image
*           *captionUpHeight            - the pixel height of the "caption up" image
*           *captionUpID                - the ID attribute to use for the "caption up" image
*           *captionDownPath            - the path of the image to use for the "caption down" button
*           *captionDownWidth           - the pixel width of the "caption down" image
*           *captionDownHeight          - the pixel height of the "caption down" image
*           *captionDownID              - the ID attribute to use for the "caption down" image
*           *captionHeight              - the function to use to determine the height of the caption. takes in an integer value (usually the height of the image to caption)
                                          and returns an integer value
*           *captionStyle               - the CSS style value to apply to the captions
*           *captionClass               - the CSS class to apply to the captions
*           *captionID                  - the ID attribute to apply to the currently active caption
*           *captionTextAttribute       - the attribute containing the text to use in captions
*           *useCaptions                - allow captions to be shown
*           *imageNumSide				- 
*           *x_add						- 
*           *y_add						- 
*           *x2_add						- 
*           *y2_add						- 
*
*       All options have default values, and as such, are optional.  Check the 'options' JSON object below to see the defaults.
*/

(function($) {
    $.galleryUtility = {};
    $.galleryUtility.zoomImage = {};
    $.galleryUtility.gallery = {};
    $.galleryUtility.idxImage = Array;
	
    $.galleryUtility.Options = {
        Lheight: 300,
        Lwidth: 400,
        Lshrink:
                        function(dimension) {
                            return dimension * 0.60;
                        },
        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',
// 			defaultLayout: 'portrait',
        startClass: 'start',
        slideSpeed: 'normal',
        zoomSpeed: 'fast',
        gutterWidth: 10,
        captionUpPath: 'js/captionUpArrow.png',
        captionUpWidth: 24,
        captionUpHeight: 17,
        captionUpID: 'captionArrowUp',
        captionDownPath: 'js/captionDownArrow.png',
        captionDownWidth: 24,
        captionDownHeight: 17,
        captionDownID: 'captionArrowDown',
        captionHeight:
                        function(zoomHeight) {
                            return zoomHeight * 0.1;
                        },
        captionStyle: 'background-color:white; font-weight:bold; color:black; opacity: 0.6; filter: alpha(opacity = 60); font-size: 16px; text-align:center;',
        captionClass: 'captionBox',
        captionID: 'activeCaption',
        captionTextAttribute: 'caption',
        useCaptions: true,
		imageNumSide: 8,
		y_add: 0,
		x_add: 0,
		y2_add: 0,
		x2_add: 0,
		y3_add: 0,
		x3_add: 0,
		overlayBgColor: '#000',
		overlayOpacity: 0.8
   };

    $.fn.slidingGallery = function(options) {
		//alert('js');
		//Init image array
        var currIndex = 0;
		for (currIndex=-$.galleryUtility.Options.imageNumSide;currIndex<=$.galleryUtility.Options.imageNumSide;currIndex++){
			$.galleryUtility.idxImage[currIndex]={};
		}
				
        //global settings
        $.extend($.galleryUtility.Options, options);
        $.galleryUtility.gallery = $(this).css('cursor', 'pointer');
        
		//Set start posistion
        $.galleryUtility.defineIdxPositions($.galleryUtility.Options.imageNumSide,$.galleryUtility.Options.x_add,$.galleryUtility.Options.y_add,$.galleryUtility.Options.x2_add,$.galleryUtility.Options.y2_add,$.galleryUtility.Options.x3_add,$.galleryUtility.Options.y3_add);
				//$.galleryUtility.debugIdxPositions($.galleryUtility.Options.imageNumSide);
		
        if ($.galleryUtility.Options.useCaptions) {
            $('body').append('<img src="' + $.galleryUtility.Options.captionUpPath + '" style="width: ' + $.galleryUtility.Options.captionUpWidth + '; display: none;"' + 'id="' + $.galleryUtility.Options.captionUpID + '" />').append('<img src="' + $.galleryUtility.Options.captionDownPath + '" style="width: ' + $.galleryUtility.Options.captionDownWidth + '; display: none;"' + 'id="' + $.galleryUtility.Options.captionDownID + '" />');
            $('#' + $.galleryUtility.Options.captionUpID + ',#' + $.galleryUtility.Options.captionDownID).css('cursor', 'help');
        }

        // eliminate overflow
        // $('body').css('overflow', 'hidden');

        //setup existing images
        var lastIndex = 0;
        var gallerySize = $.galleryUtility.gallery.each(function(i) {
            $(this).attr({
                'prev_20': (i - 20),
                'prev_19': (i - 19),
                'prev_18': (i - 18),
                'prev_17': (i - 17),
                'prev_16': (i - 16),
                'prev_15': (i - 15),
                'prev_14': (i - 14),
                'prev_13': (i - 13),
                'prev_12': (i - 12),
                'prev_11': (i - 11),
                'prev_10': (i - 10),
                'prev_9': (i - 9),
                'prev_8': (i - 8),
                'prev_7': (i - 7),
                'prev_6': (i - 6),
                'prev_5': (i - 5),
                'prev_4': (i - 4),
                'prev_3': (i - 3),
                'prev_2': (i - 2),
                'prev_1': (i - 1),
                'index': i,
                'next_1': (i + 1),
                'next_2': (i + 2),
                'next_3': (i + 3),
                'next_4': (i + 4),
                'next_5': (i + 5),
                'next_6': (i + 6),
                'next_7': (i + 7),
                'next_8': (i + 8),
                'next_9': (i + 9),
                'next_10': (i + 10),
                'next_11': (i + 11),
                'next_12': (i + 12),
                'next_13': (i + 13),
                'next_14': (i + 14),
                'next_15': (i + 15),
                'next_16': (i + 16),
                'next_17': (i + 17),
                'next_18': (i + 18),
                'next_19': (i + 19),
                'next_20': (i + 20)
            }).css('position', 'absolute');
            $(this).css('top', $("#showroom").offset().top);
            
            if (($(this).attr('layout') !== 'portrait') && ($(this).attr('layout') !== 'landscape')) {
                	$(this).attr('layout', $.galleryUtility.Options.defaultLayout);
            	}
            lastIndex = i;
        }).hide().size();
        
		//
		// Bind Image
		//
		var currIndex = 0;
		for (currIndex = 1; currIndex < 21; currIndex++) {
			$.galleryUtility.gallery.filter('[index=' + (lastIndex-currIndex) + ']').attr('next_'+currIndex, 0);
			$.galleryUtility.gallery.filter('[index=0]').attr('prev_'+currIndex, lastIndex-currIndex);
		}
		
		//
		// Set Images
		//
		$.galleryUtility.setIdxImage($.galleryUtility.gallery.filter('.' + $.galleryUtility.Options.startClass).show(),0);
		var currIndex = 0;
		for (currIndex=1;currIndex<$.galleryUtility.Options.imageNumSide;currIndex++){
			$.galleryUtility.setIdxImage($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.idxImage[0].image.attr('next_'+currIndex) + ']').show(),currIndex);
			$.galleryUtility.setIdxImage($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.idxImage[0].image.attr('prev_'+currIndex) + ']').show(),-currIndex);
		}
		$.galleryUtility.setIdxImage($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.idxImage[0].image.attr('next_'+currIndex) + ']').hide(),$.galleryUtility.Options.imageNumSide);
		$.galleryUtility.setIdxImage($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.idxImage[0].image.attr('prev_'+currIndex) + ']').hide(),-$.galleryUtility.Options.imageNumSide);

    //
		// bind events
		//
    $.galleryUtility.idxImage[0].image.one('click', $.galleryUtility.zoomIn);
		for (currIndex=1;currIndex<$.galleryUtility.Options.imageNumSide;currIndex++){
			$.galleryUtility.idxImage[currIndex].image.one('click', $.galleryUtility.slideLeft);
			$.galleryUtility.idxImage[-currIndex].image.one('click', $.galleryUtility.slideRight);
			
		}
		
		//
		// Resize event
		//
/*		
		$(window).resize(function() {
			$.galleryUtility.defineIdxPositions($.galleryUtility.Options.imageNumSide,$.galleryUtility.Options.x_add,$.galleryUtility.Options.y_add,$.galleryUtility.Options.x2_add,$.galleryUtility.Options.y2_add,$.galleryUtility.Options.x3_add,$.galleryUtility.Options.y3_add);
			var currIndex=0;
			for (currIndex = -$.galleryUtility.Options.imageNumSide; currIndex <= $.galleryUtility.Options.imageNumSide; currIndex++) {
				$.galleryUtility.setIdxImage($.galleryUtility.idxImage[currIndex].image,currIndex);
			}
			});
*/
        return $(this);
    };

//-------------------------------------------------------------------------------
// zoomIn 
//-------------------------------------------------------------------------------
    $.galleryUtility.zoomIn = function() {
	$('body').append('<div id="jquery-overlay"></div>');	

	var arrPageSizes = ___getPageSize();
	
	// alert(arrPageSizes[0]+' '+arrPageSizes[1]+' '+$.galleryUtility.Options.overlayBgColor+' '+$.galleryUtility.Options.overlayOpacity);
	// Style overlay and show it
	$('#jquery-overlay').css({
		backgroundColor:	$.galleryUtility.Options.overlayBgColor,
		opacity:			$.galleryUtility.Options.overlayOpacity,
		width:				arrPageSizes[0],
		height:				arrPageSizes[1],
		top: "0px",
		left: "0px",
		position: "absolute",
		"z-index": '98'		
	}).fadeIn("slow");
	$('#jquery-overlay').one('click', $.galleryUtility.zoomOut);
	
        $.galleryUtility.gallery.unbind();
        $.galleryUtility.idxImage[-1].image.add($.galleryUtility.idxImage[1].image).css('cursor', 'auto');
        if ($.galleryUtility.idxImage[0].image.attr('layout') === 'landscape') {
            $.galleryUtility.idxImage[0].image.css('z-index', '99').animate({
                'top': $.galleryUtility.zoomImage.Ltop,
                'left': $.galleryUtility.zoomImage.Lleft,
                'height': $.galleryUtility.zoomImage.Lheight,
                'width': $.galleryUtility.zoomImage.Lwidth
            },
            $.galleryUtility.Options.zoomSpeed, 'linear', function() {
                $.galleryUtility.idxImage[0].image.one('click', $.galleryUtility.zoomOut);
                if ($.galleryUtility.Options.useCaptions) {
                    $('#' + $.galleryUtility.Options.captionDownID).css({
                        'height': 0,
                        'top': $.galleryUtility.zoomImage.Ltop + parseInt($.galleryUtility.idxImage[0].image.css('borderTopWidth'), 10),
                        'left': $.galleryUtility.zoomImage.Lleft + ($.galleryUtility.zoomImage.Lwidth - $.galleryUtility.Options.captionDownWidth) + parseInt($.galleryUtility.idxImage[0].image.css('borderLeftWidth'), 10),
                        'z-index': 100,
                        'position': 'absolute'
                    }).show().animate({ 'height': $.galleryUtility.Options.captionDownHeight }, 'fast', 'linear', function() {
                        $('#' + $.galleryUtility.Options.captionDownID).one('click', $.galleryUtility.LcaptionDown);
                    });
                }
            });
        } else {
            $.galleryUtility.idxImage[0].image.css('z-index', '99').animate({
                'top': $.galleryUtility.zoomImage.Ptop,
                'left': $.galleryUtility.zoomImage.Pleft,
                'height': $.galleryUtility.zoomImage.Pheight,
                'width': $.galleryUtility.zoomImage.Pwidth
            },
            $.galleryUtility.Options.zoomSpeed, 'linear', function() {
                $.galleryUtility.idxImage[0].image.one('click', $.galleryUtility.zoomOut);
                if ($.galleryUtility.Options.useCaptions) {
                    $('#' + $.galleryUtility.Options.captionDownID).css({
                        'height': 0,
                        'top': $.galleryUtility.zoomImage.Ptop + parseInt($.galleryUtility.idxImage[0].image.css('borderTopWidth'), 10),
                        'left': $.galleryUtility.zoomImage.Pleft + ($.galleryUtility.zoomImage.Pwidth - $.galleryUtility.Options.captionDownWidth) + parseInt($.galleryUtility.idxImage[0].image.css('borderLeftWidth'), 10),
                        'z-index': 100,
                        'position': 'absolute'
                    }).show().animate({ 'height': $.galleryUtility.Options.captionDownHeight }, 'fast', 'linear', function() {
                        $('#' + $.galleryUtility.Options.captionDownID).one('click', $.galleryUtility.PcaptionDown);
                    });
                }
            });
        }
    };
	
//-------------------------------------------------------------------------------
// zoomOut 
//-------------------------------------------------------------------------------
$.galleryUtility.zoomOut = function() {
	$('#jquery-overlay').fadeOut("fast", function() { $('#jquery-overlay').remove();});
        if ($.galleryUtility.Options.useCaptions) {
            $('#' + $.galleryUtility.Options.captionDownID).animate({ 'height': 0 }, 50, 'linear', $.galleryUtility.zoomOutBody).unbind();
        } else {
            $.galleryUtility.zoomOutBody();
        }
    };

//-------------------------------------------------------------------------------
// zoomOut 
//-------------------------------------------------------------------------------
$.galleryUtility.zoomOutBody = function() {
        $.galleryUtility.idxImage[-1].image.add($.galleryUtility.idxImage[1].image).css('cursor', 'pointer');
        if ($.galleryUtility.idxImage[0].image.attr('layout') === 'landscape') {
            $.galleryUtility.idxImage[0].image.animate({
                'top': $.galleryUtility.idxImage[0].Ltop,
                'left': $.galleryUtility.idxImage[0].Lleft,
                'height': $.galleryUtility.idxImage[0].Lheight,
                'width': $.galleryUtility.idxImage[0].Lwidth
            },
            $.galleryUtility.Options.zoomSpeed, 'linear', function() {
                $(this).css('z-index', '0').one('click', $.galleryUtility.zoomIn);
								for (currIndex=1;currIndex<$.galleryUtility.Options.imageNumSide;currIndex++){
							        $.galleryUtility.idxImage[currIndex].image.one('click', $.galleryUtility.slideLeft);
							        $.galleryUtility.idxImage[-currIndex].image.one('click', $.galleryUtility.slideRight);
								}
                
            });
        } else {
            $.galleryUtility.idxImage[0].image.animate({
                'top': $.galleryUtility.idxImage[0].Ptop,
                'left': $.galleryUtility.idxImage[0].Pleft,
                'height': $.galleryUtility.idxImage[0].Pheight,
                'width': $.galleryUtility.idxImage[0].Pwidth
            },
            $.galleryUtility.Options.zoomSpeed, 'linear', function() {
                $(this).css('z-index', '0').one('click', $.galleryUtility.zoomIn);
								for (currIndex=1;currIndex<$.galleryUtility.Options.imageNumSide;currIndex++){
							        $.galleryUtility.idxImage[currIndex].image.one('click', $.galleryUtility.slideLeft);
							        $.galleryUtility.idxImage[-currIndex].image.one('click', $.galleryUtility.slideRight);
								}
            });
        }
    };
		
//-------------------------------------------------------------------------------
// slideRight 
//-------------------------------------------------------------------------------
    $.galleryUtility.slideRight = function() {
		
	var index=0;
	var idximage=$.galleryUtility.idxImage;
	var num=$.galleryUtility.Options.imageNumSide;
	var num2=-$.galleryUtility.Options.imageNumSide;
	
	//alert(num+" "+num2);
	
	for (index = num2; index < num; index++) {
		
		if (index == num2) {
		//
		// Slide Left
		//
			if ($.galleryUtility.idxImage[index].image.attr('layout') === 'landscape') {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index + 1].Ltop,
					'left': $.galleryUtility.idxImage[index + 1].Lleft,
					'height': $.galleryUtility.idxImage[index + 1].Lheight,
					'width': $.galleryUtility.idxImage[index + 1].Lwidth,
               		'opacity': 'show'					
				}, $.galleryUtility.Options.slideSpeed, 'linear', function(){
					$(this).one('click', $.galleryUtility.slideRight);
				});
			} else {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index + 1].Ptop,
					'left': $.galleryUtility.idxImage[index + 1].Pleft,
					'height': $.galleryUtility.idxImage[index + 1].Pheight,
					'width': $.galleryUtility.idxImage[index + 1].Pwidth,
		            'opacity': 'show'
				}, $.galleryUtility.Options.slideSpeed, 'linear', function(){
					$(this).one('click', $.galleryUtility.slideRight);
				});
			}
		} else if (index>num2 && index<-1){
		//
		// Left
		//
			if ($.galleryUtility.idxImage[index].image.attr('layout') === 'landscape') {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index + 1].Ltop,
					'left': $.galleryUtility.idxImage[index + 1].Lleft,
					'height': $.galleryUtility.idxImage[index + 1].Lheight,
					'width': $.galleryUtility.idxImage[index + 1].Lwidth
				}, $.galleryUtility.Options.slideSpeed, 'linear', function(){
					$(this).one('click', $.galleryUtility.slideRight);
				});
			} else {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index + 1].Ptop,
					'left': $.galleryUtility.idxImage[index + 1].Pleft,
					'height': $.galleryUtility.idxImage[index + 1].Pheight,
					'width': $.galleryUtility.idxImage[index + 1].Pwidth
				}, $.galleryUtility.Options.slideSpeed, 'linear', function(){
					$(this).one('click', $.galleryUtility.slideRight);
				});
			}			
		} else if (index==-1){
		//
		// Left->center
		//
			if ($.galleryUtility.idxImage[index].image.attr('layout') === 'landscape') {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index + 1].Ltop,
					'left': $.galleryUtility.idxImage[index + 1].Lleft,
					'height': $.galleryUtility.idxImage[index + 1].Lheight,
					'width': $.galleryUtility.idxImage[index + 1].Lwidth
				}, $.galleryUtility.Options.slideSpeed, 'linear', function(){
					$(this).one('click', $.galleryUtility.zoomIn);
				});
			} else {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index + 1].Ptop,
					'left': $.galleryUtility.idxImage[index + 1].Pleft,
					'height': $.galleryUtility.idxImage[index + 1].Pheight,
					'width': $.galleryUtility.idxImage[index + 1].Pwidth
				}, $.galleryUtility.Options.slideSpeed, 'linear', function(){
					$(this).one('click', $.galleryUtility.zoomIn);
				});
			}			
		} else if (index>-1 && index<num-1){
		//
		// center->right
		//
			if ($.galleryUtility.idxImage[index].image.attr('layout') === 'landscape') {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index + 1].Ltop,
					'left': $.galleryUtility.idxImage[index + 1].Lleft,
					'height': $.galleryUtility.idxImage[index + 1].Lheight,
					'width': $.galleryUtility.idxImage[index + 1].Lwidth
				}, $.galleryUtility.Options.slideSpeed, 'linear', function(){
					$(this).one('click', $.galleryUtility.slideLeft);
				});
			} else {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index + 1].Ptop,
					'left': $.galleryUtility.idxImage[index + 1].Pleft,
					'height': $.galleryUtility.idxImage[index + 1].Pheight,
					'width': $.galleryUtility.idxImage[index + 1].Pwidth
				}, $.galleryUtility.Options.slideSpeed, 'linear', function(){
					$(this).one('click', $.galleryUtility.slideLeft);
				});
			}			
		} else if (index==num-1){
		//
		// slide right
		//
			if ($.galleryUtility.idxImage[index].image.attr('layout') === 'landscape') {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index + 1].Ltop,
					'left': $.galleryUtility.idxImage[index + 1].Lleft,
					'height': $.galleryUtility.idxImage[index + 1].Lheight,
					'width': $.galleryUtility.idxImage[index + 1].Lwidth,
	                'opacity': 'hide'
				}, $.galleryUtility.Options.slideSpeed, 'linear');
			} else {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index + 1].Ptop,
					'left': $.galleryUtility.idxImage[index + 1].Pleft,
					'height': $.galleryUtility.idxImage[index + 1].Pheight,
					'width': $.galleryUtility.idxImage[index + 1].Pwidth,
	                'opacity': 'hide'
					
				}, $.galleryUtility.Options.slideSpeed, 'linear');
			}			
		} 
	}

	for (index = num; index > num2; index--) {
		$.galleryUtility.idxImage[index].image = $.galleryUtility.idxImage[index-1].image;
	}
	$.galleryUtility.setIdxImage($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.idxImage[num2].image.attr('prev_1') + ']').hide(),num2);
	return;
};


//-------------------------------------------------------------------------------
// slideLeft 
//-------------------------------------------------------------------------------

    $.galleryUtility.slideLeft = function() {
		
	var index=0;
	var idximage=$.galleryUtility.idxImage;
	var num=$.galleryUtility.Options.imageNumSide;
	var num2=-$.galleryUtility.Options.imageNumSide;
	
	//alert(num+" "+num2);
	
	for (index = num; index > num2; index--) {
		if (index == num) {
		//
		// Slide Right
		//
			if ($.galleryUtility.idxImage[index].image.attr('layout') === 'landscape') {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index - 1].Ltop,
					'left': $.galleryUtility.idxImage[index - 1].Lleft,
					'height': $.galleryUtility.idxImage[index - 1].Lheight,
					'width': $.galleryUtility.idxImage[index - 1].Lwidth,
               		'opacity': 'show'					
				}, $.galleryUtility.Options.slideSpeed, 'linear', function(){
					$(this).one('click', $.galleryUtility.slideLeft);
				});
			} else {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index - 1].Ptop,
					'left': $.galleryUtility.idxImage[index - 1].Pleft,
					'height': $.galleryUtility.idxImage[index - 1].Pheight,
					'width': $.galleryUtility.idxImage[index - 1].Pwidth,
		            'opacity': 'show'
				}, $.galleryUtility.Options.slideSpeed, 'linear', function(){
					$(this).one('click', $.galleryUtility.slideLeft);
				});
			}
		} else if (index>1 && index<num){
		//
		// Right
		//
			if ($.galleryUtility.idxImage[index].image.attr('layout') === 'landscape') {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index - 1].Ltop,
					'left': $.galleryUtility.idxImage[index - 1].Lleft,
					'height': $.galleryUtility.idxImage[index - 1].Lheight,
					'width': $.galleryUtility.idxImage[index - 1].Lwidth
				}, $.galleryUtility.Options.slideSpeed, 'linear', function(){
					$(this).one('click', $.galleryUtility.slideLeft);
				});
			} else {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index - 1].Ptop,
					'left': $.galleryUtility.idxImage[index - 1].Pleft,
					'height': $.galleryUtility.idxImage[index - 1].Pheight,
					'width': $.galleryUtility.idxImage[index - 1].Pwidth
				}, $.galleryUtility.Options.slideSpeed, 'linear', function(){
					$(this).one('click', $.galleryUtility.slideLeft);
				});
			}			
		}  else if (index==1){
		//
		// Center
		//
			if ($.galleryUtility.idxImage[index].image.attr('layout') === 'landscape') {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index - 1].Ltop,
					'left': $.galleryUtility.idxImage[index - 1].Lleft,
					'height': $.galleryUtility.idxImage[index - 1].Lheight,
					'width': $.galleryUtility.idxImage[index - 1].Lwidth
				}, $.galleryUtility.Options.slideSpeed, 'linear', function(){
					$(this).one('click', $.galleryUtility.zoomIn);
				});
			} else {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index - 1].Ptop,
					'left': $.galleryUtility.idxImage[index - 1].Pleft,
					'height': $.galleryUtility.idxImage[index - 1].Pheight,
					'width': $.galleryUtility.idxImage[index - 1].Pwidth
				}, $.galleryUtility.Options.slideSpeed, 'linear', function(){
					$(this).one('click', $.galleryUtility.zoomIn);
				});
			}			
		} else if (index>num2+1 && index<1){
		//
		// center->right
		//
			if ($.galleryUtility.idxImage[index].image.attr('layout') === 'landscape') {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index - 1].Ltop,
					'left': $.galleryUtility.idxImage[index - 1].Lleft,
					'height': $.galleryUtility.idxImage[index - 1].Lheight,
					'width': $.galleryUtility.idxImage[index - 1].Lwidth
				}, $.galleryUtility.Options.slideSpeed, 'linear', function(){
					$(this).one('click', $.galleryUtility.slideRight);
				});
			} else {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index - 1].Ptop,
					'left': $.galleryUtility.idxImage[index - 1].Pleft,
					'height': $.galleryUtility.idxImage[index - 1].Pheight,
					'width': $.galleryUtility.idxImage[index - 1].Pwidth
				}, $.galleryUtility.Options.slideSpeed, 'linear', function(){
					$(this).one('click', $.galleryUtility.slideRight);
				});
			}			
		} else if (index==num2+1){
		//
		// slide right
		//
			if ($.galleryUtility.idxImage[index].image.attr('layout') === 'landscape') {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index - 1].Ltop,
					'left': $.galleryUtility.idxImage[index - 1].Lleft,
					'height': $.galleryUtility.idxImage[index - 1].Lheight,
					'width': $.galleryUtility.idxImage[index - 1].Lwidth,
	                'opacity': 'hide'
				}, $.galleryUtility.Options.slideSpeed, 'linear');
			} else {
				$.galleryUtility.idxImage[index].image.unbind().animate({
					'top': $.galleryUtility.idxImage[index - 1].Ptop,
					'left': $.galleryUtility.idxImage[index - 1].Pleft,
					'height': $.galleryUtility.idxImage[index - 1].Pheight,
					'width': $.galleryUtility.idxImage[index - 1].Pwidth,
	                'opacity': 'hide'
					
				}, $.galleryUtility.Options.slideSpeed, 'linear');
			}			
		} 
	}
	for (index = num2; index < num; index++) {
		$.galleryUtility.idxImage[index].image = $.galleryUtility.idxImage[index+1].image;
	}
	$.galleryUtility.setIdxImage($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.idxImage[num2].image.attr('prev_1') + ']').hide(),num);
   };

//-------------------------------------------------------------------------------
// setIdxImage 
//-------------------------------------------------------------------------------
    $.galleryUtility.setIdxImage = function(image,idx) {
        $.galleryUtility.idxImage[idx].image = image;
        if ($.galleryUtility.idxImage[idx].image.attr('layout') === 'landscape') {
            $.galleryUtility.idxImage[idx].image.css({
                'top': $.galleryUtility.idxImage[idx].Ltop,
                'left': $.galleryUtility.idxImage[idx].Lleft,
                'height': $.galleryUtility.idxImage[idx].Lheight,
                'width': $.galleryUtility.idxImage[idx].Lwidth
            });
        } else {
            $.galleryUtility.idxImage[idx].image.css({
                'top': $.galleryUtility.idxImage[idx].Ptop,
                'left': $.galleryUtility.idxImage[idx].Pleft,
                'height': $.galleryUtility.idxImage[idx].Pheight,
                'width': $.galleryUtility.idxImage[idx].Pwidth
            });
        }
    };

//-------------------------------------------------------------------------------
// defineIdxPositions 
//-------------------------------------------------------------------------------
    $.galleryUtility.defineIdxPositions = function(num,x_add,y_add,x2_add,y2_add,x3_add,y3_add) {
		
    	
    	//
    	// Start Img
    	//
        $.galleryUtility.idxImage[0].Lheight = Math.round($.galleryUtility.Options.Lheight);
        $.galleryUtility.idxImage[0].Lwidth = Math.round($.galleryUtility.Options.Lwidth);
        if (y2_add=='src'){
        		$.galleryUtility.idxImage[0].Ltop = y3_add + $.galleryUtility.gallery.filter('.' + $.galleryUtility.Options.startClass).position().top;
	        } else if (y2_add!=0){
		        $.galleryUtility.idxImage[0].Ltop = y2_add - ($.galleryUtility.idxImage[0].Lheight / 2);
	        } else {
		        $.galleryUtility.idxImage[0].Ltop = y3_add+y_add+Math.round($(window).height() / 2) - ($.galleryUtility.idxImage[0].Lheight / 2);
	        }
	        
				if (x2_add=='src'){
        		$.galleryUtility.idxImage[0].Lleft = x3_add + $.galleryUtility.gallery.filter('.' + $.galleryUtility.Options.startClass).position().left;
	        } else if (x2_add!=0){
		        $.galleryUtility.idxImage[0].Lleft = x2_add - ($.galleryUtility.idxImage[0].Lwidth / 2);
	        } else {
		        $.galleryUtility.idxImage[0].Lleft = x3_add+x_add+Math.round($(window).width() / 2) - ($.galleryUtility.idxImage[0].Lwidth / 2);
	        }
	        
        $.galleryUtility.idxImage[0].Pheight = Math.round($.galleryUtility.Options.Pheight);
        $.galleryUtility.idxImage[0].Pwidth = Math.round($.galleryUtility.Options.Pwidth);
        if (y2_add=='src'){
        		$.galleryUtility.idxImage[0].Ltop = y3_add + $.galleryUtility.gallery.filter('.' + $.galleryUtility.Options.startClass).position().top;
	        } else if (y2_add!=0){
		        $.galleryUtility.idxImage[0].Ptop = y2_add - ($.galleryUtility.idxImage[0].Pheight / 2);
	        } else {
		        $.galleryUtility.idxImage[0].Ptop = y3_add+y_add+Math.round(($(window).height() / 2) - ($.galleryUtility.idxImage[0].Pheight / 2));
	        }
        if (x2_add=='src'){
        		$.galleryUtility.idxImage[0].Pleft = x3_add + $.galleryUtility.gallery.filter('.' + $.galleryUtility.Options.startClass).position().left;
	        } else if (x2_add!=0){
		        $.galleryUtility.idxImage[0].Pleft = x2_add - ($.galleryUtility.idxImage[0].Pwidth / 2);
	        } else {
		        $.galleryUtility.idxImage[0].Pleft = x3_add+x_add+Math.round(($(window).width() / 2) - ($.galleryUtility.idxImage[0].Pwidth / 2));
	        }
		
	    //
	    // Zoom Img
	    //
        $.galleryUtility.zoomImage.Lheight = Math.round($.galleryUtility.Options.Lzoom($.galleryUtility.idxImage[0].Lheight));
        $.galleryUtility.zoomImage.Lwidth = Math.round($.galleryUtility.Options.Lzoom($.galleryUtility.idxImage[0].Lwidth));
        if (y2_add=='src'){
		        $.galleryUtility.zoomImage.Ltop = y3_add + Math.round($.galleryUtility.idxImage[0].Ltop - ($.galleryUtility.zoomImage.Lheight / 2));
	        } else if (y2_add!=0){
		        $.galleryUtility.zoomImage.Ltop = y2_add - ($.galleryUtility.zoomImage.Lheight / 2);
	        } else {
  		      $.galleryUtility.zoomImage.Ltop = y3_add+y_add+Math.round(($(window).height() / 2) - ($.galleryUtility.zoomImage.Lheight / 2));
	        }
        if (x2_add=='src'){
        		$.galleryUtility.idxImage[0].Pleft = x3_add + $.galleryUtility.gallery.filter('.' + $.galleryUtility.Options.startClass).position().left - ($.galleryUtility.zoomImage.Lwidth / 2);
	        } else if (x2_add!=0){
		        $.galleryUtility.zoomImage.Lleft = x2_add - ($.galleryUtility.zoomImage.Lwidth / 2);
	        } else {
		        $.galleryUtility.zoomImage.Lleft = x3_add+x_add+Math.round(($(window).width() / 2) - ($.galleryUtility.zoomImage.Lwidth / 2));
	        }
		
        $.galleryUtility.zoomImage.Pheight = Math.round($.galleryUtility.Options.Pzoom($.galleryUtility.idxImage[0].Pheight));
        $.galleryUtility.zoomImage.Pwidth = Math.round($.galleryUtility.Options.Pzoom($.galleryUtility.idxImage[0].Pwidth));
        $.galleryUtility.zoomImage.Ptop = y_add+Math.round(($(window).height() / 2) - ($.galleryUtility.zoomImage.Pheight / 2));
        $.galleryUtility.zoomImage.Pleft = x_add+Math.round(($(window).width() / 2) - ($.galleryUtility.zoomImage.Pwidth / 2));
		
		var index=0;
		// Left Image
		for(index=-1;index>-num;index--){
	        $.galleryUtility.idxImage[index].Lheight = Math.round($.galleryUtility.Options.Lshrink($.galleryUtility.idxImage[index+1].Lheight));
	        $.galleryUtility.idxImage[index].Lwidth = Math.round($.galleryUtility.Options.Lshrink($.galleryUtility.idxImage[index+1].Lwidth));
	        $.galleryUtility.idxImage[index].Ltop = y_add+Math.round($.galleryUtility.idxImage[index+1].Ltop + (($.galleryUtility.idxImage[index+1].Lheight - $.galleryUtility.idxImage[index].Lheight) / 2));
					$.galleryUtility.idxImage[index].Lleft = x_add+Math.round($.galleryUtility.idxImage[index+1].Lleft - ($.galleryUtility.idxImage[index].Lwidth + $.galleryUtility.Options.gutterWidth));
			
	        $.galleryUtility.idxImage[index].Pheight = Math.round($.galleryUtility.Options.Pshrink($.galleryUtility.idxImage[index+1].Pheight));
	        $.galleryUtility.idxImage[index].Pwidth = Math.round($.galleryUtility.Options.Pshrink($.galleryUtility.idxImage[index+1].Pwidth));
	        $.galleryUtility.idxImage[index].Ptop = y_add+Math.round($.galleryUtility.idxImage[index+1].Ptop + (($.galleryUtility.idxImage[index+1].Pheight - $.galleryUtility.idxImage[index].Pheight) / 2));
					$.galleryUtility.idxImage[index].Pleft = x_add+Math.round($.galleryUtility.idxImage[index + 1].Pleft - ($.galleryUtility.idxImage[index].Pwidth + $.galleryUtility.Options.gutterWidth));
		}
		
		
		//Right Image
		var index=0;
		for (index = 1; index < num; index++) {
			$.galleryUtility.idxImage[index].Lheight = Math.round($.galleryUtility.Options.Lshrink($.galleryUtility.idxImage[index-1].Lheight));
			$.galleryUtility.idxImage[index].Lwidth = Math.round($.galleryUtility.Options.Lshrink($.galleryUtility.idxImage[index-1].Lwidth));
			$.galleryUtility.idxImage[index].Ltop = y_add+Math.round($.galleryUtility.idxImage[index-1].Ltop + (($.galleryUtility.idxImage[index-1].Lheight - $.galleryUtility.idxImage[index].Lheight) / 2));
			$.galleryUtility.idxImage[index].Lleft = x_add+Math.round($.galleryUtility.idxImage[index-1].Lleft + ($.galleryUtility.idxImage[index-1].Lwidth + $.galleryUtility.Options.gutterWidth));
			
			$.galleryUtility.idxImage[index].Pheight = Math.round($.galleryUtility.Options.Pshrink($.galleryUtility.idxImage[index-1].Pheight));
			$.galleryUtility.idxImage[index].Pwidth = Math.round($.galleryUtility.Options.Pshrink($.galleryUtility.idxImage[index-1].Pwidth));
			$.galleryUtility.idxImage[index].Ptop = y_add+Math.round($.galleryUtility.idxImage[index-1].Ptop + (($.galleryUtility.idxImage[index-1].Pheight - $.galleryUtility.idxImage[-index].Pheight) / 2));
			$.galleryUtility.idxImage[index].Pleft = x_add+Math.round($.galleryUtility.idxImage[index-1].Pleft + ($.galleryUtility.idxImage[index-1].Pwidth + $.galleryUtility.Options.gutterWidth));				
		}

		// Left Image Storage
        $.galleryUtility.idxImage[-num].Lheight = Math.round($.galleryUtility.Options.Lshrink($.galleryUtility.idxImage[-num+1].Lheight));
        $.galleryUtility.idxImage[-num].Lwidth = Math.round($.galleryUtility.Options.Lshrink($.galleryUtility.idxImage[-num+1].Lwidth));
        $.galleryUtility.idxImage[-num].Ltop = y_add+Math.round($.galleryUtility.idxImage[-num+1].Ltop + (($.galleryUtility.idxImage[-num+1].Lheight - $.galleryUtility.idxImage[-num].Lheight) / 2));
        $.galleryUtility.idxImage[-num].Lleft = x_add+Math.round($.galleryUtility.idxImage[-num+1].Lleft - ($.galleryUtility.idxImage[-num].Lwidth + $.galleryUtility.Options.gutterWidth));
		
        $.galleryUtility.idxImage[-num].Pheight = Math.round($.galleryUtility.Options.Pshrink($.galleryUtility.idxImage[-num+1].Pheight));
        $.galleryUtility.idxImage[-num].Pwidth = Math.round($.galleryUtility.Options.Pshrink($.galleryUtility.idxImage[-num+1].Pwidth));
        $.galleryUtility.idxImage[-num].Ptop = y_add+Math.round($.galleryUtility.idxImage[-num+1].Ptop + (($.galleryUtility.idxImage[-num+1].Pheight - $.galleryUtility.idxImage[-num].Pheight) / 2));
        $.galleryUtility.idxImage[-num].Pleft = x_add+Math.round($.galleryUtility.idxImage[-num+1].Pleft - ($.galleryUtility.idxImage[-num].Pwidth + $.galleryUtility.Options.gutterWidth));
        
        
        
        $.galleryUtility.idxImage[num].Lheight = Math.round($.galleryUtility.Options.Lshrink($.galleryUtility.idxImage[num-1].Lheight));
        $.galleryUtility.idxImage[num].Lwidth = Math.round($.galleryUtility.Options.Lshrink($.galleryUtility.idxImage[num-1].Lwidth));
        $.galleryUtility.idxImage[num].Ltop = y_add+Math.round($.galleryUtility.idxImage[num-1].Ltop + (($.galleryUtility.idxImage[num-1].Lheight - $.galleryUtility.idxImage[num].Lheight) / 2));
        $.galleryUtility.idxImage[num].Lleft = x_add+Math.round($.galleryUtility.idxImage[num-1].Lleft + ($.galleryUtility.idxImage[num-1].Lwidth + $.galleryUtility.Options.gutterWidth));
		
        $.galleryUtility.idxImage[num].Pheight = Math.round($.galleryUtility.Options.Pshrink($.galleryUtility.idxImage[num-1].Pheight));
        $.galleryUtility.idxImage[num].Pwidth = Math.round($.galleryUtility.Options.Pshrink($.galleryUtility.idxImage[num-1].Pwidth));
        $.galleryUtility.idxImage[num].Ptop = y_add+Math.round($.galleryUtility.idxImage[num-1].Ptop + (($.galleryUtility.idxImage[num-1].Pheight - $.galleryUtility.idxImage[num].Pheight) / 2));
        $.galleryUtility.idxImage[num].Pleft = x_add+Math.round($.galleryUtility.idxImage[num-1].Pleft + ($.galleryUtility.idxImage[num-1].Pwidth + $.galleryUtility.Options.gutterWidth));
    };

//-------------------------------------------------------------------------------
// debugIdxPositions 
//-------------------------------------------------------------------------------
    $.galleryUtility.debugIdxPositions = function(num){
		var index=0;
		for (index = -num; index <= num; index++) {
			var style=' style=" z-index: -10; border: 1px #FF0000 solid; position: absolute;	'
					+'; width: '+$.galleryUtility.idxImage[index].Lwidth 
					+'px; height: '+$.galleryUtility.idxImage[index].Lheight
					+'px; top: '+$.galleryUtility.idxImage[index].Ltop 
					+'px; left: '+$.galleryUtility.idxImage[index].Lleft 
					+'px;"'; 
            $('body').append('<div id="debugL_'+index +'"'+style+'> Index: '+index+' Lwidth: '+$.galleryUtility.idxImage[index].Lwidth+' Lheight: '+$.galleryUtility.idxImage[index].Lheight+' Ltop: '+$.galleryUtility.idxImage[index].Ltop+' Lleft: '+$.galleryUtility.idxImage[index].Lleft+' '+' </div>');
			var style=' style=" z-index: -10; border: 1px #00FF00 solid; position: absolute;	'
					+'; width: '+$.galleryUtility.idxImage[index].Pwidth 
					+'px; height: '+$.galleryUtility.idxImage[index].Pheight
					+'px; top: '+$.galleryUtility.idxImage[index].Ptop 
					+'px; left: '+$.galleryUtility.idxImage[index].Pleft 
					+'px;"'; 
            $('body').append('<div id="debugP_'+index +'"'+style+'> Index: '+index+' Pwidth: '+$.galleryUtility.idxImage[index].Lwidth+' Pheight: '+$.galleryUtility.idxImage[index].Pheight+' Ptop: '+$.galleryUtility.idxImage[index].Ptop+' Pleft: '+$.galleryUtility.idxImage[index].Pleft+' '+' </div>');
		}
	}
	
//-------------------------------------------------------------------------------
// LcaptionDown 
//-------------------------------------------------------------------------------

    $.galleryUtility.LcaptionDown = function() {
        $.galleryUtility.idxImage[0].image.unbind();
        $('body').append('<span id="' + $.galleryUtility.Options.captionID + '" style="' + $.galleryUtility.Options.captionStyle + '" class="' + $.galleryUtility.Options.captionClass + '">' + $.galleryUtility.idxImage[0].image.attr($.galleryUtility.Options.captionTextAttribute) + '</span>');
        $('#' + $.galleryUtility.Options.captionID).css({
            'top': $.galleryUtility.zoomImage.Ltop + parseInt($.galleryUtility.idxImage[0].image.css('borderTopWidth'), 10),
            'left': $.galleryUtility.zoomImage.Lleft + parseInt($.galleryUtility.idxImage[0].image.css('borderLeftWidth'), 10),
            'width': $.galleryUtility.zoomImage.Lwidth,
            'height': 0,
            'position': 'absolute',
            'z-index': '100'
        }).animate({ 'height': Math.round($.galleryUtility.Options.captionHeight($.galleryUtility.zoomImage.Lheight)) }, 'normal', 'linear');
        $('#' + $.galleryUtility.Options.captionDownID).animate({
            'height': 0,
            'top': $.galleryUtility.zoomImage.Ltop + (Math.round($.galleryUtility.Options.captionHeight($.galleryUtility.zoomImage.Lheight))) + parseInt($.galleryUtility.idxImage[0].image.css('borderTopWidth'), 10)
        }, 'normal', 'linear', function() { $('#' + $.galleryUtility.Options.captionDownID).hide(); });
        $('#' + $.galleryUtility.Options.captionUpID).css({
            'top': $.galleryUtility.zoomImage.Ltop + $.galleryUtility.Options.captionDownHeight + parseInt($.galleryUtility.idxImage[0].image.css('borderTopWidth'), 10),
            'left': $.galleryUtility.zoomImage.Lleft + ($.galleryUtility.zoomImage.Lwidth - $.galleryUtility.Options.captionUpWidth) + parseInt($.galleryUtility.idxImage[0].image.css('borderLeftWidth'), 10),
            'height': 0,
            'position': 'absolute',
            'z-index': '100'
        }).show().animate({
            'top': $.galleryUtility.zoomImage.Ltop + (Math.round($.galleryUtility.Options.captionHeight($.galleryUtility.zoomImage.Lheight))) + parseInt($.galleryUtility.idxImage[0].image.css('borderTopWidth'), 10),
            'height': $.galleryUtility.Options.captionUpHeight
        }, 'normal', 'linear', function() {
            $('#' + $.galleryUtility.Options.captionUpID).one('click', function() {
                $.galleryUtility.LcaptionUp(false);
            });
            $.galleryUtility.idxImage[0].image.one('click', function() {
                $.galleryUtility.LcaptionUp(true);
            });
        });
    };
//-------------------------------------------------------------------------------
// PcaptionDown 
//-------------------------------------------------------------------------------
    $.galleryUtility.PcaptionDown = function() {
        $.galleryUtility.idxImage[0].image.unbind();
        $('body').append('<span id="' + $.galleryUtility.Options.captionID + '" style="' + $.galleryUtility.Options.captionStyle + '" class="' + $.galleryUtility.Options.captionClass + '">' + $.galleryUtility.idxImage[0].image.attr($.galleryUtility.Options.captionTextAttribute) + '</span>');
        $('#' + $.galleryUtility.Options.captionID).css({
            'top': $.galleryUtility.zoomImage.Ptop + parseInt($.galleryUtility.idxImage[0].image.css('borderTopWidth'), 10),
            'left': $.galleryUtility.zoomImage.Pleft + parseInt($.galleryUtility.idxImage[0].image.css('borderLeftWidth'), 10),
            'width': $.galleryUtility.zoomImage.Pwidth,
            'height': 0,
            'position': 'absolute',
            'z-index': '100'
        }).animate({ 'height': Math.round($.galleryUtility.Options.captionHeight($.galleryUtility.zoomImage.Pheight)) }, 'normal', 'linear');
        $('#' + $.galleryUtility.Options.captionDownID).animate({
            'height': 0,
            'top': $.galleryUtility.zoomImage.Ptop + (Math.round($.galleryUtility.Options.captionHeight($.galleryUtility.zoomImage.Pheight))) + parseInt($.galleryUtility.idxImage[0].image.css('borderTopWidth'), 10)
        }, 'normal', 'linear', function() { $('#' + $.galleryUtility.Options.captionDownID).hide(); });
        $('#' + $.galleryUtility.Options.captionUpID).css({
            'top': $.galleryUtility.zoomImage.Ptop + $.galleryUtility.Options.captionDownHeight + parseInt($.galleryUtility.idxImage[0].image.css('borderTopWidth'), 10),
            'left': $.galleryUtility.zoomImage.Pleft + ($.galleryUtility.zoomImage.Pwidth - $.galleryUtility.Options.captionUpWidth) + parseInt($.galleryUtility.idxImage[0].image.css('borderLeftWidth'), 10),
            'height': 0,
            'position': 'absolute',
            'z-index': '100'
        }).show().animate({
            'top': $.galleryUtility.zoomImage.Ptop + (Math.round($.galleryUtility.Options.captionHeight($.galleryUtility.zoomImage.Pheight))) + parseInt($.galleryUtility.idxImage[0].image.css('borderTopWidth'), 10),
            'height': $.galleryUtility.Options.captionUpHeight
        }, 'normal', 'linear', function() {
            $('#' + $.galleryUtility.Options.captionUpID).one('click', function() {
                $.galleryUtility.PcaptionUp(false);
            });
            $.galleryUtility.idxImage[0].image.one('click', function() {
                $.galleryUtility.PcaptionUp(true);
            });
        });
    };
//-------------------------------------------------------------------------------
// LcaptionUp 
//-------------------------------------------------------------------------------
    $.galleryUtility.LcaptionUp = function(unzoom) {
        $('#' + $.galleryUtility.Options.captionID).animate({ 'height': 0 }, 'normal', 'linear', function() { $('#' + $.galleryUtility.Options.captionID).remove(); });
        $('#' + $.galleryUtility.Options.captionUpID).animate({
            'top': $.galleryUtility.zoomImage.Ltop + $.galleryUtility.Options.captionDownHeight + parseInt($.galleryUtility.idxImage[0].image.css('borderTopWidth'), 10),
            'height': 0
        }, 'normal', 'linear', function() {
            $('#' + $.galleryUtility.Options.captionUpID).hide();
        });
        $('#' + $.galleryUtility.Options.captionDownID).show().animate({
            'height': $.galleryUtility.Options.captionDownHeight,
            'top': $.galleryUtility.zoomImage.Ltop + parseInt($.galleryUtility.idxImage[0].image.css('borderTopWidth'), 10)
        }, 'normal', 'linear', function() {
            if (unzoom) {
                $('#' + $.galleryUtility.Options.captionUpID).unbind();
                $.galleryUtility.zoomOut();
            } else {
                $('#' + $.galleryUtility.Options.captionDownID).one('click', $.galleryUtility.LcaptionDown);
                $.galleryUtility.idxImage[0].image.one('click', $.galleryUtility.zoomOut);
            }
        });
    };
//-------------------------------------------------------------------------------
// PcaptionUp 
//-------------------------------------------------------------------------------
    $.galleryUtility.PcaptionUp = function(unzoom) {
        $('#' + $.galleryUtility.Options.captionID).animate({ 'height': 0 }, 'normal', 'linear', function() { $('#' + $.galleryUtility.Options.captionID).remove(); });
        $('#' + $.galleryUtility.Options.captionUpID).animate({
            'top': $.galleryUtility.zoomImage.Ptop + $.galleryUtility.Options.captionDownHeight + parseInt($.galleryUtility.idxImage[0].image.css('borderTopWidth'), 10),
            'height': 0
        }, 'normal', 'linear', function() {
            $('#' + $.galleryUtility.Options.captionUpID).hide();
        });
        $('#' + $.galleryUtility.Options.captionDownID).show().animate({
            'height': $.galleryUtility.Options.captionDownHeight,
            'top': $.galleryUtility.zoomImage.Ptop + parseInt($.galleryUtility.idxImage[0].image.css('borderTopWidth'), 10)
        }, 'normal', 'linear', function() {
            if (unzoom) {
                $('#' + $.galleryUtility.Options.captionUpID).unbind();
                $.galleryUtility.zoomOut();
            } else {
                $('#' + $.galleryUtility.Options.captionDownID).one('click', $.galleryUtility.PcaptionDown);
                $.galleryUtility.idxImage[0].image.one('click', $.galleryUtility.zoomOut);
            }
        });
    };	
})(jQuery);

/**
/ THIRD FUNCTION
* getPageSize() by quirksmode.com
*
* @return Array Return an array with page width, height and window width, height
*/
function ___getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
}
