			gallery_id = 'viewer';
			gallery_interval = 5000;


			permit_enlargements = true;
			scale_to_fill = false;
			vertical_center = false;
			playing = true;

			video_id = 'viewervideo';

			transition = 1;
			
			$j = jQuery.noConflict();


			$j(document).ready(
				function() {

if ( $j.browser.msie && $j.browser.version < 8 ) {
	ie7 = true;
//	alert();
}

//	update the wrapper height
					$j('#wrapper').height($j(window).height());
					$j(window).bind("resize", function(){
						$j('#wrapper').height($j(window).height());
					});
		
/*	transition background colour on hover */
/*
					$j('ul#mainmenu li ul li a').hover(
						function() {
							$j(this).fadeTo('fast', 1.0);
						},
						function() {
							$j(this).fadeTo('slow', 0.6);
						}
					);
*/

/*	transition background colour on hover */
					$j('ul.submenu li a').hover(
						function() {
							$j(this).css({ backgroundColor: "#f0f0f0" }).animate({ color: "#ffffff", backgroundColor: "#A0959A" }, 'fast');
						},
						function() {
							$j(this).animate({ color: "#42343B", backgroundColor: '#f0f0f0' }, 'slow');
						}
					);


/*	display the subsections		*/
					$j('ul.submenu li a').click(
						function() {
//							alert($j(this).attr('rel'));
							if ( ! $j('.post .scurrent').size() ) {
//								alert('no scurrent');
								$j('.post .entry:first').addClass('scurrent');
							}
							
							if ( ! $j('.post .' + $j(this).attr('rel')).hasClass('scurrent') ) {
								$j('.post .' + $j(this).attr('rel')).addClass('snext');
								$j('.post .scurrent').removeClass('scurrent').fadeOut(100, function() {
//									alert($j(this).attr('rel'));
									$j('.post .snext').removeClass('snext').addClass('scurrent').fadeIn(300);
								});
								
							}
						}
					);
					
/*	jump to gallery image	*/
					$j('#thumbs_draw ul.images a').click(
						function() {
							pauseGallery();
							showGalleryImage('v_' + $j(this).attr('id'));
							return false;
						}
					);
					
/*	jump to video	*/
					$j('#thumbs_draw ul.video a').click(
						function() {
							showVideo($j(this));
							return false;
						}
					);
					
					$j('#video_draw ul.video a').click(
						function() {
							showVideo($j(this));
							return false;
						}
					);
					
/*	play/pause	*/
					$j('.navigation .playpause').click(
						function() {
							if ( $j(this).hasClass('play') ) {
								playing = true;
								$j(this).removeClass('play').addClass('pause');
								hideVideo();
							} else {
								playing = false;
								$j(this).removeClass('pause').addClass('play');
							}
							return false;
						}
					);
					
					
					function pauseGallery() {
						playing = false;
						$j('.navigation .playpause').removeClass('pause').addClass('play');					
					}
					
/*	show hide info	*/
					$j('.navigation .info').click(
						function() {
							showDraw('#info_draw', $j(this).attr('rel'));
						}
					);
					
/*	show hide MENU	*/
					$j('.navigation .menu').click(
						function() {
//							alert('menu');
							showDraw('#menu_draw', $j(this).attr('rel'));
						}
					);
					
/*	show hide thumbs	*/
					$j('.navigation .thumbs').click(
						function() {
							showDraw('#thumbs_draw', $j(this).attr('rel'));
						}
					);

/*	show next image	*/
					$j('.navigation .next').click(
						function() {
							resetGalleryTimer();
							showGalleryImage(1);
						}
					);
/*	show previous image	*/
					$j('.navigation .prev').click(
						function() {
							resetGalleryTimer();
							showGalleryImage(-1);
						}
					);

/*	show video	*/
					$j('.navigation .video').click(
						function() {
				//		alert($j('#video_draw ul.video a').size())
							if ( $j('#video_draw ul.video a').size() > 1 )
								showDraw('#video_draw', $j(this).attr('rel'));
							else
								showVideo($j('#video_draw ul.video a:first'));
						}
					);
					
/*	hide draws	*/
					$j('.navigation .close').click(
						function() {
							closeDraws();
						}
					);
					
					$j('.archive .post h4').hover(
						function() {
							$j(this).parent().find('img.thumbnail').fadeIn('slow');
						},
						function() {
							$j(this).parent().find('img.thumbnail').fadeOut('fast');
						}
					);
						
					
/*	resize handle
	requires jquery-ui-resizable
*/
//					$j(".draw").resizable({ handles: 'e' });
					
					
/*	background gallery */

					if ( $j('#thumbs_draw ul.images a').size() ) {
						
						if ( ! $j('#' + gallery_id).size() ) {
							g = document.createElement('div');
							g.setAttribute('class', 'gallery fullscreen');
							g.className = 'gallery';
							g.setAttribute('id', gallery_id);
							$j('.post').append(g);
//	fix up ie
							$j('#' + gallery_id).addClass('fullscreen');
						}
						
						$j('#thumbs_draw ul.images a').each(
							function() {
								
								c = document.createElement('a');
								c.setAttribute('title', $j(this).attr('title'));
								c.setAttribute('id', 'v_' + $j(this).attr('id'));
								c.setAttribute('rel', $j(this).attr('rel'));
								c.setAttribute('class', 'gallery-node');
								c.className = 'gallery-node';
								
								y = document.createElement('img');
								y.setAttribute('src', $j(this).attr('href'));
								y.setAttribute('alt', $j(this).attr('title'));
								
								c.appendChild(y);
								
								$j('#' + gallery_id).append(c);
							}
						);
						
						$j('#' + gallery_id + ' a:first img').load(
							function() {
								showGalleryImage(1);
							}
						);
						
						resetGalleryTimer();

					}
					
					
					function resetGalleryTimer() {
						$j('#' + gallery_id).stopTime("playing");
						
						$j('#' + gallery_id).everyTime(gallery_interval, "playing", function() {
							if ( playing )
								showGalleryImage(1);
						});					
					}
					
					function showGalleryImage(id) {
			    		var gallery_current = $j('.gallery .activeslide');
//			    		alert('current ' + gallery_current.size());
						var gallery_next;
						
						hideVideo();

						if ( id == 1 ) {
//							gallery_next = gallery_current.next('.gallery-node').size() ? gallery_current.next() : $j('.gallery .gallery-node:first');
							if ( gallery_current.next('.gallery-node').size() ) {
								gallery_next = gallery_current.next();
//								if ( ie7 ) alert('next');
								
							} else {
//	ie things that gallery current is empty and gallery next has one element
								gallery_next = $j('.gallery .gallery-node');
							}
//	alert(gallery_current.size())
							if ( gallery_next.size() ) {
								gallery_next = jQuery(gallery_next[0]);
								id = gallery_next.attr('id');
							} else if ( gallery_next ) {
								id = gallery_next.attr('id');
							}
//	if id == -1 we are reversing
						} else if ( id == -1 ) {
							gallery_next =  gallery_current.prev('.gallery-node').length ? gallery_current.prev() : $j('.gallery .gallery-node:last');
							id = gallery_next[0].id;
//	otherwise we are jumping
						} else {
//							stopSlideshow();
							gallery_next = $j('#'+id);
						}

						
						if ( gallery_current.attr('id') == gallery_next.attr('id') ) {
							return;
						}
						
						resizeGalleryImage(gallery_next);
						
//	kill all old slides ( set z-index = 0 )
						$j('.gallery .prevslide').removeClass('prevslide');
//	hide and put the new slide on top ( set z-index = 2 )
						gallery_next.css('opacity', 0).addClass('activeslide')
//	put the current slide under the new slide ( set z-index = 1 )
						gallery_current.addClass('prevslide').removeClass('activeslide');
//	show the new slide
						if ( transition == 0 )
							gallery_next.show();
						else
							gallery_next.fadeTo(parseInt(gallery_interval/10), 1);
						
//	the thumbnails
						$j("#thumbs_draw li").removeClass('activeslide');
						thumb_id = id.substr(2, id.length);
						$j("#" + thumb_id).parent('li').addClass('activeslide');
						
					}


					function resizeGalleryImage(obj) {	  		
			//Gather browser and current image size
//						var imagewidth = $j(obj).width();
//						var imageheight = $j(obj).height();
						var browserwidth = $j(window).width();
						var browserheight = $j(window).height();
						var offset;

						imagesize = $j(obj).attr('rel');

						if ( imagesize ) {
							sizes = imagesize.split(',');
							imagewidth = sizes[0];
							imageheight = sizes[1];
						}
						
						i_ratio = imageheight/imagewidth;
						b_ratio = browserheight/browserwidth;


						if ( ! $j(obj).find('img') ) 
							return;
						img = $j(obj).find('img');

						
						if ( browserwidth < imagewidth || browserheight < imageheight ) {
							if ( scale_to_fill ) {
//								alert('scalling')
								if ( i_ratio > b_ratio ) {
									_w = browserwidth;
									_h = browserwidth * i_ratio;
								} else {
								    _h = browserheight;
									_w = browserheight / i_ratio;
								}
					
							} else {
								if ( i_ratio < b_ratio ) {
								    _w = browserwidth;
						    		_h = browserwidth * i_ratio;
								} else {
									_h = browserheight;
									_w = browserheight / i_ratio;
								}
							}
							
						} else {
						    _w = imagewidth;
				    		_h = imageheight;
						}

						img.width(_w);
						img.height(_h);
						img.css('left', ((browserwidth - _w) / 2));
						img.css('top', ((browserheight - _h) / 2));
					}


			function showVideo(obj, source, poster) {
				pauseGallery();
				closeDraws();

				obj = $j(obj);
				
				source = $j(obj).attr('href');
				poster = '';	//	$j(obj).attr('rel');
				
				if ( ! $j('#' + video_id).size() ) {
					g = document.createElement('div');
					g.setAttribute('class', 'videogallery fullscreen');
					g.className = 'videogallery';
					g.setAttribute('id', video_id);
					$j('.post').append(g);

					$j('#' + video_id).addClass('fullscreen');
				}
				
				if ( source.match(/mp4$/i) && isiphone() ) {
					location.href = source;
					return false;
				}

//	fade up video viewer
				$j('#' + video_id).fadeTo('300',1);

				_w = $j(window).width() - 2*130;

				var s1 = new SWFObject('/cms/wp-content/themes/neo-retro/libs/mediaplayer/player.swf','player',_w,'100%','9');
				s1.addParam('allowfullscreen','true');
				s1.addParam('allowscriptaccess','always');
				s1.addParam('flashvars','&image=' + poster + '&autostart=true&file=' + source + '&backcolor=000000&frontcolor=888888&lightcolor=CCCCCC&controlbar=over');


				s1.write(video_id);

				
//	show the description too
//				$j('.post-content .activeslide').removeClass('activeslide');
//				$j('#description-' + id).addClass('activeslide');
				
//	fade up the thumbnail
//				$j('.gallery-content .thumbnails ul li a').fadeTo(0, thumb_min);
//				$j('.gallery-content .thumbnails ul li a[rel="' + id + '"]').fadeTo(0, thumb_max);
			}
			
			
			function hideVideo() {
				$j('#' + video_id).remove();
			}


			function isiphone() { 
				var agent = navigator.userAgent.toLowerCase();
				if ( agent.match(/iPhone/i) || agent.match(/iPod/i) )
					return true;
				else
					return false;
			} 
				
					
					
					

				}	//	end jquery on ready
			);

		
					function closeDraws() {
						$j('.draw').animate( {width: '1px', opacity: 0}, 300 );
					}
					
					
					function showDraw(selector, width) {
						_w = 1;
						_o = 0;
						_h = $j(window).height();
						
						if ( $j(selector).width() <= _w ) {
							_w = width;
							_o = 1;
							$j('.draw').animate( {width: '1px', opacity: 0}, 300 );
						}
						$j(selector).css({minHeight: _h + 'px'}).animate( {width: _w + 'px', opacity: _o}, 300 );
//						alert(new Array(_w, _h, _o));
					}


		function is_array(input){
			return typeof(input)=='object'&&(input instanceof Array);
		}