//	lampstand/libs/functions.js

			var close_delay = 2000;
			
			var main_max = 0.8;
			var main_min = 0.5;

			var thumb_max = 1.0;
			var thumb_min = 0.6;

			var front_max = 0.8;
			var front_min = 0.6;

			var gs_t = null;
			var gs_si;	//	interval for gallery slideshow
			var gs_d = 5000;
			var ss_d = gs_d * 1.5;

			var autoplay = false;
			
//	gs-navigation menu
			var gs_opacity_max = 0.5;
			var gs_opacity_min = 0.0;
			var gs_showhide = true;
			var gs_opacity_delay = 'fast';

//	longtail mediaplayer			
			var player;

			jQuery.noConflict();

//	don't show/hide the gs navigation
			gs_showhide = ! jQuery.browser.msie && ! isiphone();
			ss_use = ! ( jQuery.browser.msie && jQuery.browser.version < 7);

			jQuery(document).ready(
				function() {

					if ( jQuery.browser.msie && jQuery.browser.version < 7 ) {				
						jQuery('.post-content').css('height', jQuery('.gallery-content').css('height'));
						jQuery('.gallery-content').css('width', jQuery('.gallery-content').css('width'));
					}
				
/*	hide post content */
					jQuery('.toggle').click(
						function() {
							if ( jQuery(this).hasClass('open') ) {
//								alert('open');
								jQuery('.post-content .entry').fadeIn('fast');
								jQuery(this).removeClass('open').addClass('close').attr('title', 'Hide information').find('span').html('Hide');
							} else {
//								alert('close');
								jQuery('.post-content .entry').fadeOut('fast');
								jQuery(this).removeClass('close').addClass('open').attr('title', 'More information').find('span').html('More');
							}
							return false;
						}
					);

//	no images - don't show close button
					if ( ! jQuery('.gallery-node').size() ) {
						jQuery('.toggle').hide();
					}
//	1 image - don't show thumbs
					else if ( jQuery('.thumbnails .gallery-node').size() == 1 ) {
						jQuery('.thumbnails').hide();
					} 
//	dont' hide posts in the blog
					else if ( jQuery('body.archive').size() ) {
					
					}
//	more than one image - hide content
					else if ( ! jQuery('body.page-template-template-newsletter-php') ) {
						jQuery('.post-content .entry').fadeOut(0);
						jQuery('.toggle').removeClass('close').addClass('open').attr('title', 'More information').find('span').html('More');
					}
					
					
/*	child page dropdown menu */
					jQuery("#mainmenu > li").hover(
//	launch on mainmenu over
						function() {
//	hide all visible uls from the parent
//							jQuery(this+':parent').find('li ul:visible').css({zIndex: 99}).slideUp('slow');
							_h = jQuery(this).find('ul:first:hidden').height();
							jQuery(this).siblings().find('ul:first:visible').slideUp('fast');
//							jQuery(this).find(':parent').slideUp('fast');
							
							if ( jQuery.browser.msie ) {
							//	alert(jQuery(this).width());
							//	margin_adjust = ( -1 * ( parseInt(jQuery(this).width()) + 20 ) ) + 'px';
							//	jQuery(this).find('ul:first:hidden').css({marginLeft: margin_adjust});
							}

//	show this one
							jQuery(this).find('ul:first:hidden').css({visibility: "visible",display: "none", zIndex: 100, height: _h}).slideDown('fast');
							
							jQuery("#mainmenu").stopTime("closing");
							
							jQuery("#mainmenu").css({zIndex: 100});
							
						},
						function() {
							jQuery("#mainmenu").stopTime("closing");
//	set a timer and close it up
							jQuery("#mainmenu").oneTime(close_delay, "closing", function() {
								jQuery("#mainmenu li ul").slideUp('fast');
								jQuery("#mainmenu").css({zIndex: 90});
							});
						}
					);
					
					
					jQuery("#mainmenu li ul").hover(
						function() {
							jQuery(this).css({ zIndex: 100 })
						},
						function() {
						}
					);
					


/*	start video if the large image is clicked */
/*	//	not required - a href will do the job
					jQuery('.video img').click(
						function() {
							id = jQuery('.video')[0].id;
							alert(id);
							source = '';
							poster = $(this).src;
							
							alert(poster);
						}
					);
*/


//	fade in front page content area
			jQuery('.page-template-template-home-php .content').hover(
				function(){
					jQuery(this).fadeTo('slow', front_max);
				},
				function(){
					jQuery(this).fadeTo('slow', front_min);
				}
			);
			
//	fade in thumbnails on hover
			jQuery('.gallery-content .thumbnails ul li a').hover(
				function(){
					jQuery(this).fadeTo('fast', thumb_max);
				},
				function(){
					jQuery(this).fadeTo('fast', thumb_min);
				}
			);
			
//	enlarge to fullscreen on gallery-node on click
			jQuery('ul.gallery .gallery-node a').not('.exclude').click(
				function() {
//					return true;
//					alert('a');
//					alert(jQuery('#supersize .activeslide')[0].id);
//					slideshow_interval = setInterval("gallery_next()", options.slide_interval);
//					jQuery('#supersize').resizenow();

//	if its a video gallery-node then just follow the link ( iphones for example )
					if ( jQuery(this).parent().hasClass('exclude') ) {
//						alert('video')
						return true;
					}
					
					if ( jQuery.browser.msie && jQuery.browser.version < 7 )
						return true;

//					fullscreen();						
					return false;
				}
			);
		
//	fix autogenerated thumb gallery
			jQuery('.gallery-content .thumbnails li').each(
				function() {
					id = jQuery(this).attr('id');
					jQuery(this).find('a').attr('rel', id);
					jQuery(this).attr('id', 'thumb-' + id);
				}
			);

//	enlarge thumbnail on click
			jQuery('body:not(.page-template-template-newsletter-php) .gallery-content .thumbnails li a').click(
				function() {
					stopSlideshow();
					showNode(jQuery(this).attr('rel'));
					return false;
				}
			);
			
//	enlarge videos in clips lists on click
			jQuery('.clip-list a').click(
				function() {
					source = jQuery(this).attr('href');
					if ( jQuery(this).attr('lowsrc') && jQuery('#highquality:checked').length == 0 ) {
						source = jQuery(this).attr('lowsrc');
					} else {
						source = jQuery(this).attr('href');
					}
					id = jQuery(this).attr('rel');
					poster = jQuery(this).find('img').attr('src');
					
//	create the container if required
					temp = id.split('-');
					target = temp[0] + '-' + temp[1] + '-video';
					
					container = document.createElement('div');
					container.setAttribute('id', target);
					container.setAttribute('class', 'video-container-fullscreen');
					container.className = 'video-container-fullscreen';
					
					closer = document.createElement('a');
					closer.setAttribute('href', '.');
					closer.setAttribute('class', 'video-container-close');
					closer.className = 'video-container-close';
		//			closer.setAttribute('style', 'position : fixed');
		//			closer.setAttribute('onclick', 'closeVideo()');
					
//					text = document.createTextNode("oi");
					
//					closer.appendChild(text);
//					container.appendChild(closer);
					
					jQuery('body').append(container);
					jQuery('body').append(closer);

/*
					alert(jQuery('#' + target).css('position'));
					alert(jQuery('#' + target).css('z-index'));
					alert(jQuery('#' + target).css('top'));
*/					
					jQuery('a.video-container-close').click(
						function () {
							closeVideo();
							return false;
						}
					);

//	vw wants videos to run at their true size
//					showVideo(id, source, poster, '100%', '100%');
					v_width = '100%';
					v_height = '100%';
					
					img = jQuery(this).find('img');

					if ( img.css('max-width') != 'none' ) {
						v_width = img.css('max-width');
					}
					if ( img.css('max-height') != 'none'  ) {
						v_height = img.css('max-height');
					}

					showVideo(id, source, poster, v_width, v_height);
					return false;
				}
			);
			


			if ( jQuery('.clip-list a').size() ) {
			
				
				jQuery(window).keydown(function (e) {
					switch(e.which) {
						case 27:	//	esc
						case 8:		//	delete / backspace
						case 88:	//	x
							jQuery('.video-container-close').remove();
							jQuery('.video-container-fullscreen').remove();
							break;
						default:
							break;
					}
				});
			}
			
//	show gs-controls on hover
			jQuery('.gallery').hover(
				function() {
//				alert(100);
//						jQuery('#gs-navigation').show("slide", { direction: "right" }, 'slow');
//	do not display control for video galleries
						if ( jQuery('.gallery .video').size() ) {
							return;
						}
						if ( gs_showhide )
							jQuery('#gs-navigation').show(gs_opacity_delay);
//	ie6 doesn't do the buttons nicely and ie7 messes up the show so use opacity
						else if ( jQuery.browser.msie && jQuery.browser.version > 6 )
							jQuery('#gs-navigation').fadeTo(gs_opacity_delay, gs_opacity_max);
//						clearTimeout(gs_t);
				},
				function() {
						if ( gs_showhide )
							jQuery('#gs-navigation').hide(gs_opacity_delay);
						else if ( jQuery.browser.msie )
							jQuery('#gs-navigation').fadeTo(gs_opacity_delay, gs_opacity_min);
//	this is the delay before hiding the toolbar
/*
					gs_t = setTimeout(function() {
//	there is a long slide to the right ( as it probably slides to screen right )
						jQuery('#gs-navigation').hide("slide", { direction: "right" }, 2000);
					}, 3000);
//					jQuery('#gs-navigation').hide("slide", { direction: "right" }, 1500);
*/
				}
			);
			
//	callbacks for gs-controls
			jQuery('#gs-playpause').click(
				function() {
					if ( jQuery(this).hasClass('play') ) {
						startSlideshow();
					} else {
						stopSlideshow();
					}
				}
			);

	
			jQuery('#gs-navigation .next').click(
				function() {
					stopSlideshow();
					showNode(1);
				}
			);

			
			jQuery('#gs-navigation .previous').click(
				function() {
					stopSlideshow();
					showNode(-1);
				}
			);


			jQuery('#gs-navigation .faster').click(
				function() {
					gs_d = parseInt(gs_d / 1.5);
					jQuery(".gallery").stopTime("playing");
					startSlideshow(true);
				//	clearInterval(gs_si);
				//	gs_si = setInterval("showNode(1)", gs_d);
				}
			);


			jQuery('#gs-navigation .slower').click(
				function() {
					gs_d = parseInt(gs_d * 1.5);
					jQuery(".gallery").stopTime("playing");
					startSlideshow(true);
				//	clearInterval(gs_si);
				//	gs_si = setInterval("showNode(1)", gs_d);
				}
			);


			jQuery('#gs-navigation .fullscreen').click(
				function() {
					start_fullscreen();
				}
			);

/*
			function faster(obj) {
				gs_d = parseInt(gs_d / 1.5);
				clearInterval(gs_si);
				gs_si = setInterval("showNode(1)", gs_d);
			}
			
			
			function slower(obj) {
				gs_d = parseInt(gs_d * 1.5);
				clearInterval(gs_si);
				gs_si = setInterval("showNode(1)", gs_d);
			}
			
*/
			function startSlideshow(delayed) {
//	if there's only one gallery-node don't play
				if ( jQuery('.gallery-node').size() < 2 ) {
					return;
				}
					
				if ( ! delayed )
					showNode(1);
				jQuery('#gs-playpause').addClass('pause');
				jQuery('#gs-playpause').removeClass('play');
				jQuery('.gallery').everyTime(gs_d, "playing", function() {
					showNode(1);
				});
//				gs_si = setInterval("showNode(1)", gs_d);
			}


			function stopSlideshow() {
				jQuery('#gs-playpause').addClass('play')
				jQuery('#gs-playpause').removeClass('pause')
				jQuery(".gallery").stopTime("playing");
//				clearInterval(gs_si);
			}
			
			
			function toggleSlideshow() {
//	its paused
				if ( jQuery('#gs-playpause').hasClass('play') )
					startSlideshow();
				else
					stopSlideshow();
			}


//	jump slideshow on thumbnail click
			function showNode(id) {
				transition = 1;
//	the current slide
	    		var gallery_current = jQuery('.gallery .activeslide');
//	the next slide
				var gallery_next;
//	if id == 1 we are advancing
				if ( id == 1 ) {
					gallery_next = gallery_current.next('.gallery-node').length ? gallery_current.next() : jQuery('.gallery .gallery-node:first');

					id = gallery_next[0].id;
//	if id == -1 we are reversing
				} else if ( id == -1 ) {
					gallery_next =  gallery_current.prev('.gallery-node').length ? gallery_current.prev() : jQuery('.gallery .gallery-node:last');
					id = gallery_next[0].id;
//	otherwise we are jumping
				} else {
//					stopSlideshow();
					gallery_next = jQuery('#'+id);
				}

//	do nothing				
				if ( gallery_next.hasClass('activeslide') ) {
					if ( jQuery.browser.msie )
						alert('nuh uh')
					return;
				}
//	kill all old slides ( set z-index = 0 )
				jQuery('.gallery .prevslide').removeClass('prevslide');
//	hide and put the new slide on top ( set z-index = 2 )
				gallery_next.hide().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 if ( transition == 1 )
					gallery_next.fadeIn(parseInt(gs_d/10));

/*	dont do this here - do it before we display supersize	
//	when we generate supersize gallery we're going to give them id's
//	also set activeslide on the supersize Gallery
				jQuery('#supersize .activeslide').removeClass('activeslide');
				jQuery('#ss-' + id).addClass('activeslide');
*/
//	toggle the description
//				jQuery('.post-content .activeslide').removeClass('activeslide');
//				jQuery('#description-' + id).addClass('activeslide');
//				title = gallery_next.find('span.title').html();
//				jQuery('.gallery-caption').html(title);
				jQuery('.gallery-caption').html('');
				gallery_next.find('span').clone().appendTo('.gallery-caption');
				
//	fade up the thumbnail
				jQuery('.gallery-content .thumbnails ul li a').fadeTo(0, thumb_min);
				jQuery('.gallery-content .thumbnails ul li a[rel="' + id + '"]').fadeTo(0, thumb_max);
			}

			
			fullscreen_id = 'gallery_container';
			fullscreen_selector = '#' + fullscreen_id;
			
			jQuery(fullscreen_selector + ' div.active-item a img').bind(
				'load',
				function() {
//					alert('laoded');
				}
			);

			
			default_options = {
				'source_selector' : 'div.gallery-node:not(.exclude)',
				'info_selector' : '#slidecaption .description',
				'title_selector' : '#slidecaption h3',
				'previous_selector' : '#ss-prevslide',
				'next_selector' : '#ss-nextslide',
				'close_selector' : '#ss-close',
				'pause_selector' : '#ss-pauseplay',
				'faster_selector' : '#ss-faster',
				'slower_selector' : '#ss-slower',
				'container_selector' : '#fullscreen',
				'start_selector' : 'div.gallery-node.activeslide a'
			}

//	fails for ie7
			options = jQuery('.gallery').attr('rel');

			if ( options ) {
				pairs = options.split('&');
				for ( i = 0; i < pairs.length; i++ ) {
					pair = pairs[i].split('=');
					if ( pair[0] == 'speed' )
						default_options.interval = pair[1] * 1000;
					else if ( pair[0] == 'next_gallery' ) {
						default_options.next_gallery = pair[1];
//	and don't loop
						default_options.loop = false;
					}
				}
			}
			
			
			
			
//			_createNewSlide = function(parent, src,)
			
			
			function fullscreenold(obj) {
				if ( isiphone() ) {
//					alert('iphone');
					
					toggleSlideshow();
					return false;
				}

//	msie6 messes up fullscreen
				if ( jQuery.browser.msie && jQuery.browser.version < 7 ) {
					alert('oi')
					return true;
				}
				
				stopSlideshow();
//	the id of the currently active gallery slide if there is one
				if ( jQuery('.gallery .activeslide').size() ) {
					id = jQuery('.gallery .activeslide')[0].id;					
				} else {				
					id = jQuery('.gallery .gallery-node')[0].id;
				}
				
//	set the active supersized slide
				jQuery('#supersize .activeslide').removeClass('activeslide');				
				jQuery('#ss-' + id).addClass('activeslide');
				
//	update the caption
				updatecaption(jQuery('#supersize .activeslide').find('img').attr('title'), jQuery('#supersize .activeslide').find('img').attr('longdesc'));
				jQuery('#supersize').start();
			}


//	if we have videos dont autoplay
			if ( jQuery('.gallery-node').size() && ! jQuery('.gallery .video').size() && autoplay )
				startSlideshow(true);
				
				
			if ( jQuery('#ss_front').size() ) {
				alert('go');
			//	build_supersized('ss_front');
				
			}

//	end jquery
				}
			);


//	start the fullscreen slideshow


			function showVideo(id, source, poster, _w, _h) {
				if ( source.match(/mp4$/i) && isiphone() ) {
//					alert(source);
					location.href = source;
					return false;
				}
				
				if ( ! _w ) {
					_w = 480;
					_h = 270;
				}
				//	page-pid-attachment-aid
				temp = id.split('-');
				target = temp[0] + '-' + temp[1];
//			alert(target)
//			alert(source)
				var s1 = new SWFObject('/cms/wp-content/themes/vita-ante-acta/libs/mediaplayer/player.swf','player',_w,_h,'9');
				s1.addParam('allowfullscreen','true');
				s1.addParam('allowscriptaccess','always');
				s1.addParam("wmode","opaque");
				s1.addParam('flashvars','&image=' + poster + '&autostart=true&file=' + source + '&backcolor=000000&frontcolor=888888&lightcolor=CCCCCC&controlbar=over');
//	so.addParam('flashvars','&author=Vincent Ward&description=desc&image=xxxx&title=Title');

				s1.write(target + '-video');

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


			function closeVideo() {
//				alert('removing close')
				if ( jQuery('.video-container-close').length )
					jQuery('.video-container-close').remove();
	//			alert('removing full')
				if ( jQuery('.video-container-fullscreen').length )
					jQuery('.video-container-fullscreen').remove();
//				return false;
			}			
			
			
			function videoResized(obj) {
//	we're leaving fullscreen
//	this crashes safari every time
				if ( ! obj.fullscreen )
					closeVideo();
			}
			
			
			function stateChanged(obj) {
				if ( obj.newstate == 'COMPLETED' )
					closeVideo();
			}
			
		
			function isiphone() { 
				var agent = navigator.userAgent.toLowerCase();
				if ( agent.match(/iPhone/i) || agent.match(/iPod/i) )
					return true;
				else
					return false;
			} 


			
			