(function ($) {
    $.galleryUtility = {};
    $.galleryUtility.centerImage = {};
    $.galleryUtility.rightImage = {};
    $.galleryUtility.leftImage = {};
    $.galleryUtility.rightImageStorage = {};
    $.galleryUtility.leftImageStorage = {};
    $.galleryUtility.zoomImage = {};
    $.galleryUtility.gallery = {};
    $.galleryUtility.Options = {
		containerheight: 600,
		lazy: true,
		bgcolor: '#FFF',
		clickappear: true,
        container: null,
        Lheight: 300,
        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: 50,
        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
    };
    $.fn.slidingGallery = function (options) {
        $.extend($.galleryUtility.Options, options);
        $('body').css('overflow-x', 'hidden');
        var container = null;
        if (!$.galleryUtility.Options.container) {
            $.galleryUtility.Options.container = $('body');
        } else {
            $.galleryUtility.Options.container.css({'position':'relative','overflow':'hidden','height':$.galleryUtility.Options.containerheight});
        }
		$('head').append('<meta property="og:url" content="'+location.host+location.pathname+'"/><meta property="og:image" content="'+$.galleryUtility.Options.container.find('img').first().attr('original')+'"/>')
		$.galleryUtility.Options.container.parent().append('<div class="mediaoverlay" style="background-color: black;height: 620px;position: absolute;top: 50px;width: 900px;z-index: 100;" /><div class="prevarrow"><img id="prevbutton" src="/sites/all/themes/cheeswedding2011/js/img/prevarrow.png" alt="prev"/></div><div class="nextarrow"><img id="nextbutton" src="/sites/all/themes/cheeswedding2011/js/img/nextarrow.png" alt="next"/></div><div id="fb-root"></div><div style="margin-top:20px;text-align:left;" id="fblike"><script>(function(d){var js, id = \'facebook-jssdk\'; if (d.getElementById(id)) {return;}js = d.createElement(\'script\'); js.id = id; js.async = true;js.src = "//connect.facebook.net/en_US/all.js#appId=237313606315427&xfbml=1";d.getElementsByTagName(\'head\')[0].appendChild(js);}(document));</script><fb:like href="'+location.host+location.pathname+'" send="false" layout="button_count" width="90" show_faces="false" font="lucida grande"></fb:like></div>');
        $.galleryUtility.gallery = $(this).css('cursor', 'pointer');
        if ($.galleryUtility.Options.useCaptions) {
            $.galleryUtility.Options.container.append('<img src="' + $.galleryUtility.Options.captionUpPath + '" style="width: ' + $.galleryUtility.Options.captionUpWidth + '; display: none; border-width:0px;"' + 'id="' + $.galleryUtility.Options.captionUpID + '" />').append('<img src="' + $.galleryUtility.Options.captionDownPath + '" style="width: ' + $.galleryUtility.Options.captionDownWidth + '; display: none; border-width:0px;"' + 'id="' + $.galleryUtility.Options.captionDownID + '" />');
            $('#' + $.galleryUtility.Options.captionUpID + ',#' + $.galleryUtility.Options.captionDownID).css('cursor', 'help');
        }
        var lastIndex = 0;
		if($.galleryUtility.Options.lazy == true){
        var gallerySize = $.galleryUtility.gallery.each(function (i) {
            $(this).attr({
                'index': i,
                'prev': (i - 1),
                'next': (i + 1),
				'src': '/sites/all/themes/cheeswedding2011/js/img/grey.gif',
								//'original':$(this).attr('src'),
				'opacity':0.5
            }).css('position', 'absolute');
            if (($(this).attr('layout') !== 'portrait') && ($(this).attr('layout') !== 'landscape')) {
                $(this).attr('layout', $.galleryUtility.Options.defaultLayout);
            }
            lastIndex = i;
        }).hide().size();
		}else{
			        var gallerySize = $.galleryUtility.gallery.each(function (i) {
            $(this).attr({
                'index': i,
                'prev': (i - 1),
                'next': (i + 1),
								'original':$(this).attr('src'),
				'opacity':0.5
            }).css('position', 'absolute');
            if (($(this).attr('layout') !== 'portrait') && ($(this).attr('layout') !== 'landscape')) {
                $(this).attr('layout', $.galleryUtility.Options.defaultLayout);
            }
            lastIndex = i;
        }).hide().size();
		}
if($.galleryUtility.Options.clickappear ==false){
	$.galleryUtility.Options.container.parents('div.region-content').css({'background-color':$.galleryUtility.Options.bgcolor,'padding':'2%','width':'96.2%'});
}
        var currIndex = 0;
        while (gallerySize < 7) {
            var $clone = $.galleryUtility.gallery.filter('[index=' + currIndex + ']').clone().attr({
                'index': lastIndex + 1,
                'prev': lastIndex,
                'next': lastIndex + 2
            }).removeClass($.galleryUtility.Options.startClass);
            $.galleryUtility.gallery.filter('[index=' + (lastIndex) + ']').after($clone);
            $.galleryUtility.gallery = $.galleryUtility.gallery.add('img[index=' + (lastIndex + 1) + ']');
            lastIndex++;
            currIndex++;
            gallerySize++;
        }
		$.galleryUtility.defineImg($.galleryUtility.gallery.filter('img:first'));	
		$.galleryUtility.definePositions();
        $.galleryUtility.gallery.filter('[index=' + lastIndex + ']').attr('next', 0);
        $.galleryUtility.gallery.filter('[index=0]').attr('prev', lastIndex);
        $.galleryUtility.setCenter($.galleryUtility.gallery.filter('.' + $.galleryUtility.Options.startClass).show());	
        $.galleryUtility.setLeft($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.centerImage.image.attr('prev') + ']').show());
        $.galleryUtility.setRight($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.centerImage.image.attr('next') + ']').show());
        $.galleryUtility.setLeftStorage($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.leftImage.image.attr('prev') + ']'));
        $.galleryUtility.setRightStorage($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.rightImage.image.attr('next') + ']'));
        $.galleryUtility.leftImage.image.one('click', $.galleryUtility.slideRight);
        $.galleryUtility.rightImage.image.one('click', $.galleryUtility.slideLeft);
				if($.galleryUtility.Options.clickappear ==false){
						$('.nextarrow img').one('click', $.galleryUtility.slideLeft).parent().show();
				$('.prevarrow img').one('click', $.galleryUtility.slideRight).parent().show();
}

		$('a.media-gallery-thumb').click(function(){
					$('meta[property=og:url]').attr('content', location.host+location.pathname);
		$('meta[property=og:image]').attr('content', $.galleryUtility.centerImage.image.attr('original'));
		var arr = $(this).find('img').attr('src').split('/');
				$.address.value(arr[arr.length-1]);  
									$.galleryUtility.CreateNewLikeButton(location.host+location.pathname);
					$('.media-gallery-media').hide();
		$('.pager').hide();
		$.galleryUtility.Options.container.parents('div.region-content').css({'background-color':$.galleryUtility.Options.bgcolor,'padding':'2%','width':'96.2%'});
			$('div#myGalleryFlow').show();
			$('#myGalleryFlow img').unbind();
			$.galleryUtility.centerImage.image.hide();
			$.galleryUtility.leftImage.image.hide();
			$.galleryUtility.rightImage.image.hide();
			$.galleryUtility.defineImg($('#myGalleryFlow img.item[original$="'+arr[arr.length-1]+'"]'));
						$.galleryUtility.definePositions();
            $.galleryUtility.setCenter($.galleryUtility.centerImage.image);
            $.galleryUtility.setLeft($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.centerImage.image.attr('prev') + ']'));
            $.galleryUtility.setRight($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.centerImage.image.attr('next') + ']'));
			 $.galleryUtility.setLeftStorage($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.leftImage.image.attr('prev') + ']'));
        $.galleryUtility.setRightStorage($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.rightImage.image.attr('next') + ']'));
			$.galleryUtility.leftImage.image.one('click', $.galleryUtility.slideRight);
        $.galleryUtility.rightImage.image.one('click', $.galleryUtility.slideLeft);
						$('.nextarrow img').one('click', $.galleryUtility.slideLeft).parent().show();
				$('.prevarrow img').one('click', $.galleryUtility.slideRight).parent().show();
			$('.back-btn').click(function(){
											$.address.value('');
				$.galleryUtility.CreateNewLikeButton(location.host+location.pathname);
				$.galleryUtility.Options.container.parents('div.region-content').css({'background-color':'#FFF','padding':'0','width':'100%'});
			$('div#myGalleryFlow').hide();
			$('.media-gallery-media').fadeIn();
			$('.pager').fadeIn();
			$('.back-btn').unbind();
						$('.nextarrow img').unbind().parent().hide();
				$('.prevarrow img').unbind().parent().hide();
			return false;
		});

			
				return false;
		});
		$('a.media-gallery-thumb').bind('ajax', function(event, ahash) {
		$('meta[property=og:url]').attr('content', location.host+location.pathname);
		$('meta[property=og:image]').attr('content', $.galleryUtility.centerImage.image.attr('original'));
									$('.fb-like').attr('data-href',location.host+location.pathname);
					$('.media-gallery-media').hide();
		$('.pager').hide();
		$.galleryUtility.Options.container.parents('div.region-content').css({'background-color':$.galleryUtility.Options.bgcolor,'padding':'2%','width':'96.2%'});
			$('div#myGalleryFlow').show();
			$('#myGalleryFlow img').unbind();
			var arr = ahash.split('/');
			$.galleryUtility.centerImage.image.hide();
			$.galleryUtility.leftImage.image.hide();
			$.galleryUtility.rightImage.image.hide();
			$.galleryUtility.defineImg($('#myGalleryFlow img.item[original$="'+arr[arr.length-1]+'"]'));
						$.galleryUtility.definePositions();
            $.galleryUtility.setCenter($.galleryUtility.centerImage.image);
            $.galleryUtility.setLeft($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.centerImage.image.attr('prev') + ']'));
            $.galleryUtility.setRight($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.centerImage.image.attr('next') + ']'));
			 $.galleryUtility.setLeftStorage($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.leftImage.image.attr('prev') + ']'));
        $.galleryUtility.setRightStorage($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.rightImage.image.attr('next') + ']'));
			$.galleryUtility.leftImage.image.one('click', $.galleryUtility.slideRight);
        $.galleryUtility.rightImage.image.one('click', $.galleryUtility.slideLeft);
						$('.nextarrow img').one('click', $.galleryUtility.slideLeft).parent().show();
				$('.prevarrow img').one('click', $.galleryUtility.slideRight).parent().show();
			$('.back-btn').click(function(){
				$.galleryUtility.Options.container.parents('div.region-content').css({'background-color':'#FFF','padding':'0','width':'100%'});
			$('div#myGalleryFlow').hide();
			$('.media-gallery-media').fadeIn();
			$('.pager').fadeIn();
			$('.back-btn').unbind();
						$('.nextarrow img').unbind().parent().hide();
				$('.prevarrow img').unbind().parent().hide();
			return false;
		});

			
				return false;
});
        /*$(window).resize(function () {
            $.galleryUtility.definePositions();
            $.galleryUtility.setCenter($.galleryUtility.centerImage.image);
            $.galleryUtility.setLeft($.galleryUtility.leftImage.image);
            $.galleryUtility.setRight($.galleryUtility.rightImage.image);
            $.galleryUtility.setLeftStorage($.galleryUtility.leftImageStorage.image);
            $.galleryUtility.setRightStorage($.galleryUtility.rightImageStorage.image);
        });*/
						        //$.galleryUtility.definePositions();
$('.mediaoverlay').hide();
        return $(this);
    };
    $.galleryUtility.slideRight = function () {
		$('meta[property=og:url]').attr('content', location.host+location.pathname);
		$('meta[property=og:image]').attr('content', $.galleryUtility.centerImage.image.attr('original'));
		var arr = $.galleryUtility.leftImage.image.attr('original').split('/');
				$.address.value(arr[arr.length-1]);   
									$.galleryUtility.CreateNewLikeButton(location.host+location.pathname);
				$('.prevarrow img').unbind().one('click', $.galleryUtility.slideRight);
		//$('.media-shadow').hide();
		            $.galleryUtility.definePositions($.galleryUtility.leftImage, $.galleryUtility.leftImageStorage, $.galleryUtility.centerImage);
        var risLeft = $.galleryUtility.rightImageStorage.left($.galleryUtility.centerImage.image, $.galleryUtility.leftImage.image);
					if($.galleryUtility.Options.lazy == true){
					if ($.galleryUtility.leftImageStorage.image.attr('src')!=$.galleryUtility.leftImageStorage.image.attr('original')){
				$.galleryUtility.leftImageStorage.image.attr('src', $.galleryUtility.leftImageStorage.image.attr('original'));
		}
			}
        if ($.galleryUtility.leftImageStorage.image.attr('layout') === 'landscape') {

            $.galleryUtility.leftImageStorage.image.css('opacity',0.5).animate({
                'bottom': 0,
                'left': $.galleryUtility.Options.gutterWidth,
                'height': $.galleryUtility.leftImageStorage.image.attr('imgheight')/2,
                'width': $.galleryUtility.leftImageStorage.image.attr('imgwidth')/2
            }, $.galleryUtility.Options.slideSpeed, 'linear', function () {
                $(this).one('click', $.galleryUtility.slideRight).show();
            }).css('z-index',0);
        } else {
            $.galleryUtility.leftImageStorage.image.css('opacity',0.5).animate({
                'bottom': 0,
                'left': $.galleryUtility.Options.gutterWidth,
                'height': $.galleryUtility.leftImageStorage.image.attr('imgheight')/2,
                'width': $.galleryUtility.leftImageStorage.image.attr('imgwidth')/2
            }, $.galleryUtility.Options.slideSpeed, 'linear', function () {
                $(this).one('click', $.galleryUtility.slideRight).show();
            }).css('z-index',0);
        }
        if ($.galleryUtility.leftImage.image.attr('layout') === 'landscape') {
            $.galleryUtility.leftImage.image.unbind().animate({
                'bottom': 0,
                'left': $.galleryUtility.centerImage.Lleft,
                'height': $.galleryUtility.leftImage.image.attr('imgheight'),
                'width': $.galleryUtility.leftImage.image.attr('imgwidth'),
				'opacity': 1
            }, $.galleryUtility.Options.slideSpeed, 'linear').css('z-index',99);
        } else {
            $.galleryUtility.leftImage.image.unbind().animate({
                'bottom': 0,
                'left': $.galleryUtility.centerImage.Pleft,
                'height': $.galleryUtility.leftImage.image.attr('imgheight'),
                'width': $.galleryUtility.leftImage.image.attr('imgwidth'),
				'opacity': 1
            }, $.galleryUtility.Options.slideSpeed, 'linear').css('z-index',99);
        }
        if ($.galleryUtility.centerImage.image.attr('layout') === 'landscape') {
            $.galleryUtility.centerImage.image.unbind().animate({
                'bottom':0,
				'left': $.galleryUtility.Options.container.width()-($.galleryUtility.centerImage.image.attr('imgwidth')/2)-$.galleryUtility.Options.gutterWidth,
                'height': $.galleryUtility.centerImage.image.attr('imgheight')/2,
                'width': $.galleryUtility.centerImage.image.attr('imgwidth')/2,
				'opacity': 0.5
            }, $.galleryUtility.Options.slideSpeed, 'linear', function () {
                $(this).one('click', $.galleryUtility.slideLeft);
            }).css('z-index',0);
        } else {
            $.galleryUtility.centerImage.image.unbind().css('z-index',0).animate({
                'bottom':0,
				'left': $.galleryUtility.Options.container.width()-($.galleryUtility.centerImage.image.attr('imgwidth')/2)-$.galleryUtility.Options.gutterWidth,
                'height': $.galleryUtility.centerImage.image.attr('imgheight')/2,
                'width': $.galleryUtility.centerImage.image.attr('imgwidth')/2,
				'opacity': 0.5
            }, $.galleryUtility.Options.slideSpeed, 'linear', function () {
                $(this).one('click', $.galleryUtility.slideLeft);
            });
        }
        if ($.galleryUtility.rightImage.image.attr('layout') === 'landscape') {
			
            $.galleryUtility.rightImage.image.unbind().hide().animate({
                'bottom':0,
                'left': risLeft,
                'height': $.galleryUtility.rightImageStorage.Lheight,
                'width': $.galleryUtility.rightImageStorage.Lwidth,
                'opacity': 'hide'
            }, $.galleryUtility.Options.slideSpeed, 'linear');
        } else {
            $.galleryUtility.rightImage.image.unbind().hide().animate({
                'bottom':0,
                'left': risLeft,
                'height': $.galleryUtility.rightImageStorage.Pheight,
                'width': $.galleryUtility.rightImageStorage.Pwidth,
                'opacity': 'hide'
            }, $.galleryUtility.Options.slideSpeed, 'linear');
        }
        $.galleryUtility.rightImageStorage.image = $.galleryUtility.rightImage.image;
        $.galleryUtility.rightImage.image = $.galleryUtility.centerImage.image;
        $.galleryUtility.centerImage.image = $.galleryUtility.leftImage.image;
        $.galleryUtility.leftImage.image = $.galleryUtility.leftImageStorage.image;
        $.galleryUtility.setLeftStorage($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.leftImageStorage.image.attr('prev') + ']'));
    };
    $.galleryUtility.slideLeft = function () {
		$('meta[property=og:url]').attr('content', location.host+location.pathname);
		$('meta[property=og:image]').attr('content', $.galleryUtility.centerImage.image.attr('original'));
		var arr = $.galleryUtility.rightImage.image.attr('original').split('/');
				$.address.value(arr[arr.length-1]);  
									$.galleryUtility.CreateNewLikeButton(location.host+location.pathname);
										$('.nextarrow img').unbind().one('click', $.galleryUtility.slideLeft);
		//$('.media-shadow').hide();
		            $.galleryUtility.definePositions($.galleryUtility.rightImage, $.galleryUtility.centerImage ,$.galleryUtility.rightImageStorage);
        var lisLeft = $.galleryUtility.leftImageStorage.left($.galleryUtility.leftImage.image, $.galleryUtility.centerImage.image, $.galleryUtility.rightImage.image);
							if($.galleryUtility.Options.lazy == true){
							if ($.galleryUtility.rightImageStorage.image.attr('src')!=$.galleryUtility.rightImageStorage.image.attr('original')){
				$.galleryUtility.rightImageStorage.image.attr('src', $.galleryUtility.rightImageStorage.image.attr('original'));
		}
							}
        if ($.galleryUtility.rightImageStorage.image.attr('layout') === 'landscape') {
            $.galleryUtility.rightImageStorage.image.css('opacity',0.5).animate({
                'bottom':0,
				'left': $.galleryUtility.Options.container.width()-($.galleryUtility.rightImageStorage.image.attr('imgwidth')/2)-$.galleryUtility.Options.gutterWidth,
                'height': $.galleryUtility.rightImageStorage.image.attr('imgheight')/2,
                'width': $.galleryUtility.rightImageStorage.image.attr('imgwidth')/2
            }, $.galleryUtility.Options.slideSpeed, 'linear', function () {
                $(this).one('click', $.galleryUtility.slideLeft).show();
            }).css('z-index',0);
        } else {
            $.galleryUtility.rightImageStorage.image.css('opacity',0.5).animate({
                'bottom':0,
				'left': $.galleryUtility.Options.container.width()-($.galleryUtility.rightImageStorage.image.attr('imgwidth')/2)-$.galleryUtility.Options.gutterWidth,
               'height': $.galleryUtility.rightImageStorage.image.attr('imgheight')/2,
                'width': $.galleryUtility.rightImageStorage.image.attr('imgwidth')/2
            }, $.galleryUtility.Options.slideSpeed, 'linear', function () {
                $(this).one('click', $.galleryUtility.slideLeft).show();
            }).css('z-index',0);
        }
        if ($.galleryUtility.rightImage.image.attr('layout') === 'landscape') {
            $.galleryUtility.rightImage.image.unbind().css('z-index',99).animate({
                'bottom':0,
                'left': $.galleryUtility.centerImage.Lleft,
               'height': $.galleryUtility.rightImage.image.attr('imgheight'),
                'width': $.galleryUtility.rightImage.image.attr('imgwidth'),
				'opacity': 1
            }, $.galleryUtility.Options.slideSpeed, 'linear').css('z-index',99);
        } else {
            $.galleryUtility.rightImage.image.unbind().animate({
                'bottom':0,
                'left': $.galleryUtility.centerImage.Pleft,
               'height': $.galleryUtility.rightImage.image.attr('imgheight'),
                'width': $.galleryUtility.rightImage.image.attr('imgwidth'),
				'opacity': 1
            }, $.galleryUtility.Options.slideSpeed, 'linear').css('z-index',99);
        }
        if ($.galleryUtility.centerImage.image.attr('layout') === 'landscape') {
            $.galleryUtility.centerImage.image.unbind().animate({
                'bottom':0,
                'left': $.galleryUtility.Options.gutterWidth,
               'height': $.galleryUtility.centerImage.image.attr('imgheight')/2,
                'width': $.galleryUtility.centerImage.image.attr('imgwidth')/2,
				'opacity': 0.5
            }, $.galleryUtility.Options.slideSpeed, 'linear', function () {
                $(this).one('click', $.galleryUtility.slideRight);
            }).css('z-index',0);
        } else {
            $.galleryUtility.centerImage.image.unbind().animate({
                'bottom':0,
                'left': $.galleryUtility.Options.gutterWidth,
               'height': $.galleryUtility.centerImage.image.attr('imgheight')/2,
                'width': $.galleryUtility.centerImage.image.attr('imgwidth')/2,
				'opacity': 0.5
            }, $.galleryUtility.Options.slideSpeed, 'linear', function () {
                $(this).one('click', $.galleryUtility.slideRight);
            }).css('z-index',0);
        }
        if ($.galleryUtility.leftImage.image.attr('layout') === 'landscape') {
            $.galleryUtility.leftImage.image.unbind().hide().animate({
                'bottom':0,
                'left': lisLeft,
                'height': $.galleryUtility.leftImageStorage.Lheight,
                'width': $.galleryUtility.leftImageStorage.Lwidth,
                'opacity': 'hide'
            }, $.galleryUtility.Options.slideSpeed, 'linear');
        } else {
            $.galleryUtility.leftImage.image.unbind().hide().animate({
                'bottom':0,
                'left': lisLeft,
                'height': $.galleryUtility.leftImageStorage.Pheight,
                'width': $.galleryUtility.leftImageStorage.Pwidth,
                'opacity': 'hide'
            }, $.galleryUtility.Options.slideSpeed, 'linear');
        }
        $.galleryUtility.leftImageStorage.image = $.galleryUtility.leftImage.image;
        $.galleryUtility.leftImage.image = $.galleryUtility.centerImage.image;
        $.galleryUtility.centerImage.image = $.galleryUtility.rightImage.image;
        $.galleryUtility.rightImage.image = $.galleryUtility.rightImageStorage.image;
        $.galleryUtility.setRightStorage($.galleryUtility.gallery.filter('[index=' + $.galleryUtility.rightImageStorage.image.attr('next') + ']'));
    };
    $.galleryUtility.zoomIn = function () {
        $.galleryUtility.gallery.unbind();
        if ($.galleryUtility.centerImage.image.attr('layout') === 'landscape') {
            $.galleryUtility.centerImage.image.css('z-index', '99').animate({
                'bottom':0,
                'left': $.galleryUtility.zoomImage.Lleft,
                'height': $.galleryUtility.zoomImage.Lheight,
                'width': $.galleryUtility.zoomImage.Lwidth
            }, $.galleryUtility.Options.zoomSpeed, 'linear', function () {
                if ($.galleryUtility.Options.useCaptions) {
                    $('#' + $.galleryUtility.Options.captionDownID).css({
                        'height': 0,
                        'bottom':0,
                        'left': $.galleryUtility.zoomImage.Lleft + ($.galleryUtility.zoomImage.Lwidth - $.galleryUtility.Options.captionDownWidth) + parseInt($.galleryUtility.centerImage.image.css('borderLeftWidth'), 10),
                        'z-index': 1000,
                        'position': 'absolute'
                    }).show().animate({
                        'height': $.galleryUtility.Options.captionDownHeight
                    }, 'fast', 'linear', function () {
                        $('#' + $.galleryUtility.Options.captionDownID).one('click', $.galleryUtility.LcaptionDown);
                    });
                }
            });
        } else {
            $.galleryUtility.centerImage.image.css('z-index', '99').animate({
                'bottom':0,
                'left': $.galleryUtility.zoomImage.Pleft,
                'height': $.galleryUtility.zoomImage.Pheight,
                'width': $.galleryUtility.zoomImage.Pwidth
            }, $.galleryUtility.Options.zoomSpeed, 'linear', function () {
                if ($.galleryUtility.Options.useCaptions) {
                    $('#' + $.galleryUtility.Options.captionDownID).css({
                        'height': 0,
                        'bottom':0,
                        'left': $.galleryUtility.zoomImage.Pleft + ($.galleryUtility.zoomImage.Pwidth - $.galleryUtility.Options.captionDownWidth) + parseInt($.galleryUtility.centerImage.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);
                    });
                }
            });
        }
    };
    $.galleryUtility.LcaptionDown = function () {
        $.galleryUtility.centerImage.image.unbind();
        $.galleryUtility.Options.container.append('<span id="' + $.galleryUtility.Options.captionID + '" style="' + $.galleryUtility.Options.captionStyle + '" class="' + $.galleryUtility.Options.captionClass + '">' + $.galleryUtility.centerImage.image.attr($.galleryUtility.Options.captionTextAttribute) + '</span>');
        $('#' + $.galleryUtility.Options.captionID).css({
            'bottom':0,
            'left': $.galleryUtility.zoomImage.Lleft + parseInt($.galleryUtility.centerImage.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,
            'bottom':0
        }, 'normal', 'linear', function () {
            $('#' + $.galleryUtility.Options.captionDownID).hide();
        });
        $('#' + $.galleryUtility.Options.captionUpID).css({
            'bottom':0,
            'left': $.galleryUtility.zoomImage.Lleft + ($.galleryUtility.zoomImage.Lwidth - $.galleryUtility.Options.captionUpWidth) + parseInt($.galleryUtility.centerImage.image.css('borderLeftWidth'), 10),
            'height': 0,
            'position': 'absolute',
            'z-index': '100'
        }).show().animate({
            'bottom':0,
            'height': $.galleryUtility.Options.captionUpHeight
        }, 'normal', 'linear', function () {
            $('#' + $.galleryUtility.Options.captionUpID).one('click', function () {
                $.galleryUtility.LcaptionUp(false);
            });
        });
    };
    $.galleryUtility.PcaptionDown = function () {
        $.galleryUtility.centerImage.image.unbind();
        $.galleryUtility.Options.container.append('<span id="' + $.galleryUtility.Options.captionID + '" style="' + $.galleryUtility.Options.captionStyle + '" class="' + $.galleryUtility.Options.captionClass + '">' + $.galleryUtility.centerImage.image.attr($.galleryUtility.Options.captionTextAttribute) + '</span>');
        $('#' + $.galleryUtility.Options.captionID).css({
            'bottom':0,
            'left': $.galleryUtility.zoomImage.Pleft + parseInt($.galleryUtility.centerImage.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,
            'bottom':0
        }, 'normal', 'linear', function () {
            $('#' + $.galleryUtility.Options.captionDownID).hide();
        });
        $('#' + $.galleryUtility.Options.captionUpID).css({
            'bottom':0,
            'left': $.galleryUtility.zoomImage.Pleft + ($.galleryUtility.zoomImage.Pwidth - $.galleryUtility.Options.captionUpWidth) + parseInt($.galleryUtility.centerImage.image.css('borderLeftWidth'), 10),
            'height': 0,
            'position': 'absolute',
            'z-index': '100'
        }).show().animate({
            'bottom':0,
            'height': $.galleryUtility.Options.captionUpHeight
        }, 'normal', 'linear', function () {
            $('#' + $.galleryUtility.Options.captionUpID).one('click', function () {
                $.galleryUtility.PcaptionUp(false);
            });
        });
    };
    $.galleryUtility.LcaptionUp = function (unzoom) {
        $('#' + $.galleryUtility.Options.captionID).animate({
            'height': 0
        }, 'normal', 'linear', function () {
            $('#' + $.galleryUtility.Options.captionID).remove();
        });
        $('#' + $.galleryUtility.Options.captionUpID).animate({
            'bottom':0,
            'height': 0
        }, 'normal', 'linear', function () {
            $('#' + $.galleryUtility.Options.captionUpID).hide();
        });
        $('#' + $.galleryUtility.Options.captionDownID).show().animate({
            'height': $.galleryUtility.Options.captionDownHeight,
            'bottom':0
        }, 'normal', 'linear', function () {
            if (unzoom) {
                $('#' + $.galleryUtility.Options.captionUpID).unbind();
                $.galleryUtility.zoomOut();
            } else {
                $('#' + $.galleryUtility.Options.captionDownID).one('click', $.galleryUtility.LcaptionDown);
            }
        });
    };
    $.galleryUtility.PcaptionUp = function (unzoom) {
        $('#' + $.galleryUtility.Options.captionID).animate({
            'height': 0
        }, 'normal', 'linear', function () {
            $('#' + $.galleryUtility.Options.captionID).remove();
        });
        $('#' + $.galleryUtility.Options.captionUpID).animate({
            'bottom':0,
            'height': 0
        }, 'normal', 'linear', function () {
            $('#' + $.galleryUtility.Options.captionUpID).hide();
        });
        $('#' + $.galleryUtility.Options.captionDownID).show().animate({
            'height': $.galleryUtility.Options.captionDownHeight,
            'bottom':0
        }, 'normal', 'linear', function () {
            if (unzoom) {
                $('#' + $.galleryUtility.Options.captionUpID).unbind();
                $.galleryUtility.zoomOut();
            } else {
                $('#' + $.galleryUtility.Options.captionDownID).one('click', $.galleryUtility.PcaptionDown);
            }
        });
    };
    $.galleryUtility.zoomOut = function () {
        if ($.galleryUtility.Options.useCaptions) {
            $('#' + $.galleryUtility.Options.captionDownID).animate({
                'height': 0
            }, 50, 'linear', $.galleryUtility.zoomOutBody).unbind();
        } else {
            $.galleryUtility.zoomOutBody();
        }
    };
    $.galleryUtility.zoomOutBody = function () {
        if ($.galleryUtility.centerImage.image.attr('layout') === 'landscape') {
            $.galleryUtility.centerImage.image.animate({
                'bottom':0,
                'left': $.galleryUtility.centerImage.Lleft,
                'height': $.galleryUtility.centerImage.Lheight,
                'width': $.galleryUtility.centerImage.Lwidth
            }, $.galleryUtility.Options.zoomSpeed, 'linear', function () {
                $(this).css('z-index', '0');
                $.galleryUtility.leftImage.image.one('click', $.galleryUtility.slideRight);
                $.galleryUtility.rightImage.image.one('click', $.galleryUtility.slideLeft);
            });
        } else {
            $.galleryUtility.centerImage.image.animate({
                'bottom':0,
                'left': $.galleryUtility.centerImage.Pleft,
                'height': $.galleryUtility.centerImage.Pheight,
                'width': $.galleryUtility.centerImage.Pwidth
            }, $.galleryUtility.Options.zoomSpeed, 'linear', function () {
                $(this).css('z-index', '0');
                $.galleryUtility.leftImage.image.one('click', $.galleryUtility.slideRight);
                $.galleryUtility.rightImage.image.one('click', $.galleryUtility.slideLeft);
            });
        }
    };
    $.galleryUtility.setRightStorage = function (image) {
        $.galleryUtility.rightImageStorage.image = image;
        if ($.galleryUtility.rightImageStorage.image.attr('layout') === 'landscape') {
            $.galleryUtility.rightImageStorage.image.hide().css({
                'bottom':0,
                'height': $.galleryUtility.rightImageStorage.Lheight,
                'width': $.galleryUtility.rightImageStorage.Lwidth
            });
        } else {
            $.galleryUtility.rightImageStorage.image.hide().css({
                'bottom':0,
                'height': $.galleryUtility.rightImageStorage.Pheight,
                'width': $.galleryUtility.rightImageStorage.Pwidth
            });
        }
        $.galleryUtility.rightImageStorage.image.css('left', $.galleryUtility.rightImageStorage.left($.galleryUtility.rightImage.image, $.galleryUtility.centerImage.image));
    };
    $.galleryUtility.setLeftStorage = function (image) {
        $.galleryUtility.leftImageStorage.image = image;
        if ($.galleryUtility.leftImageStorage.image.attr('layout') === 'landscape') {
            $.galleryUtility.leftImageStorage.image.hide().css({
                'bottom':0,
                'height': $.galleryUtility.leftImageStorage.Lheight,
                'width': $.galleryUtility.leftImageStorage.Lwidth
            });
        } else {
            $.galleryUtility.leftImageStorage.image.hide().css({
                'bottom':0,
                'height': $.galleryUtility.leftImageStorage.Pheight,
                'width': $.galleryUtility.leftImageStorage.Pwidth
            });
        }
        $.galleryUtility.leftImageStorage.image.css('left', $.galleryUtility.leftImageStorage.left($.galleryUtility.leftImageStorage.image, $.galleryUtility.leftImage.image, $.galleryUtility.centerImage.image));
    };
	$.galleryUtility.defineImg = function (center){
		$.galleryUtility.centerImage.image = center;
		if($.galleryUtility.centerImage.image.attr('prev') == -1){
			$.galleryUtility.centerImage.image.attr('prev', $.galleryUtility.gallery.length-1);
		}
		if($.galleryUtility.centerImage.image.attr('next') > $.galleryUtility.gallery.length-1){
			$.galleryUtility.centerImage.image.attr('next', 0);
		}
		$.galleryUtility.leftImage.image = $.galleryUtility.gallery.filter('[index=' + $.galleryUtility.centerImage.image.attr('prev') + ']');
		$.galleryUtility.rightImage.image = $.galleryUtility.gallery.filter('[index=' + $.galleryUtility.centerImage.image.attr('next') + ']');
	}
    $.galleryUtility.setCenter = function (image) {
							if($.galleryUtility.Options.lazy == true){
						$.galleryUtility.centerImage.image.attr('src', $.galleryUtility.centerImage.image.attr('original'));
							}
        if ($.galleryUtility.centerImage.image.attr('layout') === 'landscape') {
            $.galleryUtility.centerImage.image.css({
                'bottom':0,
                'left': $.galleryUtility.centerImage.Lleft,
                'height': $.galleryUtility.centerImage.image.attr('imgheight'),
                'width': $.galleryUtility.centerImage.image.attr('imgwidth'),
				'z-index': 99,
				'opacity':1
            }).show();
        } else {
            $.galleryUtility.centerImage.image.css({
                'bottom':0,
                'left': $.galleryUtility.centerImage.Pleft,
                'height': $.galleryUtility.centerImage.image.attr('imgheight'),
                'width': $.galleryUtility.centerImage.image.attr('imgwidth'),
				'z-index': 99,
				'opacity':1
            }).show();
        }
    };
    $.galleryUtility.setRight = function (image) {
							if($.galleryUtility.Options.lazy == true){
						$.galleryUtility.rightImage.image.attr('src', $.galleryUtility.rightImage.image.attr('original'));
							}
        if ($.galleryUtility.rightImage.image.attr('layout') === 'landscape') {
            $.galleryUtility.rightImage.image.css({
                'bottom':0,
                'height': $.galleryUtility.rightImage.image.attr('imgheight')/2,
                'width': $.galleryUtility.rightImage.image.attr('imgwidth')/2,
				'z-index': 0,
				'opacity':0.5
            });
        } else {
            $.galleryUtility.rightImage.image.css({
                'bottom':0,
                'height': $.galleryUtility.rightImage.image.attr('imgheight')/2,
                'width': $.galleryUtility.rightImage.image.attr('imgwidth')/2,
				'z-index': 0,
				'opacity':0.5
            });
        }
        $.galleryUtility.rightImage.image.css('left', $.galleryUtility.Options.container.width()-($.galleryUtility.rightImage.image.attr('imgwidth')/2)-$.galleryUtility.Options.gutterWidth).show();
    };
    $.galleryUtility.setLeft = function (image) {
							if($.galleryUtility.Options.lazy == true){
				$.galleryUtility.leftImage.image.attr('src', $.galleryUtility.leftImage.image.attr('original'));
							}
        if ($.galleryUtility.leftImage.image.attr('layout') === 'landscape') {
            $.galleryUtility.leftImage.image.css({
                'bottom':0,
                'height': $.galleryUtility.leftImage.image.attr('imgheight')/2,
                'width': $.galleryUtility.leftImage.image.attr('imgwidth')/2,
				'z-index': 0,
				'opacity':0.5
            });
        } else {
            $.galleryUtility.leftImage.image.css({
                'bottom':0,
                'height': $.galleryUtility.leftImage.image.attr('imgheight')/2,
                'width': $.galleryUtility.leftImage.image.attr('imgwidth')/2,
				'z-index': 0,
				'opacity':0.5
            });
        }
        $.galleryUtility.leftImage.image.css('left',$.galleryUtility.Options.gutterWidth).show();
    };
    $.galleryUtility.definePositions = function (referenceimg, leftrefimg, rightrefimg) {
		  if (typeof referenceimg == "undefined") {
    referenceimg = $.galleryUtility.centerImage;
  }
  		  if (typeof rightrefimg == "undefined") {
    rightrefimg = $.galleryUtility.rightImage;
  }
    		  if (typeof leftrefimg == "undefined") {
    leftrefimg = $.galleryUtility.leftImage;
  }
        var container = $.galleryUtility.Options.container;
        if (container[0].tagName == 'BODY') {
            container = $(window);
        }
        var Gheight = container.height();
        var Gwidth = container.width();
        $.galleryUtility.centerImage.Lheight = Math.round(referenceimg.image.attr('imgheight'));
        $.galleryUtility.centerImage.Lwidth = Math.round(referenceimg.image.attr('imgwidth'));
        $.galleryUtility.centerImage.Lleft = Math.round(Gwidth / 2) - ($.galleryUtility.centerImage.Lwidth / 2);
        $.galleryUtility.centerImage.Pheight = Math.round(referenceimg.image.attr('imgheight'));
        $.galleryUtility.centerImage.Pwidth = Math.round(referenceimg.image.attr('imgwidth'));
        $.galleryUtility.centerImage.Pleft = Math.round((Gwidth / 2) - ($.galleryUtility.centerImage.Pwidth / 2));
        $.galleryUtility.zoomImage.Lheight = Math.round($.galleryUtility.Options.Lzoom($.galleryUtility.centerImage.Lheight));
        $.galleryUtility.zoomImage.Lwidth = Math.round($.galleryUtility.Options.Lzoom($.galleryUtility.centerImage.Lwidth));
        $.galleryUtility.zoomImage.Lleft = Math.round((Gwidth / 2) - ($.galleryUtility.zoomImage.Lwidth / 2));
        $.galleryUtility.zoomImage.Pheight = Math.round($.galleryUtility.Options.Pzoom($.galleryUtility.centerImage.Pheight));
        $.galleryUtility.zoomImage.Pwidth = Math.round($.galleryUtility.Options.Pzoom($.galleryUtility.centerImage.Pwidth));
        $.galleryUtility.zoomImage.Pleft = Math.round((Gwidth / 2) - ($.galleryUtility.zoomImage.Pwidth / 2));
        $.galleryUtility.leftImage.Lheight = $.galleryUtility.leftImage.Pheight = Math.round(leftrefimg.image.attr('imgheight'));
        $.galleryUtility.leftImage.Lwidth = $.galleryUtility.leftImage.Pwidth = Math.round(leftrefimg.image.attr('imgwidth'));
        $.galleryUtility.leftImage.left = function (left, center) {
            if (center.attr('layout') == 'landscape') {
				return Math.round($.galleryUtility.centerImage.Lleft - $.galleryUtility.Options.gutterWidth);
               /* if (left.attr('layout') === 'landscape') {
                    return Math.round($.galleryUtility.centerImage.Lleft - ($.galleryUtility.leftImage.Lwidth + $.galleryUtility.Options.gutterWidth));
                } else {
                    return Math.round($.galleryUtility.centerImage.Lleft - ($.galleryUtility.leftImage.Pwidth + $.galleryUtility.Options.gutterWidth));
                }*/
            } else {
				return Math.round($.galleryUtility.centerImage.Pleft - $.galleryUtility.Options.gutterWidth);
               /*if (left.attr('layout') === 'landscape') {
                    return Math.round($.galleryUtility.centerImage.Pleft - ($.galleryUtility.leftImage.Lwidth + $.galleryUtility.Options.gutterWidth));
                } else {
                    return Math.round($.galleryUtility.centerImage.Pleft - ($.galleryUtility.leftImage.Pwidth + $.galleryUtility.Options.gutterWidth));
                }*/
            }
        };
        $.galleryUtility.rightImage.Lheight = $.galleryUtility.rightImage.Pheight =  Math.round(rightrefimg.image.attr('imgheight'));
        $.galleryUtility.rightImage.Lwidth = $.galleryUtility.rightImage.Pwidth  = Math.round(rightrefimg.image.attr('imgwidth'));
        $.galleryUtility.rightImage.left = function (right, center) {
            if (center.attr('layout') == 'landscape') {
				if(right.attr('layout') == 'landscape'){
                return Math.round($.galleryUtility.centerImage.Lleft + $.galleryUtility.centerImage.Lwidth - ($.galleryUtility.rightImage.Lwidth/2) + $.galleryUtility.Options.gutterWidth);
				}else{
				return Math.round($.galleryUtility.centerImage.Lleft + $.galleryUtility.centerImage.Lwidth - ($.galleryUtility.rightImage.Pwidth/2) + $.galleryUtility.Options.gutterWidth);
				}
            } else {
							if(right.attr('layout') == 'landscape'){
                return Math.round($.galleryUtility.centerImage.Pleft + $.galleryUtility.centerImage.Pwidth - ($.galleryUtility.rightImage.Lwidth/2) + $.galleryUtility.Options.gutterWidth);
								}else{
				return Math.round($.galleryUtility.centerImage.Pleft + $.galleryUtility.centerImage.Pwidth - ($.galleryUtility.rightImage.Pwidth/2) + $.galleryUtility.Options.gutterWidth);
				}
            }
        };
        $.galleryUtility.leftImageStorage.Lheight = Math.round($.galleryUtility.Options.Lshrink($.galleryUtility.leftImage.Lheight));
        $.galleryUtility.leftImageStorage.Lwidth = Math.round($.galleryUtility.Options.Lshrink($.galleryUtility.leftImage.Lwidth));
        $.galleryUtility.leftImageStorage.left = function (leftStorage, left, center) {
            if (leftStorage.attr('layout') == 'landscape') {
                return Math.round($.galleryUtility.leftImage.left(left, center) - ($.galleryUtility.leftImageStorage.Lwidth + $.galleryUtility.Options.gutterWidth));
            } else {
                return Math.round($.galleryUtility.leftImage.left(left, center) - ($.galleryUtility.leftImageStorage.Pwidth + $.galleryUtility.Options.gutterWidth));
            }
        };
        $.galleryUtility.leftImageStorage.Pheight = Math.round($.galleryUtility.Options.Pshrink($.galleryUtility.leftImage.Pheight));
        $.galleryUtility.leftImageStorage.Pwidth = Math.round($.galleryUtility.Options.Pshrink($.galleryUtility.leftImage.Pwidth));
        $.galleryUtility.rightImageStorage.Lheight = Math.round($.galleryUtility.Options.Lshrink($.galleryUtility.rightImage.Lheight));
        $.galleryUtility.rightImageStorage.Lwidth = Math.round($.galleryUtility.Options.Lshrink($.galleryUtility.rightImage.Lwidth));
        $.galleryUtility.rightImageStorage.left = function (right, center) {
            if (right.attr('layout') == 'landscape') {
                return Math.round($.galleryUtility.rightImage.left(right, center) + ($.galleryUtility.rightImage.Lwidth + $.galleryUtility.Options.gutterWidth));
            } else {
                return Math.round($.galleryUtility.rightImage.left(right, center) + ($.galleryUtility.rightImage.Pwidth + $.galleryUtility.Options.gutterWidth));
            }
        };
        $.galleryUtility.rightImageStorage.Pheight = Math.round($.galleryUtility.Options.Pshrink($.galleryUtility.rightImage.Pheight));
        $.galleryUtility.rightImageStorage.Pwidth = Math.round($.galleryUtility.Options.Pshrink($.galleryUtility.rightImage.Pwidth));
    };
	$.galleryUtility.CreateNewLikeButton = function (url)
        {
            var elem = $(document.createElement("fb:like"));
            elem.attr("href", url);
			elem.attr("send","false");elem.attr("layout","button_count");elem.attr("width","90");elem.attr("show_faces","false");elem.attr("font","lucida grande");
            $("div#fblike").empty().append(elem);
            FB.XFBML.parse($("div#fblike").get(0));
        }
})(jQuery);;
/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */

(function(jQuery){

	// We override the animation for all of these color styles
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}

			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});

	// Color Conversion functions from highlightFade
	// By Blair Mitchelmore
	// http://jquery.offput.ca/highlightFade/

	// Parse strings looking for color tuples [255,255,255]
	function getRGB(color) {
		var result;

		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
			return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		// Otherwise, we're most likely dealing with a named color
		return colors[jQuery.trim(color).toLowerCase()];
	}
	
	function getColor(elem, attr) {
		var color;

		do {
			color = jQuery.curCSS(elem, attr);

			// Keep going until we find an element that has color, or we hit the body
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break; 

			attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
	};
	
	// Some named colors to work with
	// From Interface by Stefan Petre
	// http://interface.eyecon.ro/

	var colors = {
		aqua:[0,255,255],
		azure:[240,255,255],
		beige:[245,245,220],
		black:[0,0,0],
		blue:[0,0,255],
		brown:[165,42,42],
		cyan:[0,255,255],
		darkblue:[0,0,139],
		darkcyan:[0,139,139],
		darkgrey:[169,169,169],
		darkgreen:[0,100,0],
		darkkhaki:[189,183,107],
		darkmagenta:[139,0,139],
		darkolivegreen:[85,107,47],
		darkorange:[255,140,0],
		darkorchid:[153,50,204],
		darkred:[139,0,0],
		darksalmon:[233,150,122],
		darkviolet:[148,0,211],
		fuchsia:[255,0,255],
		gold:[255,215,0],
		green:[0,128,0],
		indigo:[75,0,130],
		khaki:[240,230,140],
		lightblue:[173,216,230],
		lightcyan:[224,255,255],
		lightgreen:[144,238,144],
		lightgrey:[211,211,211],
		lightpink:[255,182,193],
		lightyellow:[255,255,224],
		lime:[0,255,0],
		magenta:[255,0,255],
		maroon:[128,0,0],
		navy:[0,0,128],
		olive:[128,128,0],
		orange:[255,165,0],
		pink:[255,192,203],
		purple:[128,0,128],
		violet:[128,0,128],
		red:[255,0,0],
		silver:[192,192,192],
		white:[255,255,255],
		yellow:[255,255,0]
	};
	
})(jQuery);
;
jQuery.fn.clearForm = function() {
      return this.each(function() {
        var type = this.type, tag = this.tagName.toLowerCase();
        if (tag == 'form')
          return jQuery(':input',this).clearForm();
        if (type == 'text' || type == 'password' || tag == 'textarea')
          this.value = '';
        else if (type == 'checkbox' || type == 'radio')
          this.checked = false;
        else if (tag == 'select')
          this.selectedIndex = -1;
      });
    };

jQuery(document).ready(function ($) {
	$('form').clearForm();
	var maximgheight = 300;
    if ($('div#myMediaFlow').length != 0) {
        var pic_real_width, pic_real_height;
        var img = $("div#myMediaFlow img").each(function (y) {; // Get my img elem
            if ($(this).width() && $(this).width() != 0) {
                $(this).attr({
                    'imgwidth': $(this).width(),
                    'imgheight': $(this).height()
                });
							maximgheight = maximgheight < $(this).height() ? $(this).height() : maximgheight;
            } else {
                $("<img/>") // Make in memory copy of image to avoid css issues
                .attr("src", $(this).attr("src")).load(function () {
                    $(this).attr({
                        'imgwidth': this.width,
                        'imgheight': this.height,
                        'width': this.width,
                        'height': this.height
                    });
                });
							maximgheight = maximgheight < this.height ? this.height : maximgheight;
                // attribute does not exist
            }
        });
        $('div#myMediaFlow img').slidingGallery({
            container: $('div#myMediaFlow'),
            'gutterWidth': 10,
            'clickappear': false,
'lazy':false,
			'bgcolor':'#000',
			'containerheight':maximgheight
        });
		

    }


    if ($('div#myGalleryFlow').length != 0) {
        var pic_real_width, pic_real_height;
        var img = $("div#myGalleryFlow img").each(function (y) {; // Get my img elem
            if ($(this).width() && $(this).width() != 0) {
                $(this).attr({
                    'imgwidth': $(this).width(),
                    'imgheight': $(this).height()
                });
				maximgheight = maximgheight <  $(this).height() ?  $(this).height() : maximgheight;
            } else {

                $("<img/>") // Make in memory copy of image to avoid css issues
                .attr("src", $(this).attr("original")).load(function () {
                    $(this).attr({
                        'imgwidth': this.width,
                        'imgheight': this.height,
                        'width': this.width,
                        'height': this.height
                    });
					maximgheight = maximgheight < this.height ? this.height : maximgheight;
                });
                // attribute does not exist
            }
		});
			        $('div#myGalleryFlow').hide();
        $('div#myGalleryFlow img').slidingGallery({
            container: $('div#myGalleryFlow'),
            'gutterWidth': 10,
						'containerheight':maximgheight,
						'bgcolor':'#000'
        });	
		
    }
    $('ul#main-menu li a').hover(function () {
        $(this).stop().animate({
            'font-size': '120%',
            'color': '#e498a9'
        }, {
            duration: 300
        });
    }, function () {
        $(this).stop().animate({
            'font-size': '100%',
            'color': '#4a1322'
        }, {
            duration: 100
        });
    });

    $('#location-list li.views-row').hover(function () {
        $(this).find('.title-overlay').stop().animate({
            'height': '75px'
        }, {
            duration: 300
        }).find('h3').stop().animate({
            'font-size': '120%'
        }, {
            duration: 200
        });
        var hoverImg = HoverImgOf($(this).find('.locationlistimg').attr("src"));
        $(this).find('.locationlistimg').attr("src", hoverImg);
    }, function () {
        $(this).find('.title-overlay').stop().animate({
            'height': '50px'
        }, {
            duration: 300
        }).find('h3').stop().animate({
            'font-size': '100%'
        }, {
            duration: 200
        });
        var normalImg = NormalImgOf($(this).find('.locationlistimg').attr("src"));
        $(this).find('.locationlistimg').attr("src", normalImg);
    });

    $('.view-packages li.views-row').hover(function () {
        $(this).find('.views-field-title').stop().animate({
            'height': '75px'
        }, {
            duration: 300
        }).find('h3 a').stop().animate({
            'font-size': '120%'
        }, {
            duration: 200
        });
    }, function () {
        $(this).find('.views-field-title').stop().animate({
            'height': '50px'
        }, {
            duration: 300
        }).find('h3 a').stop().animate({
            'font-size': '100%'
        }, {
            duration: 200
        });
    });

    $('.media-gallery-collection .tabs-weddingday, .media-gallery-collection .tabs-prewedding').click(function () {
        window.location = $(this).find('a.media-gallery-thumb').attr('href');
    });
    $('.media-gallery-collection .tabs-weddingday, .media-gallery-collection .tabs-prewedding').hover(function () {
        $(this).find('.meta-wrapper').stop().animate({
            'height': '75px'
        }, {
            duration: 300
        }).find('.media-title').stop().animate({
            'font-size': '120%'
        }, {
            duration: 200
        });
    }, function () {
        $(this).find('.meta-wrapper').stop().animate({
            'height': '50px'
        }, {
            duration: 300
        }).find('.media-title').stop().animate({
            'font-size': '100%'
        }, {
            duration: 200
        });
    });

    $('.morelocationbtn').click(function () {
        $('.morelocation').slideToggle("slow");;
    });
    var hash = window.location.hash;
    hash = !hash ? '#prewedding' : hash;
    //$('.back-btn').parent().attr('href',$('.back-btn').parent().attr()+"hash");
    if (hash == "#prewedding") {
        $('.tabs-weddingday').hide();
        $('.tabs-prewedding').show().css('float', 'left');
        $('#weddingday_btn > a').css({
            'border-bottom': 'none'
        });
        $('#prewedding_btn > a').css({
            'border-bottom': '2px solid white'
        });
    } else if (hash == "#weddingday") {
        $('.tabs-prewedding').hide();
        $('.tabs-weddingday').show().css('float', 'left');
        $('#prewedding_btn > a').css({
            'border-bottom': 'none'
        });
        $('#weddingday_btn > a').css({
            'border-bottom': '2px solid white'
        });
    } else {
        $('.tabs-weddingday').hide();
        $('.tabs-prewedding').show().css('float', 'left');
    }
    $('.tabs-weddingday').each(function () {
        $(this).find('a').attr('href', $(this).find('a').attr('href') + "#weddingday");
    });
    $('.tabs-prewedding').each(function () {
        $(this).find('a').attr('href', $(this).find('a').attr('href') + "#prewedding");
    });
    $('#prewedding_btn').click(function () {
        $('.tabs-weddingday').hide();
        $('.tabs-prewedding').css('float', 'left').fadeIn();
        $('#weddingday_btn > a').css({
            'border-bottom': 'none'
        });
        $('#prewedding_btn > a').css({
            'border-bottom': '2px solid white'
        });

    });
    $('#weddingday_btn').click(function () {
        $('.tabs-prewedding').hide();
        $('.tabs-weddingday').css('float', 'left').fadeIn();
        $('#prewedding_btn > a').css({
            'border-bottom': 'none'
        });
        $('#weddingday_btn > a').css({
            'border-bottom': '2px solid white'
        });

    });
	$.address.history(0);
	$.address.init(function(event) {
		$('.field-name-media-gallery-media a.media-gallery-thumb').address(function() {
			var arr = $(this).find('img').attr('src').split('/');
		    return arr[arr.length-1];  
		});
		if(endsWith(window.location.hash,'.jpg')){
		$('.field-name-media-gallery-media a.media-gallery-thumb').first().trigger('ajax', window.location.hash);
		}
	});
	function endsWith(str, suffix) {
    return str.indexOf(suffix, str.length - suffix.length) !== -1;
}

function HoverImgOf(filename) {
    return filename.replace('desaturated_location', 'location_thumb');
}

function NormalImgOf(filename) {
    return filename.replace('location_thumb', 'desaturated_location');
}

});;
/*
 * jQuery Address Plugin v1.4
 * http://www.asual.com/jquery/address/
 *
 * Copyright (c) 2009-2010 Rostislav Hristov
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * Date: 2011-05-04 14:22:12 +0300 (Wed, 04 May 2011)
 */
(function(c){c.address=function(){var v=function(a){c(c.address).trigger(c.extend(c.Event(a),function(){for(var b={},e=c.address.parameterNames(),f=0,p=e.length;f<p;f++)b[e[f]]=c.address.parameter(e[f]);return{value:c.address.value(),path:c.address.path(),pathNames:c.address.pathNames(),parameterNames:e,parameters:b,queryString:c.address.queryString()}}.call(c.address)))},w=function(){c().bind.apply(c(c.address),Array.prototype.slice.call(arguments));return c.address},r=function(){return M.pushState&&
d.state!==k},s=function(){return("/"+g.pathname.replace(new RegExp(d.state),"")+g.search+(D()?"#"+D():"")).replace(U,"/")},D=function(){var a=g.href.indexOf("#");return a!=-1?B(g.href.substr(a+1),l):""},u=function(){return r()?s():D()},ha=function(){return"javascript"},N=function(a){a=a.toString();return(d.strict&&a.substr(0,1)!="/"?"/":"")+a},B=function(a,b){if(d.crawlable&&b)return(a!==""?"!":"")+a;return a.replace(/^\!/,"")},x=function(a,b){return parseInt(a.css(b),10)},V=function(a){for(var b,
e,f=0,p=a.childNodes.length;f<p;f++){try{if("src"in a.childNodes[f]&&a.childNodes[f].src)b=String(a.childNodes[f].src)}catch(J){}if(e=V(a.childNodes[f]))b=e}return b},F=function(){if(!K){var a=u();if(h!=a)if(y&&q<7)g.reload();else{y&&q<8&&d.history&&t(O,50);h=a;E(l)}}},E=function(a){v(W);v(a?X:Y);t(Z,10)},Z=function(){if(d.tracker!=="null"&&d.tracker!==null){var a=c.isFunction(d.tracker)?d.tracker:j[d.tracker],b=(g.pathname+g.search+(c.address&&!r()?c.address.value():"")).replace(/\/\//,"/").replace(/^\/$/,
"");if(c.isFunction(a))a(b);else if(c.isFunction(j.urchinTracker))j.urchinTracker(b);else if(j.pageTracker!==k&&c.isFunction(j.pageTracker._trackPageview))j.pageTracker._trackPageview(b);else j._gaq!==k&&c.isFunction(j._gaq.push)&&j._gaq.push(["_trackPageview",decodeURI(b)])}},O=function(){var a=ha()+":"+l+";document.open();document.writeln('<html><head><title>"+n.title.replace("'","\\'")+"</title><script>var "+C+' = "'+encodeURIComponent(u())+(n.domain!=g.hostname?'";document.domain="'+n.domain:
"")+"\";<\/script></head></html>');document.close();";if(q<7)m.src=a;else m.contentWindow.location.replace(a)},aa=function(){if(G&&$!=-1){var a,b=G.substr($+1).split("&");for(i=0;i<b.length;i++){a=b[i].split("=");if(/^(autoUpdate|crawlable|history|strict|wrap)$/.test(a[0]))d[a[0]]=isNaN(a[1])?/^(true|yes)$/i.test(a[1]):parseInt(a[1],10)!==0;if(/^(state|tracker)$/.test(a[0]))d[a[0]]=a[1]}G=null}h=u()},ca=function(){if(!ba){ba=o;aa();var a=function(){ia.call(this);ja.call(this)},b=c("body").ajaxComplete(a);
a();if(d.wrap){c("body > *").wrapAll('<div style="padding:'+(x(b,"marginTop")+x(b,"paddingTop"))+"px "+(x(b,"marginRight")+x(b,"paddingRight"))+"px "+(x(b,"marginBottom")+x(b,"paddingBottom"))+"px "+(x(b,"marginLeft")+x(b,"paddingLeft"))+'px;" />').parent().wrap('<div id="'+C+'" style="height:100%;overflow:auto;position:relative;'+(H&&!window.statusbar.visible?"resize:both;":"")+'" />');c("html, body").css({height:"100%",margin:0,padding:0,overflow:"hidden"});H&&c('<style type="text/css" />').appendTo("head").text("#"+
C+"::-webkit-resizer { background-color: #fff; }")}if(y&&q<8){a=n.getElementsByTagName("frameset")[0];m=n.createElement((a?"":"i")+"frame");if(a){a.insertAdjacentElement("beforeEnd",m);a[a.cols?"cols":"rows"]+=",0";m.noResize=o;m.frameBorder=m.frameSpacing=0}else{m.style.display="none";m.style.width=m.style.height=0;m.tabIndex=-1;n.body.insertAdjacentElement("afterBegin",m)}t(function(){c(m).bind("load",function(){var e=m.contentWindow;h=e[C]!==k?e[C]:"";if(h!=u()){E(l);g.hash=B(h,o)}});m.contentWindow[C]===
k&&O()},50)}t(function(){v("init");E(l)},1);if(!r())if(y&&q>7||!y&&"on"+I in j)if(j.addEventListener)j.addEventListener(I,F,l);else j.attachEvent&&j.attachEvent("on"+I,F);else ka(F,50)}},ia=function(){var a,b=c("a"),e=b.size(),f=-1,p=function(){if(++f!=e){a=c(b.get(f));a.is('[rel*="address:"]')&&a.address();t(p,1)}};t(p,1)},la=function(){if(h!=u()){h=u();E(l)}},ma=function(){if(j.removeEventListener)j.removeEventListener(I,F,l);else j.detachEvent&&j.detachEvent("on"+I,F)},ja=function(){if(d.crawlable){var a=
g.pathname.replace(/\/$/,"");c("body").html().indexOf("_escaped_fragment_")!=-1&&c('a[href]:not([href^=http]), a[href*="'+document.domain+'"]').each(function(){var b=c(this).attr("href").replace(/^http:/,"").replace(new RegExp(a+"/?$"),"");if(b===""||b.indexOf("_escaped_fragment_")!=-1)c(this).attr("href","#"+b.replace(/\/(.*)\?_escaped_fragment_=(.*)$/,"!$2"))})}},k,C="jQueryAddress",I="hashchange",W="change",X="internalChange",Y="externalChange",o=true,l=false,d={autoUpdate:o,crawlable:l,history:o,
strict:o,wrap:l},z=c.browser,q=parseFloat(c.browser.version),da=z.mozilla,y=z.msie,ea=z.opera,H=z.webkit||z.safari,P=l,j=function(){try{return top.document!==k?top:window}catch(a){return window}}(),n=j.document,M=j.history,g=j.location,ka=setInterval,t=setTimeout,U=/\/{2,9}/g;z=navigator.userAgent;var m,G=V(document),$=G?G.indexOf("?"):-1,Q=n.title,K=l,ba=l,R=o,fa=o,L=l,h=u();if(y){q=parseFloat(z.substr(z.indexOf("MSIE")+4));if(n.documentMode&&n.documentMode!=q)q=n.documentMode!=8?7:8;var ga=n.onpropertychange;
n.onpropertychange=function(){ga&&ga.call(n);if(n.title!=Q&&n.title.indexOf("#"+u())!=-1)n.title=Q}}if(P=da&&q>=1||y&&q>=6||ea&&q>=9.5||H&&q>=523){if(ea)history.navigationMode="compatible";if(document.readyState=="complete")var na=setInterval(function(){if(c.address){ca();clearInterval(na)}},50);else{aa();c(ca)}c(window).bind("popstate",la).bind("unload",ma)}else!P&&D()!==""?g.replace(g.href.substr(0,g.href.indexOf("#"))):Z();return{bind:function(a,b,e){return w(a,b,e)},init:function(a){return w("init",
a)},change:function(a){return w(W,a)},internalChange:function(a){return w(X,a)},externalChange:function(a){return w(Y,a)},baseURL:function(){var a=g.href;if(a.indexOf("#")!=-1)a=a.substr(0,a.indexOf("#"));if(/\/$/.test(a))a=a.substr(0,a.length-1);return a},autoUpdate:function(a){if(a!==k){d.autoUpdate=a;return this}return d.autoUpdate},crawlable:function(a){if(a!==k){d.crawlable=a;return this}return d.crawlable},history:function(a){if(a!==k){d.history=a;return this}return d.history},state:function(a){if(a!==
k){d.state=a;var b=s();if(d.state!==k)if(M.pushState)b.substr(0,3)=="/#/"&&g.replace(d.state.replace(/^\/$/,"")+b.substr(2));else b!="/"&&b.replace(/^\/#/,"")!=D()&&t(function(){g.replace(d.state.replace(/^\/$/,"")+"/#"+b)},1);return this}return d.state},strict:function(a){if(a!==k){d.strict=a;return this}return d.strict},tracker:function(a){if(a!==k){d.tracker=a;return this}return d.tracker},wrap:function(a){if(a!==k){d.wrap=a;return this}return d.wrap},update:function(){L=o;this.value(h);L=l;return this},
title:function(a){if(a!==k){t(function(){Q=n.title=a;if(fa&&m&&m.contentWindow&&m.contentWindow.document){m.contentWindow.document.title=a;fa=l}if(!R&&da)g.replace(g.href.indexOf("#")!=-1?g.href:g.href+"#");R=l},50);return this}return n.title},value:function(a){if(a!==k){a=N(a);if(a=="/")a="";if(h==a&&!L)return;R=o;h=a;if(d.autoUpdate||L){E(o);if(r())M[d.history?"pushState":"replaceState"]({},"",d.state.replace(/\/$/,"")+(h===""?"/":h));else{K=o;if(H)if(d.history)g.hash="#"+B(h,o);else g.replace("#"+
B(h,o));else if(h!=u())if(d.history)g.hash="#"+B(h,o);else g.replace("#"+B(h,o));y&&q<8&&d.history&&t(O,50);if(H)t(function(){K=l},1);else K=l}}return this}if(!P)return null;return N(h)},path:function(a){if(a!==k){var b=this.queryString(),e=this.hash();this.value(a+(b?"?"+b:"")+(e?"#"+e:""));return this}return N(h).split("#")[0].split("?")[0]},pathNames:function(){var a=this.path(),b=a.replace(U,"/").split("/");if(a.substr(0,1)=="/"||a.length===0)b.splice(0,1);a.substr(a.length-1,1)=="/"&&b.splice(b.length-
1,1);return b},queryString:function(a){if(a!==k){var b=this.hash();this.value(this.path()+(a?"?"+a:"")+(b?"#"+b:""));return this}a=h.split("?");return a.slice(1,a.length).join("?").split("#")[0]},parameter:function(a,b,e){var f,p;if(b!==k){var J=this.parameterNames();p=[];b=b?b.toString():"";for(f=0;f<J.length;f++){var S=J[f],A=this.parameter(S);if(typeof A=="string")A=[A];if(S==a)A=b===null||b===""?[]:e?A.concat([b]):[b];for(var T=0;T<A.length;T++)p.push(S+"="+A[T])}c.inArray(a,J)==-1&&b!==null&&
b!==""&&p.push(a+"="+b);this.queryString(p.join("&"));return this}if(b=this.queryString()){e=[];p=b.split("&");for(f=0;f<p.length;f++){b=p[f].split("=");b[0]==a&&e.push(b.slice(1).join("="))}if(e.length!==0)return e.length!=1?e:e[0]}},parameterNames:function(){var a=this.queryString(),b=[];if(a&&a.indexOf("=")!=-1){a=a.split("&");for(var e=0;e<a.length;e++){var f=a[e].split("=")[0];c.inArray(f,b)==-1&&b.push(f)}}return b},hash:function(a){if(a!==k){this.value(h.split("#")[0]+(a?"#"+a:""));return this}a=
h.split("#");return a.slice(1,a.length).join("#")}}}();c.fn.address=function(v){if(!c(this).attr("address")){var w=function(r){if(r.shiftKey||r.ctrlKey||r.metaKey)return true;if(c(this).is("a")){var s=v?v.call(this):/address:/.test(c(this).attr("rel"))?c(this).attr("rel").split("address:")[1].split(" ")[0]:c.address.state()!==undefined&&c.address.state()!="/"?c(this).attr("href").replace(new RegExp("^(.*"+c.address.state()+"|\\.)"),""):c(this).attr("href").replace(/^(#\!?|\.)/,"");c.address.value(s);
r.preventDefault()}};c(this).click(w).live("click",w).live("submit",function(r){if(c(this).is("form")){var s=c(this).attr("action");s=v?v.call(this):(s.indexOf("?")!=-1?s.replace(/&$/,""):s+"?")+c(this).serialize();c.address.value(s);r.preventDefault()}}).attr("address",true)}return this}})(jQuery);
;

