/**
 * jQuery.timers
 **/
jQuery.fn.extend({
	everyTime: function(interval, label, fn, times, belay) {
		return this.each(function() {
			jQuery.timer.add(this, interval, label, fn, times, belay);
		});
	},
	oneTime: function(interval, label, fn) {
		return this.each(function() {
			jQuery.timer.add(this, interval, label, fn, 1);
		});
	},
	stopTime: function(label, fn) {
		return this.each(function() {
			jQuery.timer.remove(this, label, fn);
		});
	}
});

jQuery.event.special

jQuery.extend({
	timer: {
		global: [],
		guid: 1,
		dataKey: "jQuery.timer",
		regex: /^([0-9]+(?:\.[0-9]*)?)\s*(.*s)?$/,
		powers: {
			// Yeah this is major overkill...
			'ms': 1,
			'cs': 10,
			'ds': 100,
			's': 1000,
			'das': 10000,
			'hs': 100000,
			'ks': 1000000
		},
		timeParse: function(value) {
			if (value == undefined || value == null)
				return null;
			var result = this.regex.exec(jQuery.trim(value.toString()));
			if (result[2]) {
				var num = parseFloat(result[1]);
				var mult = this.powers[result[2]] || 1;
				return num * mult;
			} else {
				return value;
			}
		},
		add: function(element, interval, label, fn, times, belay) {
			var counter = 0;
			
			if (jQuery.isFunction(label)) {
				if (!times) 
					times = fn;
				fn = label;
				label = interval;
			}
			
			interval = jQuery.timer.timeParse(interval);

			if (typeof interval != 'number' || isNaN(interval) || interval <= 0)
				return;

			if (times && times.constructor != Number) {
				belay = !!times;
				times = 0;
			}
			
			times = times || 0;
			belay = belay || false;
			
			var timers = jQuery.data(element, this.dataKey) || jQuery.data(element, this.dataKey, {});
			
			if (!timers[label])
				timers[label] = {};
			
			fn.timerID = fn.timerID || this.guid++;
			
			var handler = function() {
				if (belay && this.inProgress) 
					return;
				this.inProgress = true;
				if ((++counter > times && times !== 0) || fn.call(element, counter) === false)
					jQuery.timer.remove(element, label, fn);
				this.inProgress = false;
			};
			
			handler.timerID = fn.timerID;
			
			if (!timers[label][fn.timerID])
				timers[label][fn.timerID] = window.setInterval(handler,interval);
			
			this.global.push( element );
			
		},
		remove: function(element, label, fn) {
			var timers = jQuery.data(element, this.dataKey), ret;
			
			if ( timers ) {
				
				if (!label) {
					for ( label in timers )
						this.remove(element, label, fn);
				} else if ( timers[label] ) {
					if ( fn ) {
						if ( fn.timerID ) {
							window.clearInterval(timers[label][fn.timerID]);
							delete timers[label][fn.timerID];
						}
					} else {
						for ( var fn in timers[label] ) {
							window.clearInterval(timers[label][fn]);
							delete timers[label][fn];
						}
					}
					
					for ( ret in timers[label] ) break;
					if ( !ret ) {
						ret = null;
						delete timers[label];
					}
				}
				
				for ( ret in timers ) break;
				if ( !ret ) 
					jQuery.removeData(element, this.dataKey);
			}
		}
	}
});

jQuery(window).bind("unload", function() {
	jQuery.each(jQuery.timer.global, function(index, item) {
		jQuery.timer.remove(item);
	});
});
/*
 * jQuery Easing v1.3
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/*
  * EASING EQUATIONS
  */
(function($){
	$.fn.galleryView = function() {
		var opts = $.fn.galleryView.defaults;
		
		var si;
		var id;
		var iterator = 0;
		var gallery_width;
		var gallery_height;
		var frame_margin;
		var strip_width;
		var strip_margin;
		var wrapper_width;
		var currentPosition = 0;
		var item_count = 0;
		var slide_method;
		var f;
		var img_path;
		var paused = false;
		var stopped = false;
		var frame_caption_size = 20;
		var frame_margin_top = 0;
		var pointer_width = 2;
		
		//Define jQuery objects for reuse
		var j_filmstrip;
		var j_frames;
		var j_panels;
		var j_pointer;
		
/************************************************/
/*	Plugin Methods								*/
/************************************************/	
		$.fn.galleryView.stopPlaying=function(){
			//pauze
			//iterator--;
			$(document).stopTime("transition");
			stopped=true;		 
		}

		$.fn.galleryView.startPlaying=function(){
			//play
			//opts.animate = true;
			if(stopped) {
				$(document).everyTime(opts.transition_interval,"transition",function(){
					showNextItem();
				});
			stopped = false;
			}
		}
        
		//check if slideshow contains video or audio
		var mediaType = queryString('type');	
		if(mediaType == 0) { //it's a picture
			jQuery('#autoplayOn').show();
			jQuery.fn.galleryView.startPlaying(); 
		}
		else {
			jQuery.fn.galleryView.stopPlaying(); 
		}
		
		
		
		function showItem(i) {
			//Disable next/prev buttons until transition is complete
			$('img.nav-next').unbind('click');
			$('img.nav-prev').unbind('click');
			j_frames.unbind('click');
			if(opts.fade_panels) {
				//Fade out all panels and fade in target panel
				j_panels.fadeOut(opts.transition_speed).eq(i%item_count).fadeIn(opts.transition_speed);
			} 
			
			//Slide either pointer or filmstrip, depending on transition method
			if(slide_method=='strip') {
				//Stop filmstrip if it's currently in motion
				j_filmstrip.stop();
				
				//Determine distance between pointer (eventual destination) and target frame
				var distance = getPos(j_frames[i]).left - (getPos(j_pointer[0]).left+2);
				var leftstr = (distance>=0?'-=':'+=')+Math.abs(distance)+'px';
				
				//Animate filmstrip and slide target frame under pointer
				//If target frame is a duplicate, jump back to 'original' frame
				j_filmstrip.animate({
					'left':leftstr
				},opts.transition_speed,opts.easing,function(){
					//Always ensure that there are a sufficient number of hidden frames on either
					//side of the filmstrip to avoid empty frames
					if(i>item_count) {
						i = i%item_count;
						iterator = i;
						j_filmstrip.css('left','-'+((opts.frame_width+frame_margin)*i)+'px');
					} else if (i<=(item_count-strip_size)) {
						i = (i%item_count)+item_count;
						iterator = i;
						j_filmstrip.css('left','-'+((opts.frame_width+frame_margin)*i)+'px');
					}
					
					if(!opts.fade_panels) {
						//j_panels.hide().eq(i%item_count).show();
						var theSrc = $('a',j_panels[i%item_count]).eq(0).attr('href');
						$('.mediaiframe').attr("src",theSrc);
					}
					currentPosition = i;
					$('img.nav-prev').click(jumpToPrevItem);
					$('img.nav-next').click(jumpToNextItem);
					enableFrameClicking();
				});
			} else {
				//Stop pointer if it's currently in motion
				j_pointer.stop();
				//Get position of target frame
				var pos = getPos(j_frames[i]);
				//Slide the pointer over the target frame
				j_pointer.animate({
					'left':(pos.left-2+'px')
				},opts.transition_speed,opts.easing,function(){	
					if(!opts.fade_panels) {
						//j_panels.hide().eq(i%item_count).show();
						var theSrc = $('a',j_panels[i%item_count]).eq(0).attr('href');
						$('.mediaiframe').attr("src",theSrc);
					}	
					$('img.nav-prev').click(jumpToPrevItem);
					$('img.nav-next').click(jumpToNextItem);
					enableFrameClicking();
				});
			}
			
			if($('a',j_frames[i])[0]) {
				j_pointer.unbind('click').click(function(){
					var a = $('a',j_frames[i]).eq(0);
					if(a.attr('target')=='_blank') {window.open(a.attr('href'));}
					else {location.href = a.attr('href');}
				});
			}
		};
		function showNextItem() {
			if(++iterator==j_frames.length) {iterator=0;/*$.fn.galleryView.stopPlaying();*/}
			/*else {*/
			showItem(iterator);
			/*}*/
		};
		function showPrevItem() {
			if(--iterator<0) {iterator = j_frames.length-1;}
			showItem(iterator);
		};
		function jumpToNextItem() {
			$(document).stopTime("transition");
			if(++iterator==j_frames.length) {iterator=0;}
			showItem(iterator);
			    if(opts.animate) {
			        $(document).everyTime(opts.transition_interval,"transition",function(){
				        showNextItem();
			        });
					if(stopped == true) {
						$.fn.galleryView.stopPlaying();
					}
			    }
			    else {
			        showNextItem();
			    }
		};
		function jumpToPrevItem() {
			$(document).stopTime("transition");
			if(--iterator<0) {iterator = item_count-1;}
			showItem(iterator);
			if(opts.animate) {
			    $(document).everyTime(opts.transition_interval,"transition",function(){
				    showNextItem();
			    });
				if(stopped == true) {
					$.fn.galleryView.stopPlaying();
				}
			}
			else {
			     showNextItem();
			}
		};
		function getPos(el) {
			var left = 0, top = 0;
			if(el != undefined) {
			    var el_id = el.id;
			}
			else {
			    return {'left':left,'top':top};
			}

			if(el.offsetParent) {
				do {
					left += el.offsetLeft;
					top += el.offsetTop;
				} while(el = el.offsetParent);
			}
			//If we want the position of the gallery itself, return it
			if(el_id == id) {return {'left':left,'top':top};}
			//Otherwise, get position of element relative to gallery
			else {
				var fPos = getPos(f[0]);
				var fLeft = fPos.left;
				var fTop = fPos.top;
				
				return {'left':left-fLeft,'top':top-fTop};
			}
		};
		function enableFrameClicking() {
			j_frames.each(function(i){
				//If there isn't a link in this frame, set up frame to slide on click
				//Frames with links will handle themselves
				if($('a',this).length==0) {
					$(this).click(function(){
						$(document).stopTime("transition");
						showItem(i);
						iterator = i;
						if(opts.animate) {
						    $(document).everyTime(opts.transition_interval,"transition",function(){
							    showNextItem();
						    });
							 if(stopped == true) {
								$.fn.galleryView.stopPlaying();
							 }
						  }
						  else {
						    showNextItem();
						  }
					});
				}
			});
		};
		
/************************************************/
/*	Main Plugin Code							*/
/************************************************/
		return this.each(function() {
			f = $(this);
			//Determine path between current page and filmstrip images
			//Scan script tags and look for path to GalleryView plugin
			$('script').each(function(i){
				var s = $(this);
				if(s.attr('src') && s.attr('src').match(/jquery\.galleryview/)){
					img_path = s.attr('src').split('jquery.galleryview')[0]+'themes/';	
				}
			});
			
			//Hide gallery to prevent Flash of Unstyled Content (FoUC) in IE
			f.css('visibility','hidden');
			
			//Assign elements to variables for reuse
			j_filmstrip = $('.filmstrip',f);
			j_frames = $('li',j_filmstrip);
			j_panels = $('.panel',f);
			
			id = f.attr('id');
			
			//Number of frames in filmstrip
			item_count = j_frames.length;
			//Number of frames that can display within the screen's width
			//30 = width of block for navigation button * 2
			//5 = minimum frame margin
			strip_size = Math.floor((opts.panel_width-30)/(opts.frame_width+5)); 
			
			
			/************************************************/
			/*	Determine transition method for filmstrip	*/
			/************************************************/
					//If more items than strip size, slide filmstrip
					//Otherwise, slide pointer
					if(strip_size >= item_count) {
						slide_method = 'pointer';
						strip_size = item_count;
					}
					else {slide_method = 'strip';}
			
			/************************************************/
			/*	Determine dimensions of various elements	*/
			/************************************************/
					//Width of gallery block
					gallery_width = opts.panel_width;
					//Height of gallery block = screen + filmstrip + captions (optional)
					gallery_height = opts.panel_height+opts.frame_height+frame_margin_top+(opts.show_captions?frame_caption_size:frame_margin_top);
					//Space to put between filmstrip frames
					//30 = width of block for navigation button * 2
					frame_margin = Math.floor(Math.min((opts.panel_width-30-(opts.frame_width*strip_size))/(strip_size+1),10));
					//Width of filmstrip
					if(slide_method == 'pointer') {strip_width = (opts.frame_width*item_count)+(frame_margin*(item_count));}
					else {strip_width = (opts.frame_width*item_count*3)+(frame_margin*(item_count*3));}
					strip_margin = 0;
					//Width of filmstrip wrapper (to hide overflow)
					wrapper_width = ((strip_size*opts.frame_width)+((strip_size-1)*frame_margin));
			
			
			/************************************************/
			/*	Modify/Augment DOM elements					*/
			/************************************************/
					//Add wrapper to filmstrip to hide extra frames
					j_filmstrip.wrap('<div class="strip_wrapper"></div>');
					if(slide_method=='strip') {
						j_frames.clone().appendTo(j_filmstrip);
						j_frames.clone().appendTo(j_filmstrip);
						j_frames = $('li',j_filmstrip);
					}
					//If there are panel captions, add overlay divs
					if($('.panel-overlay').length>0) {j_panels.append('<div class="overlay"></div>');}
					
					//If captions are enabled, add caption divs and fill with the image titles
					if(opts.show_captions) {
						j_frames.append('<div class="caption"></div>').each(function(i){
							$(this).find('.caption').html($(this).find('img').attr('title'));			   
						});
					}
					
					//Add navigation buttons
					$('<img />').addClass('nav-next').attr('src',img_path+opts.nav_theme+'/next.png').appendTo(f).css({
						'position':'absolute',
						'cursor':'pointer',
						'top':opts.panel_height+'px',
						'right':'0px'
					}).click(jumpToNextItem);
					$('<img />').addClass('nav-prev').attr('src',img_path+opts.nav_theme+'/prev.png').appendTo(f).css({
						'position':'absolute',
						'cursor':'pointer',
						'top':opts.panel_height+'px',
						'left':'0px'
					}).click(jumpToPrevItem);
					
		
			
			/************************************************/
			/*	Apply CSS Styles							*/
			/************************************************/
					f.css({
						'position':'relative',
						'margin':'0',
						'background':opts.background_color,
						'border':opts.border,
						'width':gallery_width+'px',
						'fontSize':'0px'
						//'height':gallery_height+'px'
					});
					j_panels.css({
						'width':(opts.panel_width-parseInt(j_panels.css('paddingLeft').split('px')[0],10)-parseInt(j_panels.css('paddingRight').split('px')[0],10))+'px',
						//'height':(opts.panel_height-parseInt(j_panels.css('paddingTop').split('px')[0],10)-parseInt(j_panels.css('paddingBottom').split('px')[0],10))+'px',
						'position':'absolute',
						'top':'0px',
						'left':'0px',
						'overflow':'hidden',
						'background':'white',
						'display':'none',
						'fontSize':'0px'
					});
					j_filmstrip.css({
						'listStyle':'none',
						'margin':'0',
						'padding':'0',
						'width':strip_width+'px',
						'position':'absolute',
						'zIndex':'900',
						'fontSize':'0px',
						'top':'0',
						'left':'0',
						'height':(opts.frame_height+10)+'px',
						'background':opts.background_color
					});
					j_frames.css({
						'float':'left',
						/*'position':'relative',*/
						'height':opts.frame_height+'px',
						'zIndex':'901',
						'marginTop':frame_margin_top+'px',
						'marginBottom':'0px',
						'fontSize':'0px',
						'marginRight':frame_margin+'px',
						'padding':'0',
						'cursor':'pointer'
					});
					$('img',j_frames).css({
						'border':'none'
					});
					$('.strip_wrapper',f).css({
						'position':'absolute',
						'top':opts.panel_height+'px',
						'left':((gallery_width-wrapper_width)/2)+'px',
						'width':wrapper_width+'px',
						'height':(opts.frame_height+frame_margin_top+(opts.show_captions?frame_caption_size:frame_margin_top))+'px',
						'fontSize':'0px',
						'overflow':'hidden'
					});
					$('.caption',f).css({
						'position':'absolute',
						'top':opts.frame_height+'px',
						'left':'0',
						'margin':'0',
						'width':opts.frame_width+'px',
						'padding':'0',
						'color':opts.caption_text_color,
						'textAlign':'center',
						'fontSize':'0px',
						'height':frame_caption_size+'px',
						'lineHeight':frame_caption_size+'px'
					});
					$('.overlay',j_panels).css({
						'position':'absolute',
						'zIndex':'998',
						'width':opts.panel_width+'px',
						'height':opts.overlay_height+'px',
						'bottom':'0',
						'left':'0',
						'background':opts.overlay_color,
						'opacity':opts.overlay_opacity
					});

			
			/************************************************/
			/*	Create Pointer element						*/
			/************************************************/
					var pointer = $('<div></div>');
					pointer.attr('id','pointer').appendTo(f).css({
						 'position':'absolute',
						 'zIndex':'1000',
						 'cursor':'pointer',
						 'top':getPos(j_frames[0]).top-(pointer_width/2)+'px',
						 'left':getPos(j_frames[0]).left-(pointer_width/2)+'px',
						 'height':opts.frame_height-pointer_width+'px',
						 'width':opts.frame_width-pointer_width+'px',
						 'border':pointer_width+'px solid '+(opts.nav_theme=='dark'?'#9c0':'white')
					});
					j_pointer = $('#pointer',f);
					
			
			/************************************************/
			/*	Add events to various elements				*/
			/************************************************/
					enableFrameClicking();
					if(opts.pause_on_hover && stopped == false) {
						$('.panel',f).mouseover(function(){
							$(document).oneTime(500,"animation_pause",function(){
								$(document).stopTime("transition");
								paused=true;		 
							});
						}).mouseout(function(){
							$(document).stopTime("animation_pause");
							if(paused) {
								$(document).everyTime(opts.transition_interval,"transition",function(){
									showNextItem();
								});
								paused = false;
							}
						});
					}
					
			/************************************************/
			/*	hide certain items when needed   			*/
			/************************************************/
					if(item_count < 2) {
					    $('.nav-next').css({
						    'display':'none'
					    });
						$('.nav-prev').css({
						    'display':'none'
					    });
						$('#pointer').css({
						    'display':'none'
					    });					    
					}	
		
			/************************************************/
			/*	Initiate Automated Animation				*/
			/************************************************/
				
					//If the filmstrip is animating, move the strip to the middle third
					if(slide_method=='strip') {
						j_filmstrip.css('left','-'+((opts.frame_width+frame_margin)*item_count)+'px');
						iterator = item_count;
					}
					//If there's a link under the pointer, enable clicking on the pointer
					if($('a',j_frames[iterator])[0]) {
						j_pointer.click(function(){
							var a = $('a',j_frames[iterator]).eq(0);
							if(a.attr('target')=='_blank') {window.open(a.attr('href'));}
							else {location.href = a.attr('href');}
						});
					}
					//If we have more than one item, begin automated transitions
					if(item_count > 1 && Utilities.GetCookie('autoplay') != 'off') {
					    if(opts.animate && stopped == false) {
						    $(document).everyTime(opts.transition_interval,"transition",function(){
							    showNextItem();
						    });
						}
					}
					//autoplay aan of uit? check cookie
                    if(Utilities.GetCookie('autoplay') == 'off') {
                        autoplay(0);
                    }
					
					//Make gallery visible now that work is complete
					f.css('visibility','visible');
		});
	};
	
	$.fn.galleryView.defaults = {
			panel_width: 450,
			panel_height: 0,
			frame_width: 76,
			frame_height: 76,
			transition_speed: 200,
			transition_interval: 7000,
			background_color: 'white',
			overlay_text_color: 'white',
			caption_text_color: 'black',
			border: 'none',
			nav_theme: 'dark',
			show_captions: false,
			fade_panels: false,
			easing: 'swing',
			pause_on_hover: true,
			frame_margin:5,
			animate:true
	};
})(jQuery);


function autoplay(theBool) {
    if(theBool) {
        jQuery('#autoplayOn').show();
        jQuery('#autoplayOff').hide();
        jQuery.fn.galleryView.startPlaying();   
        Utilities.SetCookie('autoplay','on',999);     
    }
    else {        
        jQuery('#autoplayOn').hide();
        jQuery('#autoplayOff').show();
        jQuery.fn.galleryView.stopPlaying();
        Utilities.SetCookie('autoplay','off',999); 
    }
}

function queryString(parameter) { 
  var loc = top.location.search.substring(1, top.location.search.length);
  var param_value = false;

  var params = loc.split("&");
  for (i=0; i<params.length;i++) {
      param_name = params[i].substring(0,params[i].indexOf('='));
      if (param_name == parameter) {
          param_value = params[i].substring(params[i].indexOf('=')+1)
      }
  }
  if (param_value) {
      return param_value;
  }
  else {
      return false; //Here determine return if no parameter is found
  }
}

$(document).ready(function(){
	$('.gallerywrapperDiv').galleryView();
});