if( !jQuery().data( 'amsgGalleryPluginLoaded' ) )
{ // avoid duplicating ourselves
	jQuery().data( 'amsgGalleryPluginLoaded', true );

	/**
	 * AstonishME Simple Gallery
	 */

	__amSimpleGallery = function(){
		var me;

		return {
			Init: function( selector ){
				if( typeof( me ) == "undefined" )
				{ // not run yet?
					me = this; // set reference to self
				}
				// set available params to defaults
				var params = jQuery.extend({
						// no comma after final entry or IE barfs
						test:'unset'
						}, ( arguments.length > 1&& arguments[1] ? arguments[1] : '' ) );
				me.CreateScreen();
				jQuery( selector ).each( function(){
					me.CreateGallery( this, params );
				});
			}, // /Init

			CreateGallery:function( element, params ){ // create a new gallery
				var params = jQuery.extend({
						// no comma after final entry or IE barfs
						link: 'a', // any particular link class ?
						getLink: function( gallery, link, img, params ){
							return jQuery( link ).attr( 'href' );
						}, // hook to allow interpratation of links
						share: function( gallery, link, img, params ){
							return false;
						}, // hook to add share links
						info:  function( gallery, link, img, params ){
							var title = jQuery( img ).attr( 'alt' );
							var info = jQuery( img ).attr( 'title' );
							return ( title ? '<h3>'+title+'</h3>' : '' ) + ( info ? '<p>'+info+'</p>' : '' );
						}, // hook to allow interpratation of info
						img: 'img' // where's the image?
						}, params );
				jQuery( element ).data( 'amsgImages', Array() );
				var oap = element;
				var params = jQuery.fn.extend({
						// no comma after final entry or IE barfs
						}, ( arguments.length > 1 ? arguments[1] : '' ) );

				if( jQuery( element ).is( params.link ) )
				{ // single image
					jQuery( element ).find( params.img ).each( function(){
						me.AddImage( element, element, this, params );
					});
				}
				else
				{ // it's a container
					jQuery( element ).find( params.link ).each( function(){
						var link = this;
						jQuery( this ).find( params.img ).each( function(){
							me.AddImage( element, link, this, params );
						});
					});
				}
				var imgCount = jQuery( element ).data( 'amsgImages').length;
				if( imgCount )
				{
					me.log( 'AMSG : Gallery created ('+imgCount+' image'+( imgCount > 1 ? 's' : '' )+')' );
				}
			},

			AddImage:function( gallery, link, img, params ){
				jQuery( link ).click( function(e){ // kill the click
					e.stopPropagation();
					return false;
				});

				var images = jQuery( gallery ).data( 'amsgImages' );
				if( typeof( images ) == 'undefined' )
				{
					images = Array();
				}
				jQuery( img ).data( 'amsgData', {
					gallery : gallery,
					position : images.length
				});
				jQuery( img ).click(function(e){
					me.ThumbClick( this );
				});
				images.push({
					loaded: false,
					src: params.getLink( gallery, link, img, params ),
					info: params.info( gallery, link, img, params ),
					share: params.share( gallery, link, img, params ),
					initial_height: 0,
					initial_width: 0,
					thumbUrl: jQuery(img).attr('src')
				})
				jQuery( gallery ).data( 'amsgImages', images );
			},


			/**
			 * Displays an image when thumb clicked
			 */
			ThumbClick:function( img )
			{
				var data = jQuery( img ).data( 'amsgData' );
				var gallery = jQuery( data.gallery );
				var position = data.position;
				if( !jQuery('html').hasClass('amsgActive') )
				{ // open our screen
					jQuery( '#amsgScreen').addClass( 'amsgHide');
					if( jQuery('head').data('is_crap_browser') )
					{ // it's a crap browser
						jQuery( 'head' ).data( 'body_x', jQuery(self).scrollLeft() );
						jQuery( 'head' ).data( 'body_y', jQuery(self).scrollTop() );
//						window.alert( jQuery(self).scrollTop() );
						self.scrollTo(0,0);
					}
					jQuery('html').addClass('amsgActive'); // show our screen
				}
				jQuery( '#amsgSlider' ).data( 'width', jQuery( '#amsgSlider' ).width() );
				me.PreLoad( gallery, position, true );
			}, // /ThumbClick


			/**
			 * PreLoads an image if required
			 * Auto shows image once loaded, if required
			 */
			PreLoad: function( gallery, position, autoShow ){
				var galleryImages = jQuery( gallery ).data( 'amsgImages' );
				var imgDetails = galleryImages[ position ];

				var data = {gallery:gallery,position:position}

				if( autoShow )
				{ // we want to show it once loaded
					jQuery( me ).data( 'amsgAutoShow', data );
				}
				if( imgDetails.loaded == false )
				{ // img isn't loaded yet
					var preload = jQuery( '<img src="'+imgDetails.src+'" class="amsgPreLoad" />' );
					data.preload = preload;
/* FF on a mac?
					preload.ready( function(){
						me.ImageLoaded( data );
					});
*/

					preload.load( function(){
						me.ImageLoaded( data );
					});
					preload.appendTo('body'); // pre-load the image
					me.log( 'AMSG : Pre-loading : '+imgDetails.src );
				}
				else
				{
					data.preload = false;
					me.ImageLoaded( data );
				}
			}, // /PreLoad

			ImageLoaded:function( data ){
				var gallery = jQuery( data.gallery ).data('amsgImages');
				var imgDetails = gallery[ data.position ]
				if( data.preload )
				{ // get width and height
					me.log( 'AMSG : Storing image details : '+imgDetails.src );
					imgDetails.width = jQuery( data.preload ).width();
					imgDetails.height = jQuery( data.preload ).height();
					imgDetails.loaded = true; // set loaded flag
					gallery[ data.position ] = imgDetails;
					jQuery( data.gallery ).data('amsgImages', gallery ); // update details
				}

				me.log( 'AMSG : Loaded : '+imgDetails.src );
				if( jQuery( me ).data( 'amsgAutoShow' ) == data )
				{ // we want to show this image
					me.log( 'AMSG : Auto show '+imgDetails.src );
//					jQuery( '#amsgDetail' ).hide( 'explode', {number:3}, 1000, function( ){
//					jQuery( '#amsgDetail' ).fadeOut( 10, function(){
						jQuery( '#amsgDetail').css({
							position:'relative',
							top:0,
							left:0,
							display:'inline'
						});

						jQuery( '#amsgScreen').addClass('amsgHide');
//						jQuery( '#amsgDetail' ).fadeIn( 1, function(){
						if( imgDetails.info )
						{ // we have info for this image
							jQuery( '#amsgInfoBlock').html( imgDetails.info + '<span class="amsgUnderlay"></span>' );
							jQuery( '#amsgImgInfo' ).css({visibility:'visible'});
						}
						else
						{
							jQuery( '#amsgImgInfo' ).css({visibility:'hidden'});
						}

						if( imgDetails.share )
						{ // we have share links for this image
							jQuery( '#amsgShare').html( '<span class="amsgUnderlay"></span>' );
							imgDetails.share.appendTo( '#amsgShare' );
							jQuery( '#amsgImgShare' ).css({visibility:'visible'});
						}
						else
						{
							jQuery( '#amsgImgShare' ).css({visibility:'hidden'});
						}
						jQuery( '#amsgDetail').data( 'original_width', imgDetails.width );
						jQuery( '#amsgDetail').data( 'original_height', imgDetails.height );
						jQuery( '#amsgDetail').data( 'gallery', data.gallery );
						jQuery( '#amsgDetail').data( 'position', data.position );
						jQuery( '#amsgDetail' ).attr( 'src', imgDetails.src );
						jQuery( '#amsgDetail').ready( function(){
							me.Resize();
							jQuery( '#amsgDetail').click(function(e){ // cancel clicks on image
								e.stopPropagation();
							}).draggable({
								scroll:false, // stop window scroll
								stop:function(e, ui){
									jQuery( '#amsgDetail').data( 'zoomData', {
										distance_left: jQuery( '#amsgDetail').css('left').slice(0,-2) - ( jQuery( '#amsgImgWrap').width() / 2 ),
										distance_top: jQuery( '#amsgDetail').css('top').slice(0,-2) - ( jQuery( '#amsgImgWrap').height() / 2 ),
										zoom: jQuery( '#amsgZoom' ).data('zoomData')
									});
								}
							});
							me.log( 'fade in' );
//							jQuery( '#amsgDetail, #amsgTools' ).fadeOut( 1, function(){
								jQuery( '#amsgScreen').removeClass('amsgHide');
//								jQuery( '#amsgDetail').fadeIn(10, function(){
//									jQuery('#amsgTools').fadeIn(10);
//								});
//							});
							if( me.GetPrevious() != data.position && gallery[ me.GetPrevious() ].loaded == false )
							{
								me.PreLoad( data.gallery, me.GetPrevious(), false );
							}

							if( me.GetNext() != data.position && gallery[ me.GetNext() ].loaded == false )
							{
								me.PreLoad( data.gallery, me.GetNext(), false );
							}

//						});

						});

//					});
					jQuery( '#amsgImgPrevious, #amsgImgNext' ).css({
						visibility:'hidden'
					})
					if( data.position )
					{ // we have a previous image
						jQuery( '#amsgImgPrevious img').attr('src', gallery[data.position - 1].thumbUrl );
						jQuery( '#amsgImgPrevious' ).css({
							visibility:'visible'
						})
					}
					if( data.position < gallery.length - 1  )
					{
						jQuery( '#amsgImgNext img').attr('src', gallery[data.position + 1].thumbUrl );
						jQuery( '#amsgImgNext' ).css({
							visibility:'visible'
						})
					}
				}
			},

			/**
			 * Shows the previous image in the gallery
			 */
			ShowPrevious:function(){
//				jQuery( '#amsgDetail').fadeOut('fast');
				var gallery = jQuery('#amsgDetail').data('gallery');
				var images = jQuery(gallery).data('amsgImages');
				var position = me.GetPrevious();
				me.log( 'AMSG : Showing previous ('+position+')');
				jQuery( '#amsgScreen').addClass( 'amsgHide');
				me.PreLoad( gallery, position, true );
			},

			GetPrevious:function(){
				var gallery = jQuery('#amsgDetail').data('gallery');
				var images = jQuery(gallery).data('amsgImages');
				var position = jQuery('#amsgDetail').data('position');
				if( position == 0 )
				{
					position = images.length;
				}
				position--;
				return position;
			},


			/**
			 * Shows the next image in the gallery
			 */
			ShowNext:function(){
//				jQuery( '#amsgDetail').fadeOut('fast');
				var gallery = jQuery('#amsgDetail').data('gallery');
				var images = jQuery(gallery).data('amsgImages');
				var position = me.GetNext();
				me.log( 'AMSG : Showing next ('+position+')');
				jQuery( '#amsgScreen').addClass( 'amsgHide');
				me.PreLoad( gallery, position, true );
			},

			GetNext:function(){
				var gallery = jQuery('#amsgDetail').data('gallery');
				var images = jQuery(gallery).data('amsgImages');
				var position = jQuery('#amsgDetail').data('position');
				position++;
				if( position == images.length )
				{
					position = 0;
				}
				return position;
			},

			/**
			 * Adds the gallery (X)HTML to the <body> if required
			 */
			CreateScreen: function(){
				if( !jQuery( '#amsgScreen' ).is( '#amsgScreen' ) )
				{ // (X)HTML hasn't been added yet
					var detailScreen = jQuery( '<div id="amsgScreen"></div>');
					var detailWrap = jQuery( '<div id="amsgWrap"></div>');
					var tools = jQuery( '<div id="amsgTools"></div>' );
					jQuery( '<div class="amsgUnderlay">&nbsp;</div>' ).appendTo( tools );
					jQuery( '<span id="amsgImgShare" class="amsgImgTools" title=" Toggle Share Links [ key : s ] "><span id="amsgImgShareIcon">S</span></span>' ).appendTo( tools );
					jQuery( '<span id="amsgImgInfo" class="amsgImgTools" title=" Toggle Image info [ key : i ] "><span id="amsgImgInfoIcon">I</span></span>' ).appendTo( tools );
					jQuery( '<span id="amsgImgClose" class="amsgImgTools" title=" Close [ key : esc ] ">X</span>' ).appendTo( tools );
					var sliderWrap = jQuery( '<div id="amsgSliderWrap"></div>' );
					var slider = jQuery( '<div id="amsgSlider"></div>' );
					jQuery( '<div class="ui-slider-handle" title=" Zoom [ keys : ctrl+left arrow or ctrl+right arrow ] ">&nbsp;</div>' ).appendTo( slider );
					jQuery( '<span id="amsgZoom">&nbsp;</span>' ).appendTo( slider );
					slider.appendTo( sliderWrap );
					sliderWrap.appendTo( tools );
					tools.appendTo( detailScreen );
					jQuery( '<div id="amsgImgWrap"><img id="amsgDetail" title=" [ Drag : hold down left mouse button ] " /></div>' ).appendTo( detailWrap );
					jQuery( '<span id="amsgImgPrevious" class="amsgHideable" title=" Previous Image [ keys : left arrow or shift + tab ] "><img src="" title=" previous image " /></span>' ).appendTo( detailWrap );
					jQuery( '<span id="amsgImgNext" class="amsgHideable" title=" Next Image [ keys : right arrow or tab ] "><img src="" title=" next image " /></span>' ).appendTo( detailWrap );
					detailWrap.appendTo( detailScreen );
					jQuery( '<span id="amsgInfoBlock"></span>').appendTo( detailScreen );
					jQuery( '<span id="amsgShare" class="amsgHideable"></span>').appendTo( detailScreen );
//					jQuery( '<div id="amsgUnderlay" class="amsgUnderlay"><a id="amsgLogo" href="http://amasimplegallery.com" title=" find out how to add galleries to your site ">AstonishMe Simple Gallery</a></div>' ).appendTo( detailScreen );
					jQuery( '<div id="amsgUnderlay" class="amsgUnderlay"></div>' ).appendTo( detailScreen );
					detailScreen.appendTo( 'body' );

					jQuery( '#amsgSlider' ).slider({ // init slider
						startValue: 100,
						steps:100,
						slide:function( e, ui ){
							me.DoZoom(ui.value);
						} // /slide
					}); // /slider


					jQuery( '#amsgUnderlay, #amsgImgClose, #amsgImgWrap' ).click( function(e){ // add close
						e.stopPropagation();
						jQuery( '#amsgDetail').css({display:'none'});
						jQuery( 'html' ).removeClass('amsgActive');
						if( jQuery('head').data('is_crap_browser') )
						{ // it's a crap browser
							self.scrollTo(jQuery( 'head' ).data( 'body_x'),jQuery( 'head' ).data( 'body_y' ));
						}
					}); // /click

					jQuery( '#amsgImgPrevious' ).click(function(e){ // add previous
						e.stopPropagation();
						me.ShowPrevious();
					}); // /click

					jQuery( '#amsgImgNext' ).click(function(e){ // add next
						e.stopPropagation();
						me.ShowNext();
					}); // /click

					jQuery( '#amsgImgInfo' ).click(function(e){ // add info
						e.stopPropagation();
						jQuery( '#amsgInfoBlock' ).toggle('fast');
						jQuery( this ).toggleClass( 'amsgInfoPressed' );
					}); // /click

					jQuery( '#amsgImgShare' ).click(function(e){ // add info
						e.stopPropagation();
						if( jQuery( '#amsgImgShare' ).css('visibility') == 'visible' )
						{
							jQuery( '#amsgShare' ).toggle('fast');
							jQuery( this ).toggleClass( 'amsgSharePressed' );
						}
					}); // /click

					jQuery( '#amsgSlider .ui-slider-handle' ).css({left:jQuery( '#amsgSlider' ).width()+'px'});
					jQuery( '#amsgZoom' ).width( ( jQuery( '#amsgSlider' ).width() -1 )+'px');
					jQuery( window ).resize( function(){ me.Resize(); });
					me.log( 'AMSG : Screen created' );
				}
			}, // /Create Screen


			/**
			 * Peform zoom action
			 */
			DoZoom:function( amount ){
				jQuery( '#amsgZoom' ).data( 'zoomData', amount );
				jQuery( '#amsgZoom' ).width( ( jQuery( '#amsgSlider' ).width() * ( amount / 100 ) - 1 ) +'px');
				jQuery( '#amsgDetail' ).width( jQuery( '#amsgDetail' ).data( 'original_width' ) /100 * amount );
				jQuery( '#amsgDetail' ).height( jQuery( '#amsgDetail' ).data( 'original_height' ) /100 * amount );
				jQuery( '#amsgSlider .ui-slider-handle' ).css({left:jQuery( '#amsgZoom' ).width()+'px'});

				var zoomData = jQuery( '#amsgDetail' ).data('zoomData');
var new_top = Math.round( ( jQuery('#amsgScreen').height() - jQuery( '#amsgDetail').height() - 22 ) / 2 )+'px';
var new_left = Math.round( ( jQuery('#amsgScreen').width() - jQuery( '#amsgDetail').width() - 22 ) / 2 )+'px';
				jQuery( '#amsgDetail' ).css({
					top: new_top,
					left: new_left
				});

				if( jQuery( '#amsgDetail' ).css( 'top' ).slice( 0, -2 ) * - 1 > ( jQuery( '#amsgDetail').height() - 100  ) )
				{ // to high
					jQuery( '#amsgDetail').css({
						top:( ( jQuery( '#amsgDetail').height() - 100  ) * -1 )+'px'
					});
				} // /to high

				// top doesn't change :-S
				if( jQuery( '#amsgDetail' ).css( 'top' ).slice( 0, -2 ) > ( jQuery( '#amsgScreen').height() - 100  ) )
				{ // to low
					jQuery( '#amsgDetail').css({
						top:( ( jQuery( '#amsgScreen').height() - 100  ) )+'px'
					});
				} // /to low

				if( jQuery( '#amsgDetail' ).css( 'left' ).slice( 0, -2 ) * - 1 > ( jQuery( '#amsgDetail').width() - 100  ) )
				{ // to far left
					jQuery( '#amsgDetail').css({
						left:( ( jQuery( '#amsgDetail').width() - 100  ) * -1 )+'px'
					});
				} // /to far left

				// left doesn't change :-S
				if( jQuery( '#amsgDetail' ).css( 'left' ).slice( 0, -2 ) > ( jQuery( '#amsgWrap').width() - 100  ) )
				{ // to far right
					jQuery( '#amsgDetail').css({
						left:( jQuery( '#amsgWrap').width() - 100 )+'px'
					});
				} // /to far right
			},// /DoZoom


			/**
			 * Re-calculate max img dimensions on windows resize
			 * Sets zoom slider as appropriate
			 */
			Resize: function()
			{
//				jQuery( '#amsgDetail' ).css({display:'none' });
//				jQuery( '#amsgScreen' ).width( jQuery('body').width()+'px' );
//				jQuery( '#amsgScreen' ).height( jQuery('body').height()+'px' );
				jQuery( '#amsgImgWrap' ).width( ( jQuery( '#amsgScreen' ).width() - 20 )+'px' );
				jQuery( '#amsgImgWrap' ).height( ( jQuery( '#amsgScreen' ).height() - 20 )+'px' );
				me.SetZoom( jQuery( '#amsgWrap' ).width() - 2, jQuery( '#amsgWrap' ).height() - 2 );
//				jQuery( '#amsgDetail' ).css({display:'inline' });
var new_top = Math.round( ( jQuery('#amsgScreen').height() - jQuery( '#amsgDetail').height() - 22 ) / 2 )+'px';
var new_left = Math.round( ( jQuery('#amsgScreen').width() - jQuery( '#amsgDetail').width() - 22 ) / 2 )+'px';
				jQuery( '#amsgDetail' ).css({
					top: new_top,
					left: new_left
				});

//				me.log( 'top : '+new_top+', left : '+new_left );

				var offsetLeft = ( jQuery( '#amsgTools').css('left').slice(0,-2) * 1 ) + ( jQuery( '#amsgImgInfo').css('left').slice(0,-2) * 1 );
				var centerLeft = Math.round( ( jQuery( '#amsgScreen' ).width() - jQuery( '#amsgImgInfo').width() ) / 2 ) - 6;
				var offsetTop = ( jQuery( '#amsgTools').css('top').slice(0,-2) * 1 ) + ( jQuery( '#amsgImgInfo').css('top').slice(0,-2) * 1 );
				var bottom = ( jQuery( '#amsgScreen' ).height() - 30 - offsetTop ) * -1;
				jQuery( '#amsgInfoBlock').css({
//left:"50%",
//bottom:"5px",
//marginLeft:"-200px"
/*
						bottom:bottom+'px',
						left: centerLeft - offsetLeft+'px'
*/
								});
				me.log( 'AMSG : Resize' );
			}, // /Resize


			/**
			 * Calculate max zoom for viewport
			 */
			SetZoom: function( avail_width, avail_height ){
				var img_width = jQuery( '#amsgDetail' ).data( 'original_width' );
				var img_height = jQuery( '#amsgDetail' ).data( 'original_height' );

				var width_multiplier = ( avail_width > img_width ? 1 : avail_width / img_width );
				var height_multiplier = ( avail_height > img_height ? 1 : avail_height / img_height );

				var zoom = Math.round( ( width_multiplier > height_multiplier ? height_multiplier : width_multiplier ) * 100 - .5) / 100;

				var new_width = Math.round( img_width * zoom );
				var new_height = Math.round( img_height * zoom );

				jQuery( '#amsgDetail' ).width( new_width+'px' );
				jQuery( '#amsgDetail' ).height( new_height+'px' );
				jQuery( '#amsgSlider .ui-slider-handle' ).css({left:( jQuery( '#amsgSlider' ).data( 'width' ) * zoom )+'px'});
				jQuery( '#amsgZoom' ).width( jQuery( '#amsgSlider' ).data('width') * zoom -1 );
				jQuery( '#amsgZoom' ).data( 'zoomData', Math.round( zoom * 100 ) );
				jQuery( '#amsgDetail').data( 'zoomData', {
					distance_left: 0,
					distance_top: 0,
					zoom: 0
				});
				me.log( 'AMSG : Set initital zoom' );
				return zoom;
			}, // /SetZoom


			/**
			 * Queues a gallery call if document not ready
			 */
			AddQueue:function(){
				var queue = jQuery(me).data( 'amsgQueue');
				if( typeof(queue) == 'undefined' )
				{ // first time
					me = this;
					queue = Array();
					jQuery('<!--[if IE]><script type="text/javascript">jQuery("head").data("is_crap_browser", true );</script><![endif]-->').appendTo('head');
					jQuery(document).ready(function(){
						jQuery( me ).data( 'amsgLoaded', true ); // set flag
						me.AddHotkeys(); // add hotkeys
						me.ExecQueue(); // exec queue
					}); // /ready
				}
				if( jQuery( me ).data( 'amsgLoaded' ) )
				{ // document.ready() done
					me.Init( arguments[0], arguments.length > 1 ? arguments[1] : '' );
				}
				else
				{ // queue call until document.ready()
					queue.push( arguments );
					jQuery(me).data( 'amsgQueue', queue );
				}
			},


			/**
			 * Executes queued gallery calls
			 */
			ExecQueue:function(){
				queue = jQuery(me).data( 'amsgQueue');
				while( queue.length )
				{
					data = queue.pop();
					me.Init( data[0], data.length > 1 ? data[1] : '' );
				}
			},


			/**
			 * Adds hotkey actions
			 */
			AddHotkeys:function()
			{
				jQuery(document).keydown( function(e){
					if( jQuery('html').hasClass('amsgActive') )
					{ // we're live
						switch( e.keyCode )
						{
							case 9 : // tab key
								if( e.shiftKey == false && jQuery('#amsgImgNext').css('visibility') == 'visible' )
								{
									me.ShowNext();
								}
								else if( e.shiftKey && jQuery('#amsgImgPrevious').css('visibility') == 'visible' )
								{
									me.ShowPrevious();
								}

								return false;
								break;

							case 27 : // esc key
								jQuery('html').removeClass('amsgActive');
								return false;
								break;

							case 37 : // left arrow
								if( e.ctrlKey )
								{
									var zoom = jQuery( '#amsgZoom').data('zoomData') - 10;
									me.DoZoom( zoom > 0 ? zoom : 1 );
								}
								else if( jQuery('#amsgImgPrevious').css('visibility') == 'visible' )
								{
									me.ShowPrevious();
								}
								return false;
								break;

							case 39 : // right arrow
								if( e.ctrlKey )
								{
									var zoom = jQuery( '#amsgZoom').data('zoomData') + 10;
									me.DoZoom( zoom < 101 ? zoom : 100 );
								}
								else if( jQuery('#amsgImgNext').css('visibility') == 'visible' )
								{
									me.ShowNext();
								}
								return false;
								break;

							case 73 : // I pressed
								jQuery('#amsgImgInfo').click();
								break;

							case 83 : // S pressed
								jQuery('#amsgImgShare').click();
								break;
						}
					}
				});
			},


			/**
			 * Add log message to console if active
			 * @param (string ) msg : log message
			 */
			log:function( msg ){
				if( typeof( console ) != 'undefined' )
				{
					try{
						console.log( msg );
					}
					catch(e){} // do nothing
				}
				else
				{
//					window.alert( msg );
				}
			}, // /log

			/**
			 * Add error message to console if active
			 * @param (string ) msg : error message
			 */
			error:function( msg ){
				if( typeof( console ) != 'undefined' )
				{
					try{
						console.error( msg );
					}
					catch(e){} // do nothing
				}
			},// /error

			/**
			 * Add info message to console if active
			 * @param (string ) msg : info message
			 */
			info:function( msg ){
				if( typeof( console ) != 'undefined' )
				{
					try{
						console.info( msg );
					}
					catch(e){} // do nothing
				}
			} // /info
		}
	}; // /_amSimpleGallery

	var _amSimpleGallery = new __amSimpleGallery();
	_amSimpleGallery.info( 'AstonishMe Simple Gallery : Loaded' );

	function amSimpleGallery( selector ){
		_amSimpleGallery.AddQueue( selector, arguments.length > 1 ? arguments[1] : '' );
	}
}
