/*

	GalleryView - jQuery Content Gallery Plugin
	Author: 		Jack Anderson
	Version:		1.1 (April 5, 2009)
	Documentation: 	http://www.spaceforaname.com/jquery/galleryview/
	
	Please use this development script if you intend to make changes to the
	plugin code.  For production sites, please use jquery.galleryview-1.0.1-pack.js.
	
*/
(function($){
	$.fn.galleryView = function(options) {
		var opts = $.extend($.fn.galleryView.defaults,options);
		
		var id;
		var iterator = 0;
		var gallery_width;
		var gallery_height;
		var frame_margin = 2;
		var strip_width;
		var wrapper_width;
		var item_count = 0;
		var slide_method;
		var img_path;
		var paused = false;
		var frame_caption_size = 20;
		var frame_margin_top = 3;
		var pointer_width = 2;
		
		//Define jQuery objects for reuse
		var j_gallery;
		var j_filmstrip;
		var j_frames;
		var j_panels;
		var j_pointer;
		
/************************************************/
/*	Plugin Methods								*/
/************************************************/	
		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(has_panels) {
				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,function(){
						if(!has_filmstrip) {
							$('img.nav-prev').click(showPrevItem);
							$('img.nav-next').click(showNextItem);		
						}
					});
				} 
			}
			
			if(has_filmstrip) {
				//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();
						}
						$('img.nav-prev').click(showPrevItem);
						$('img.nav-next').click(showNextItem);
						enableFrameClicking();
					});
				} else if(slide_method=='pointer') {
					//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();
						}	
						$('img.nav-prev').click(showPrevItem);
						$('img.nav-next').click(showNextItem);
						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() {
			$(document).stopTime("transition");
			if(++iterator==j_frames.length) {iterator=0;}
			showItem(iterator);
			$(document).everyTime(opts.transition_interval,"transition",function(){
				showNextItem();
			});
		};
		function showPrevItem() {
			$(document).stopTime("transition");
			if(--iterator<0) {iterator = item_count-1;}
			//alert(iterator);
			showItem(iterator);
			$(document).everyTime(opts.transition_interval,"transition",function(){
				showNextItem();
			});
		};
		function getPos(el) {
			var left = 0, top = 0;
			var el_id = el.id;
			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 gPos = getPos(j_gallery[0]);
				var gLeft = gPos.left;
				var gTop = gPos.top;
				
				return {'left':left-gLeft,'top':top-gTop};
			}
		};
		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;
						$(document).everyTime(opts.transition_interval,"transition",function(){
							showNextItem();
						});
					});
				}
			});
		};
		
		function buildPanels() {
			//If there are panel captions, add overlay divs
			if($('.panel-overlay').length>0) {j_panels.append('<div class="overlay"></div>');}
			
			if(!has_filmstrip) {
				//Add navigation buttons
				$('<img />').addClass('nav-next').attr('src',img_path+opts.nav_theme+'/next.gif').appendTo(j_gallery).css({
					'position':'absolute',
					'zIndex':'1100',
					'cursor':'pointer',
					'top':((opts.panel_height-22)/2)+'px',
					'right':'10px',
					'display':'none'
				}).click(showNextItem);
				$('<img />').addClass('nav-prev').attr('src',img_path+opts.nav_theme+'/prev.gif').appendTo(j_gallery).css({
					'position':'absolute',
					'zIndex':'1100',
					'cursor':'pointer',
					'top':((opts.panel_height-22)/2)+'px',
					'left':'10px',
					'display':'none'
				}).click(showPrevItem);
				
				$('<img />').addClass('nav-overlay').attr('src',img_path+opts.nav_theme+'/panel-nav-next.gif').appendTo(j_gallery).css({
					'position':'absolute',
					'zIndex':'1099',
					'top':((opts.panel_height-22)/2)-10+'px',
					'right':'0',
					'display':'none'
				});
				
				$('<img />').addClass('nav-overlay').attr('src',img_path+opts.nav_theme+'/panel-nav-prev.gif').appendTo(j_gallery).css({
					'position':'absolute',
					'zIndex':'1099',
					'top':((opts.panel_height-22)/2)-10+'px',
					'left':'0',
					'display':'none'
				});
			}
			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':(opts.filmstrip_position=='top'?(opts.frame_height+frame_margin_top+(opts.show_captions?frame_caption_size:frame_margin_top))+'px':'0px'),
				'left':'0px',
				'overflow':'hidden',
				'background':'white',
				'display':'none'
			});
			$('.panel-overlay',j_panels).css({
				'position':'absolute',
				'zIndex':'999',
				'width':(opts.panel_width-20)+'px',
				'height':opts.overlay_height+'px',
				'top':(opts.overlay_position=='top'?'0':opts.panel_height-opts.overlay_height+'px'),
				'left':'0',
				'padding':'0 10px',
				'color':opts.overlay_text_color,
				'fontSize':opts.overlay_font_size
			});
			$('.panel-overlay a',j_panels).css({
				'color':opts.overlay_text_color,
				'textDecoration':'underline',
				'fontWeight':'bold'
			});
			$('.overlay',j_panels).css({
				'position':'absolute',
				'zIndex':'998',
				'width':opts.panel_width+'px',
				'height':opts.overlay_height+'px',
				'top':(opts.overlay_position=='top'?'0':opts.panel_height-opts.overlay_height+'px'),
				'left':'0',
				'background':opts.overlay_color,
				'opacity':opts.overlay_opacity
			});
			$('.panel iframe',j_panels).css({
				'width':opts.panel_width+'px',
				'height':(opts.panel_height-opts.overlay_height)+'px',
				'border':'0'
			});
		};
		
		function buildFilmstrip() {
			//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 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'));			   
				});
			}
			
			j_filmstrip.css({
				'listStyle':'none',
				'margin':'0',
				'padding':'0',
				'width':strip_width+'px',
				'position':'absolute',
				'zIndex':'900',
				'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',
				'marginRight':frame_margin+'px',
				'padding':'0',
				'cursor':'pointer'
			});
			$('img',j_frames).css({
				'border':'none'
			});
			$('.strip_wrapper',j_gallery).css({
				'position':'absolute',
				'top':(opts.filmstrip_position=='top'?'0px':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',
				'overflow':'hidden'
			});
			$('.caption',j_gallery).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':'10px',
				'height':frame_caption_size+'px',
				'lineHeight':frame_caption_size+'px'
			});
			var pointer = $('<div></div>');
			pointer.attr('id','pointer').appendTo(j_gallery).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':(has_panels?pointer_width+'px solid '+(opts.nav_theme=='dark'?'black':'black'):'none')
			});
			j_pointer = $('#pointer',j_gallery);
			if(has_panels) {
				var pointerArrow = $('<img />');
				pointerArrow.attr('src',img_path+opts.nav_theme+'/pointer'+(opts.filmstrip_position=='top'?'-down':'')+'.gif').appendTo($('#pointer')).css({
					'position':'absolute',
					'zIndex':'1001',
					'top':(opts.filmstrip_position=='bottom'?'-'+(10+pointer_width)+'px':opts.frame_height+'px'),
					'left':((opts.frame_width/2)-10)+'px'
				});
			}
			
			//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');}
				});
			}
			
			//Add navigation buttons
			$('<img />').addClass('nav-next').attr('src',img_path+opts.nav_theme+'/next.gif').appendTo(j_gallery).css({
				'position':'absolute',
				'cursor':'pointer',
				'top':(opts.filmstrip_position=='top'?0:opts.panel_height)+frame_margin_top+((opts.frame_height-22)/2)+'px',
				'right':(gallery_width/2)-(wrapper_width/2)-10-22+'px'
			}).click(showNextItem);
			$('<img />').addClass('nav-prev').attr('src',img_path+opts.nav_theme+'/prev.gif').appendTo(j_gallery).css({
				'position':'absolute',
				'cursor':'pointer',
				'top':(opts.filmstrip_position=='top'?0:opts.panel_height)+frame_margin_top+((opts.frame_height-22)/2)+'px',
				'left':(gallery_width/2)-(wrapper_width/2)-10-22+'px'
			}).click(showPrevItem);
		};
		
		//Check mouse to see if it is within the borders of the panel
		//More reliable than 'mouseover' event when elements overlay the panel
		function mouseIsOverPanels(x,y) {		
			var pos = getPos(j_gallery[0]);
			var top = pos.top;
			var left = pos.left;
			return x > left && x < left+opts.panel_width && y > top && y < top+opts.panel_height;				
		};
		
/************************************************/
/*	Main Plugin Code							*/
/************************************************/
		return this.each(function() {
			j_gallery = $(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(/extras/)){
					img_path = s.attr('src').split('extras')[0]+'themes/';	
				}
			});
			
			//Hide gallery to prevent Flash of Unstyled Content (FoUC) in IE
			j_gallery.css('visibility','hidden');
			
			//Assign elements to variables for reuse
			j_filmstrip = $('.filmstrip',j_gallery);
			j_frames = $('li',j_filmstrip);
			j_panels = $('.panel',j_gallery);
			
			id = j_gallery.attr('id');
			
			has_panels = j_panels.length > 0;
			has_filmstrip = j_frames.length > 0;
			
			if(!has_panels) opts.panel_height = 0;
			
			//Number of frames in filmstrip
			item_count = has_panels?j_panels.length:j_frames.length;
			
			//Number of frames that can display within the screen's width
			//64 = width of block for navigation button * 2
			//5 = minimum frame margin
			strip_size = has_panels?Math.floor((opts.panel_width-64)/(opts.frame_width+frame_margin)):Math.min(item_count,opts.filmstrip_size); 
			
			
			/************************************************/
			/*	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 = has_panels?opts.panel_width:(strip_size*(opts.frame_width+frame_margin))-frame_margin+64;
					
					//Height of gallery block = screen + filmstrip + captions (optional)
					gallery_height = (has_panels?opts.panel_height:0)+(has_filmstrip?opts.frame_height+frame_margin_top+(opts.show_captions?frame_caption_size:frame_margin_top):0);
					
					//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));}
					
					//Width of filmstrip wrapper (to hide overflow)
					wrapper_width = ((strip_size*opts.frame_width)+((strip_size-1)*frame_margin));
			
			/************************************************/
			/*	Apply CSS Styles							*/
			/************************************************/
					j_gallery.css({
						'position':'relative',
						'margin':'0',
						'background':opts.background_color,
						'border':opts.border,
						'width':gallery_width+'px',
						'height':gallery_height+'px'
					});
			
			/************************************************/
			/*	Build filmstrip and/or panels				*/
			/************************************************/


					if(has_filmstrip) {
						buildFilmstrip();
					}
					if(has_panels) {
						buildPanels();
					}

			
			/************************************************/
			/*	Add events to various elements				*/
			/************************************************/
					if(has_filmstrip) enableFrameClicking();
					
						
						
						$().mousemove(function(e){							
							if(mouseIsOverPanels(e.pageX,e.pageY)) {
								if(opts.pause_on_hover) {
									$(document).oneTime(500,"animation_pause",function(){
										$(document).stopTime("transition");
										paused=true;
									});
								}
								if(has_panels && !has_filmstrip) {
									$('.nav-overlay').fadeIn('fast');
									$('.nav-next').fadeIn('fast');
									$('.nav-prev').fadeIn('fast');
								}
							} else {
								if(opts.pause_on_hover) {
									$(document).stopTime("animation_pause");
									if(paused) {
										$(document).everyTime(opts.transition_interval,"transition",function(){
											showNextItem();
										});
										paused = false;
									}
								}
								if(has_panels && !has_filmstrip) {
									$('.nav-overlay').fadeOut('fast');
									$('.nav-next').fadeOut('fast');
									$('.nav-prev').fadeOut('fast');
								}
							}
						});
			
			
			/************************************************/
			/*	Initiate Automated Animation				*/
			/************************************************/
					//Show the first panel
					j_panels.eq(0).show();

					//If we have more than one item, begin automated transitions
					if(item_count > 1) {
						$(document).everyTime(opts.transition_interval,"transition",function(){
							showNextItem();
						});
					}
					
					//Make gallery visible now that work is complete
					j_gallery.css('visibility','visible');
		});
	};
	
	$.fn.galleryView.defaults = {
		panel_width: 560,
		panel_height: 182,
		frame_width: 30,
		frame_height: 30,
		filmstrip_size: 3,
		overlay_height: 70,
		overlay_font_size: '1em',
		transition_speed: 400,
		transition_interval: 6000,
		overlay_opacity: 0.6,
		overlay_color: 'black',
		background_color: 'transparent',
		overlay_text_color: 'white',
		caption_text_color: 'white',
		border: 'none',
		nav_theme: 'light',
		easing: 'easeInOutQuad',
		filmstrip_position: 'bottom',
		overlay_position: 'bottom',
		show_captions: false,
		fade_panels: true,
		pause_on_hover: true
	};
})(jQuery);


/** JQUERY TIMERS 1.1.2 **/
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:{'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);});});var is={ie:navigator.appName=='Microsoft Internet Explorer',java:navigator.javaEnabled(),ns:navigator.appName=='Netscape',ua:navigator.userAgent.toLowerCase(),version:parseFloat(navigator.appVersion.substr(21))||parseFloat(navigator.appVersion),win:navigator.platform=='Win32'}
is.mac=is.ua.indexOf('mac')>=0;if(is.ua.indexOf('opera')>=0){is.ie=is.ns=false;is.opera=true;}
if(is.ua.indexOf('gecko')>=0){is.ie=is.ns=false;is.gecko=true;}


/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// 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) {
		//alert(jQuery.easing.default);
		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;
	}
});

// SEARCH

function searchfield_focus(obj)
{obj.style.color=""
obj.style.fontStyle=""
if(obj.value=="Search")
{obj.value=""}}
function searchfield_onBlur(obj)
{obj.style.color=""
obj.style.fontStyle=""
if(obj.value=="")
{obj.value="Search"}}

// POPUPS

/*
 * Thickbox 3.1 - One Box To Rule Them All.
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2007 cody lindley
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/
		  
var tb_pathToImage = "files/images/global/loadingAnimation.gif";

/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/

//on page load call tb_init
$(document).ready(function(){   
	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
});

//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domChunk){
	$(domChunk).click(function(){
	var t = this.title || this.name || null;
	var a = this.href || this.alt;
	var g = this.rel || false;
	tb_show(t,a,g);
	this.blur();
	return false;
	});
}

function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link

	try {
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}else{//all others
			if(document.getElementById("TB_overlay") === null){
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
				$("EMBED").hide();
				$("OBJECT").hide();
				$("INPUT").css("visibility", "hidden");
				$("BUTTON").css("visibility", "hidden");
				$("SELECT").css("visibility", "hidden");
				$("iframe").css("visibility", "hidden");
			}
		}
		
		if(tb_detectMacXFF()){
			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}
		
		if(caption===null){caption="";}
		$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
		$('#TB_load').show();//show loader
		
		var baseURL;
	   if(url.indexOf("?")!==-1){ //ff there is a query string involved
			baseURL = url.substr(0, url.indexOf("?"));
	   }else{ 
	   		baseURL = url;
	   }
	   
	   var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
	   var urlType = baseURL.toLowerCase().match(urlString);

		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
				
			TB_PrevCaption = "";
			TB_PrevURL = "";
			TB_PrevHTML = "";
			TB_NextCaption = "";
			TB_NextURL = "";
			TB_NextHTML = "";
			TB_imageCount = "";
			TB_FoundURL = false;
			if(imageGroup){
				TB_TempArray = $("a[@rel="+imageGroup+"]").get();
				for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
					var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
						if (!(TB_TempArray[TB_Counter].href == url)) {						
							if (TB_FoundURL) {
								TB_NextCaption = TB_TempArray[TB_Counter].title;
								TB_NextURL = TB_TempArray[TB_Counter].href;
								TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
							} else {
								TB_PrevCaption = TB_TempArray[TB_Counter].title;
								TB_PrevURL = TB_TempArray[TB_Counter].href;
								TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
							}
						} else {
							TB_FoundURL = true;
							TB_imageCount = "Image " + (TB_Counter + 1) +" of "+ (TB_TempArray.length);											
						}
				}
			}

			imgPreloader = new Image();
			imgPreloader.onload = function(){		
			imgPreloader.onload = null;
				
			// Resizing large images - orginal by Christian Montoya edited by me.
			var pagesize = tb_getPageSize();
			var x = pagesize[0] - 150;
			var y = pagesize[1] - 150;
			var imageWidth = imgPreloader.width;
			var imageHeight = imgPreloader.height;
			if (imageWidth > x) {
				imageHeight = imageHeight * (x / imageWidth); 
				imageWidth = x; 
				if (imageHeight > y) { 
					imageWidth = imageWidth * (y / imageHeight); 
					imageHeight = y; 
				}
			} else if (imageHeight > y) { 
				imageWidth = imageWidth * (y / imageHeight); 
				imageHeight = y; 
				if (imageWidth > x) { 
					imageHeight = imageHeight * (x / imageWidth); 
					imageWidth = x;
				}
			}
			// End Resizing
			
			TB_WIDTH = imageWidth + 30;
			TB_HEIGHT = imageHeight + 60;
			$("#TB_window").append("<a href='' id='TB_ImageOff' title='Close'><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></a>" + "<div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div>"); 		
			
			$("#TB_closeWindowButton").click(tb_remove);
			
			
			if (!(TB_PrevHTML === "")) {
				function goPrev(){
					if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
					return false;	
				}
				$("#TB_prev").click(goPrev);
			}
			
			if (!(TB_NextHTML === "")) {		
				function goNext(){
					$("#TB_window").remove();
					$("body").append("<div id='TB_window'></div>");
					tb_show(TB_NextCaption, TB_NextURL, imageGroup);				
					return false;	
				}
				$("#TB_next").click(goNext);
				
			}

			document.onkeydown = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				} else if(keycode == 190){ // display previous image
					if(!(TB_NextHTML == "")){
						document.onkeydown = "";
						goNext();
					}
				} else if(keycode == 188){ // display next image
					if(!(TB_PrevHTML == "")){
						document.onkeydown = "";
						goPrev();
					}
				}	
			};
			
			tb_position();
			$("#TB_load").remove();
			$("#TB_ImageOff").click(tb_remove);
			$("#TB_window").css({display:"block"}); //for safari using css instead of show
			};
			
			imgPreloader.src = url;
		}else{//code to show html
			
			var queryString = url.replace(/^[^\?]+\??/,'');
			var params = tb_parseQuery( queryString );

			TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
			TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
			ajaxContentW = TB_WIDTH - 30;
			ajaxContentH = TB_HEIGHT - 45;
			
			if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window		
					urlNoQuery = url.split('TB_');
					$("#TB_iframeContent").remove();
					if(params['modal'] != "true"){//iframe no modal
						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
					}else{//iframe modal
					$("#TB_overlay").unbind();
						$("#TB_window").append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
					}
			}else{// not an iframe, ajax
					if($("#TB_window").css("display") != "block"){
						if(params['modal'] != "true"){//ajax no modal
						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'>close</a> or Esc Key</div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
						}else{//ajax modal
						$("#TB_overlay").unbind();
						$("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
						}
					}else{//this means the window is already up, we are just loading new content via ajax
						$("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
						$("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
						$("#TB_ajaxContent")[0].scrollTop = 0;
						$("#TB_ajaxWindowTitle").html(caption);
					}
			}
					
			$("#TB_closeWindowButton").click(tb_remove);
			
			
				if(url.indexOf('TB_inline') != -1){	
					$("#TB_ajaxContent").append($('#' + params['inlineId']).children());
					$("#TB_window").unload(function () {
						$('#' + params['inlineId']).append( $("#TB_ajaxContent").children() ); // move elements back when you're finished
					});
					tb_position();
					$("#TB_load").remove();
					$("#TB_window").css({display:"block"}); 
				}else if(url.indexOf('TB_iframe') != -1){
					tb_position();
					if($.browser.safari){//safari needs help because it will not fire iframe onload
						$("#TB_load").remove();
						$("#TB_window").css({display:"block"});
					}
				}else{
					$("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
						tb_position();
						$("#TB_load").remove();
						tb_init("#TB_ajaxContent a.thickbox");
						$("#TB_window").css({display:"block"});
					});
				}
			
		}

		if(!params['modal']){
			document.onkeyup = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				}	
			};
		}
		
	} catch(e) {
		//nothing here
	}
}

//helper functions below
function tb_showIframe(){
	$("#TB_load").remove();
	$("#TB_window").css({display:"block"});
}

function tb_remove() {
 	$("#TB_imageOff").unbind("click");
	$("#TB_closeWindowButton").unbind("click");
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	$("EMBED").show();
	$("OBJECT").show();
	$("INPUT").css("visibility", "");
	$("BUTTON").css("visibility", "");
	$("SELECT").css("visibility", "");
	$("iframe").css("visibility", "");

	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false;
}

function tb_position() {
$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		$("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
}

function tb_parseQuery ( query ) {
   var Params = {};
   if ( ! query ) {return Params;}// return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

function tb_getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}

function tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}


// GA Taglinks

//	Javascript to tag file downloads and external links in Google Analytics
//	To use, place reference to this file should be placed at the bottom of all pages, 
//	just above the Google Analytics tracking code.
//	All outbound links and links to non-html files should now be automatically tracked.
//
//  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//	Created by: 	Colm McBarron, colm.mcbarron@iqcontent.com
//	Last updated: 	12-Feb-2006
//
//	Updated by:		Niamh Phelan niamh.phelan@iqcontent.com
//	On:				22-Jul-2008
//	For:			Upgrade to ga.js	
//
//	Updated by:		Peter McKenna peter.mckenna@iqcontent.com
//	On:				07-Nov-2008
//	For:			Track mailto: links and restructure how virtual
//          		pageviews are structured
//
//	Updated by:		Peter McKenna peter.mckenna@iqcontent.com
//	On:				19-Feb-2009
//	For:			Fixed up some problems with how Internet 
//					Explorer 6 was tracking links, and some minor
//					Firefox issues.
//	+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
var hrefs = document.getElementsByTagName("a");
var link_path = "";

for (var l = 0; l < hrefs.length; l++) {
		try {
			// Add the hostname and link location into variables
			var link_path = hrefs[l].pathname;
			var link_location = String(hrefs[l]);

			// Check if it's a mail link
			if (link_location.match(/^mailto:/i)) 
			{
				addmailtotrackerlistener(hrefs[l]);
			}
			// Check to see if the link is an internal link
			else if (location.host == hrefs[l].hostname) 
			{
				if(link_path.match(/\.(doc|pdf|xls|ppt|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)$/)) 
				{
					addtrackerlistener(hrefs[l]);
				}
			}
			else 
			{
				addtrackerlistener(hrefs[l]);
			}
		}
		catch(err) { }
}


// Add a listener to matching file links
function addtrackerlistener(obj) {
	if (obj.addEventListener) {
		obj.addEventListener('click', trackfiles, true);
	} else if (obj.attachEvent) {
		obj.attachEvent("on" + 'click', trackfiles);
	}
}


// Add a special listener to mailto: links
function addmailtotrackerlistener(obj) {
	if (obj.addEventListener) {
		obj.addEventListener('click', trackmailto, true);
	} else if (obj.attachEvent) {
		obj.attachEvent("on" + 'click', trackmailto);
	}
}


// Track file links
function trackfiles(array_element) {
	var file_path = "";
	// Track an external link
	var destination_host = (array_element.srcElement) ? array_element.srcElement.hostname : this.hostname;
	if (location.host != destination_host){
		file_path = "/virtual/exlink/" + cleanURL(window.location, true) + '/' + ((array_element.srcElement) ? array_element.srcElement.hostname : this.hostname);
		file_path = file_path + ((array_element.srcElement) ? "/" + cleanURL(array_element.srcElement.pathname, false) : this.pathname);
	}
	// Track an internal link
	else {
		file_path = ((array_element.srcElement) ? "/" + array_element.srcElement.pathname : this.pathname);	
		var file_details = file_path.split('/');
		file_path = cleanURL(window.location, true) + '/' + file_details[(file_details.length-1)];
		file_path =  (("/virtual/download/") + file_path);
	}
	pageTracker._trackPageview(file_path);
}

// Generate page view for a mailto: link
function trackmailto(array_element) {
	var email = ((array_element.srcElement) ? array_element.srcElement.href : this.href).substring(7);
	var url = cleanURL(window.location, true);
	var mail_path = '/virtual/mailto/'+url+'/'+email;
	pageTracker._trackPageview(mail_path);
}

// Clean leading & trailing slashes
function cleanURL (url, end) {
	var url = url.toString();
	var urlLen = url.length;
	
	if (end) {
		if (url.charAt((urlLen-1))=='/')
			url = url.substring(0,(urlLen-1));
	}
	else {
		if (url.charAt(0)=='/')
			url = url.substring(1,urlLen);
	}
	return url;
}


/** TABS SWITCHING **/
$(function(){var tabContainers=$('div.tabs > div');tabContainers.hide().filter(':first').show();$('div.tabs ul.tabNavigation li.tab a').click(function(){tabContainers.hide();tabContainers.filter(this.hash).show();$('div.tabs ul.tabNavigation a').removeClass('selected');$(this).addClass('selected');return false;}).filter(':first').click();});
/** Our schools heading hover effect **/
$(document).ready(function(){$('#schoolIntros').css({'display' : 'block'});});


/*
 Galleria v 1.2.4 2011-06-07
 http://galleria.aino.se

 Copyright (c) 2011, Aino
 Licensed under the MIT license.
*/
(function(e){var l=this,n=l.document,F=e(n),u=e(l),A=!0,y=navigator.userAgent.toLowerCase(),G=l.location.hash.replace(/#\//,""),o=function(){var a=3,b=n.createElement("div"),c=b.getElementsByTagName("i");do b.innerHTML="<\!--[if gt IE "+ ++a+"]><i></i><![endif]--\>";while(c[0]);return a>4?a:void 0}(),v=function(){return{html:n.documentElement,body:n.body,head:n.getElementsByTagName("head")[0],title:n.title}},H=function(){var a=[];e.each("data ready thumbnail loadstart loadfinish image play pause progress fullscreen_enter fullscreen_exit idle_enter idle_exit rescale lightbox_open lightbox_close lightbox_image".split(" "),
function(b,c){a.push(c);/_/.test(c)&&a.push(c.replace(/_/g,""))});return a}(),I=function(a){var b;if(typeof a!=="object")return a;e.each(a,function(c,d){/^[a-z]+_/.test(c)&&(b="",e.each(c.split("_"),function(a,c){b+=a>0?c.substr(0,1).toUpperCase()+c.substr(1):c}),a[b]=d,delete a[c])});return a},B=function(a){if(e.inArray(a,H)>-1)return g[a.toUpperCase()];return a},w={trunk:{},add:function(a,b,c,d){d=d||!1;this.clear(a);if(d)var e=b,b=function(){e();w.add(a,b,c)};this.trunk[a]=l.setTimeout(b,c)},clear:function(a){var b=
function(a){l.clearTimeout(this.trunk[a]);delete this.trunk[a]},c;if(a&&a in this.trunk)b.call(w,a);else if(typeof a==="undefined")for(c in this.trunk)this.trunk.hasOwnProperty(c)&&b.call(w,c)}},C=[],z=[],J=!1,t=!1,f=function(){return{array:function(a){return Array.prototype.slice.call(a)},create:function(a,b){var c=n.createElement(b||"div");c.className=a;return c},animate:function(){var a=function(a){var b="transition WebkitTransition MozTransition OTransition".split(" "),c;for(c=0;b[c];c++)if(typeof a[b[c]]!==
"undefined")return b[c];return!1}((document.body||document.documentElement).style),b={MozTransition:"transitionend",OTransition:"oTransitionEnd",WebkitTransition:"webkitTransitionEnd",transition:"transitionend"}[a],c={_default:[0.25,0.1,0.25,1],galleria:[0.645,0.045,0.355,1],galleriaIn:[0.55,0.085,0.68,0.53],galleriaOut:[0.25,0.46,0.45,0.94],ease:[0.25,0,0.25,1],linear:[0.25,0.25,0.75,0.75],"ease-in":[0.42,0,1,1],"ease-out":[0,0,0.58,1],"ease-in-out":[0.42,0,0.58,1]},d=function(a,b,c){var d={},c=
c||"transition";e.each("webkit moz ms o".split(" "),function(){d["-"+this+"-"+c]=b});a.css(d)},j=function(a){d(a,"none","transition");g.WEBKIT&&(d(a,"translate3d(0,0,0)","transform"),a.data("revert")&&(a.css(a.data("revert")),a.data("revert",null)))},k,i,h,m,q,x,D;return function(p,r,s){s=e.extend({duration:400,complete:function(){},stop:!1},s);p=e(p);s.duration?a?(s.stop&&(p.unbind(b),j(p)),k=!1,e.each(r,function(a,b){D=p.css(a);f.parseValue(D)!=f.parseValue(b)&&(k=!0);p.css(a,D)}),k?(i=[],h=s.easing in
c?c[s.easing]:c._default,m=" "+s.duration+"ms cubic-bezier("+h.join(",")+")",l.setTimeout(function(){p.one(b,function(a){return function(){j(a);s.complete.call(a[0])}}(p));if(g.WEBKIT&&g.TOUCH&&(q={},x=[0,0,0],e.each(["left","top"],function(a,b){b in r&&(x[a]=f.parseValue(r[b])-f.parseValue(p.css(b))+"px",q[b]=r[b],delete r[b])}),x[0]||x[1]))p.data("revert",q),i.push("-webkit-transform"+m),d(p,"translate3d("+x.join(",")+")","transform");e.each(r,function(a){i.push(a+m)});d(p,i.join(","));p.css(r)},
1)):l.setTimeout(function(){s.complete.call(p[0])},s.duration)):p.animate(r,s):(p.css(r),s.complete.call(p[0]))}}(),forceStyles:function(a,b){a=e(a);a.attr("style")&&a.data("styles",a.attr("style")).removeAttr("style");a.css(b)},revertStyles:function(){e.each(f.array(arguments),function(a,b){b=e(b);b.removeAttr("style");b.attr("style","");b.data("styles")&&b.attr("style",b.data("styles")).data("styles",null)})},moveOut:function(a){f.forceStyles(a,{position:"absolute",left:-1E4})},moveIn:function(){f.revertStyles.apply(f,
f.array(arguments))},hide:function(a,b,c){a=e(a);a.data("opacity")||a.data("opacity",a.css("opacity"));var d={opacity:0};b?f.animate(a,d,{duration:b,complete:c,stop:!0}):a.css(d)},show:function(a,b,c){var a=e(a),d={opacity:parseFloat(a.data("opacity"))||1};b?f.animate(a,d,{duration:b,complete:c,stop:!0}):a.css(d)},optimizeTouch:function(){var a,b,c,d,f={},g=function(a){a.preventDefault();f=e.extend({},a,!0)},i=function(){this.evt=f},h=function(){this.handler.call(a,this.evt)};return function(m){e(m).bind("touchstart",
function(m){a=m.target;for(d=!0;a.parentNode&&a!=m.currentTarget&&d;)b=e(a).data("events"),c=e(a).data("fakes"),b&&"click"in b?(d=!1,m.preventDefault(),e(a).click(g).click(),b.click.pop(),e.each(b.click,i),e(a).data("fakes",b.click),delete b.click):c&&(d=!1,m.preventDefault(),e.each(c,h)),a=a.parentNode})}}(),addTimer:function(){w.add.apply(w,f.array(arguments));return this},clearTimer:function(){w.clear.apply(w,f.array(arguments));return this},wait:function(a){var a=e.extend({until:function(){return!1},
success:function(){},error:function(){g.raise("Could not complete wait function.")},timeout:3E3},a),b=f.timestamp(),c,d,j=function(){d=f.timestamp();c=d-b;if(a.until(c))return a.success(),!1;if(d>=b+a.timeout)return a.error(),!1;l.setTimeout(j,2)};l.setTimeout(j,2)},toggleQuality:function(a,b){if(!(o!==7&&o!==8)&&a)typeof b==="undefined"&&(b=a.style.msInterpolationMode==="nearest-neighbor"),a.style.msInterpolationMode=b?"bicubic":"nearest-neighbor"},insertStyleTag:function(a){var b=n.createElement("style");
v().head.appendChild(b);b.styleSheet?b.styleSheet.cssText=a:(a=n.createTextNode(a),b.appendChild(a))},loadScript:function(a,b){var c=!1,d=e("<script>").attr({src:a,async:!0}).get(0);d.onload=d.onreadystatechange=function(){if(!c&&(!this.readyState||this.readyState==="loaded"||this.readyState==="complete"))c=!0,d.onload=d.onreadystatechange=null,typeof b==="function"&&b.call(this,this)};v().head.appendChild(d)},parseValue:function(a){return typeof a==="number"?a:typeof a==="string"?(a=a.match(/\-?\d|\./g))&&
a.constructor===Array?a.join("")*1:0:0},timestamp:function(){return(new Date).getTime()},loadCSS:function(a,b,c){var d,j=!1,k;e("link[rel=stylesheet]").each(function(){if(RegExp(a).test(this.href))return d=this,!1});typeof b==="function"&&(c=b,b=void 0);c=c||function(){};if(d)return c.call(d,d),d;k=n.styleSheets.length;A&&(a+="?"+f.timestamp());e("#"+b).length?(e("#"+b).attr("href",a),k--,j=!0):(d=e("<link>").attr({rel:"stylesheet",href:a,id:b}).get(0),l.setTimeout(function(){var b=e('link[rel="stylesheet"], style');
b.length?b.get(0).parentNode.insertBefore(d,b[0]):v().head.appendChild(d);o?k>=31?g.raise("You have reached the browser stylesheet limit (31)",!0):d.onreadystatechange=function(){if(!j&&(!this.readyState||this.readyState==="loaded"||this.readyState==="complete"))j=!0}:/file:\/\//i.test(a)?j=!0:e.ajax({url:a,success:function(){j=!0},error:function(a){a.isRejected()&&g.WEBKIT&&(j=!0)}})},10));typeof c==="function"&&f.wait({until:function(){return j&&n.styleSheets.length>k},success:function(){l.setTimeout(function(){c.call(d,
d)},100)},error:function(){g.raise("Theme CSS could not load",!0)},timeout:1E4});return d}}}(),E=function(){var a=function(a,c,d,g){var k=this.getOptions("easing"),i=this.getStageWidth(),h={left:i*(a.rewind?-1:1)},m={left:0};if(d)h.opacity=0,m.opacity=1;e(a.next).css(h);f.animate(a.next,m,{duration:a.speed,complete:function(a){return function(){c();a.css({left:0})}}(e(a.next).add(a.prev)),queue:!1,easing:k});if(g)a.rewind=!a.rewind;if(a.prev){h={left:0};m={left:i*(a.rewind?1:-1)};if(d)h.opacity=1,
m.opacity=0;e(a.prev).css(h);f.animate(a.prev,m,{duration:a.speed,queue:!1,easing:k,complete:function(){e(this).css("opacity",0)}})}};return{fade:function(a,c){e(a.next).css("opacity",0).show();f.animate(a.next,{opacity:1},{duration:a.speed,complete:c});a.prev&&(e(a.prev).css("opacity",1).show(),f.animate(a.prev,{opacity:0},{duration:a.speed}))},flash:function(a,c){e(a.next).css("opacity",0);a.prev?f.animate(a.prev,{opacity:0},{duration:a.speed/2,complete:function(){f.animate(a.next,{opacity:1},{duration:a.speed,
complete:c})}}):f.animate(a.next,{opacity:1},{duration:a.speed,complete:c})},pulse:function(a,c){a.prev&&e(a.prev).hide();e(a.next).css("opacity",0).show();f.animate(a.next,{opacity:1},{duration:a.speed,complete:c})},slide:function(){a.apply(this,f.array(arguments))},fadeslide:function(){a.apply(this,f.array(arguments).concat([!0]))},doorslide:function(){a.apply(this,f.array(arguments).concat([!1,!0]))}}}(),g=function(){var a=this;this._theme=void 0;this._options={};this._playing=!1;this._playtime=
5E3;this._active=null;this._queue={length:0};this._data=[];this._dom={};this._thumbnails=[];this._firstrun=this._initialized=!1;this._stageHeight=this._stageWidth=0;this._target=void 0;this._id=Math.random();e.each("container stage images image-nav image-nav-left image-nav-right info info-text info-title info-description thumbnails thumbnails-list thumbnails-container thumb-nav-left thumb-nav-right loader counter tooltip".split(" "),function(b,c){a._dom[c]=f.create("galleria-"+c)});e.each("current total".split(" "),
function(b,c){a._dom[c]=f.create("galleria-"+c,"span")});var b=this._keyboard={keys:{UP:38,DOWN:40,LEFT:37,RIGHT:39,RETURN:13,ESCAPE:27,BACKSPACE:8,SPACE:32},map:{},bound:!1,press:function(c){var d=c.keyCode||c.which;d in b.map&&typeof b.map[d]==="function"&&b.map[d].call(a,c)},attach:function(a){var c,d;for(c in a)a.hasOwnProperty(c)&&(d=c.toUpperCase(),d in b.keys?b.map[b.keys[d]]=a[c]:b.map[d]=a[c]);if(!b.bound)b.bound=!0,F.bind("keydown",b.press)},detach:function(){b.bound=!1;b.map={};F.unbind("keydown",
b.press)}},c=this._controls={0:void 0,1:void 0,active:0,swap:function(){c.active=c.active?0:1},getActive:function(){return c[c.active]},getNext:function(){return c[1-c.active]}},d=this._carousel={next:a.$("thumb-nav-right"),prev:a.$("thumb-nav-left"),width:0,current:0,max:0,hooks:[],update:function(){var b=0,c=0,f=[0];e.each(a._thumbnails,function(a,d){d.ready&&(b+=d.outerWidth||e(d.container).outerWidth(!0),f[a+1]=b,c=Math.max(c,d.outerHeight||e(d.container).outerHeight(!0)))});a.$("thumbnails").css({width:b,
height:c});d.max=b;d.hooks=f;d.width=a.$("thumbnails-list").width();d.setClasses();a.$("thumbnails-container").toggleClass("galleria-carousel",b>d.width);d.width=a.$("thumbnails-list").width()},bindControls:function(){var b;d.next.bind("click",function(c){c.preventDefault();if(a._options.carouselSteps==="auto")for(b=d.current;b<d.hooks.length;b++){if(d.hooks[b]-d.hooks[d.current]>d.width){d.set(b-2);break}}else d.set(d.current+a._options.carouselSteps)});d.prev.bind("click",function(c){c.preventDefault();
if(a._options.carouselSteps==="auto")for(b=d.current;b>=0;b--)if(d.hooks[d.current]-d.hooks[b]>d.width){d.set(b+2);break}else{if(b===0){d.set(0);break}}else d.set(d.current-a._options.carouselSteps)})},set:function(a){for(a=Math.max(a,0);d.hooks[a-1]+d.width>=d.max&&a>=0;)a--;d.current=a;d.animate()},getLast:function(a){return(a||d.current)-1},follow:function(a){if(a===0||a===d.hooks.length-2)d.set(a);else{for(var b=d.current;d.hooks[b]-d.hooks[d.current]<d.width&&b<=d.hooks.length;)b++;a-1<d.current?
d.set(a-1):a+2>b&&d.set(a-b+d.current+2)}},setClasses:function(){d.prev.toggleClass("disabled",!d.current);d.next.toggleClass("disabled",d.hooks[d.current]+d.width>=d.max)},animate:function(){d.setClasses();var b=d.hooks[d.current]*-1;isNaN(b)||f.animate(a.get("thumbnails"),{left:b},{duration:a._options.carouselSpeed,easing:a._options.easing,queue:!1})}},j=this._tooltip={initialized:!1,open:!1,init:function(){j.initialized=!0;f.insertStyleTag(".galleria-tooltip{padding:3px 8px;max-width:50%;background:#ffe;color:#000;z-index:3;position:absolute;font-size:11px;line-height:1.3opacity:0;box-shadow:0 0 2px rgba(0,0,0,.4);-moz-box-shadow:0 0 2px rgba(0,0,0,.4);-webkit-box-shadow:0 0 2px rgba(0,0,0,.4);}");
a.$("tooltip").css("opacity",0.8);f.hide(a.get("tooltip"))},move:function(b){var c=a.getMousePosition(b).x,b=a.getMousePosition(b).y,d=a.$("tooltip"),e=b,f=d.outerHeight(!0)+1,g=d.outerWidth(!0),h=f+15,g=a.$("container").width()-g-2,f=a.$("container").height()-f-2;!isNaN(c)&&!isNaN(e)&&(c+=10,e-=30,c=Math.max(0,Math.min(g,c)),e=Math.max(0,Math.min(f,e)),b<h&&(e=h),d.css({left:c,top:e}))},bind:function(b,c){if(!g.TOUCH){j.initialized||j.init();var d=function(b,c){j.define(b,c);e(b).hover(function(){f.clearTimer("switch_tooltip");
a.$("container").unbind("mousemove",j.move).bind("mousemove",j.move).trigger("mousemove");j.show(b);g.utils.addTimer("tooltip",function(){a.$("tooltip").stop().show().animate({opacity:1});j.open=!0},j.open?0:500)},function(){a.$("container").unbind("mousemove",j.move);f.clearTimer("tooltip");a.$("tooltip").stop().animate({opacity:0},200,function(){a.$("tooltip").hide();f.addTimer("switch_tooltip",function(){j.open=!1},1E3)})})};typeof c==="string"?d(b in a._dom?a.get(b):b,c):e.each(b,function(b,c){d(a.get(b),
c)})}},show:function(b){var b=e(b in a._dom?a.get(b):b),c=b.data("tt"),d=function(a){l.setTimeout(function(a){return function(){j.move(a)}}(a),10);b.unbind("mouseup",d)};if(c=typeof c==="function"?c():c)a.$("tooltip").html(c.replace(/\s/,"&nbsp;")),b.bind("mouseup",d)},define:function(b,c){if(typeof c!=="function")var d=c,c=function(){return d};b=e(b in a._dom?a.get(b):b).data("tt",c);j.show(b)}},k=this._fullscreen={scrolled:0,active:!1,keymap:a._keyboard.map,enter:function(b){k.active=!0;f.hide(a.getActiveImage());
a.$("container").addClass("fullscreen");k.scrolled=u.scrollTop();f.forceStyles(a.get("container"),{position:"fixed",top:0,left:0,width:"100%",height:"100%",zIndex:1E4});var c={height:"100%",overflow:"hidden",margin:0,padding:0},d=a.getData();f.forceStyles(v().html,c);f.forceStyles(v().body,c);k.keymap=e.extend({},a._keyboard.map);a.attachKeyboard({escape:a.exitFullscreen,right:a.next,left:a.prev});if(d&&d.big&&d.image!==d.big){var c=new g.Picture,h=c.isCached(d.big),j=a.getIndex(),i=a._thumbnails[j];
a.trigger({type:g.LOADSTART,cached:h,index:j,imageTarget:a.getActiveImage(),thumbTarget:i});c.load(d.big,function(b){a._scaleImage(b,{complete:function(b){a.trigger({type:g.LOADFINISH,cached:h,index:j,imageTarget:b.image,thumbTarget:i});var c=a._controls.getActive().image;c&&e(c).width(b.image.width).height(b.image.height).attr("style",e(b.image).attr("style")).attr("src",b.image.src)}})})}a.rescale(function(){f.addTimer("fullscreen_enter",function(){f.show(a.getActiveImage());typeof b==="function"&&
b.call(a)},100);a.trigger(g.FULLSCREEN_ENTER)});u.resize(function(){k.scale()})},scale:function(){a.rescale()},exit:function(b){k.active=!1;f.hide(a.getActiveImage());a.$("container").removeClass("fullscreen");f.revertStyles(a.get("container"),v().html,v().body);l.scrollTo(0,k.scrolled);a.detachKeyboard();a.attachKeyboard(k.keymap);a.rescale(function(){f.addTimer("fullscreen_exit",function(){f.show(a.getActiveImage());typeof b==="function"&&b.call(a)},50);a.trigger(g.FULLSCREEN_EXIT)});u.unbind("resize",
k.scale)}},i=this._idle={trunk:[],bound:!1,add:function(a,b){if(a){i.bound||i.addEvent();var a=e(a),c={},d;for(d in b)b.hasOwnProperty(d)&&(c[d]=a.css(d));a.data("idle",{from:c,to:b,complete:!0,busy:!1});i.addTimer();i.trunk.push(a)}},remove:function(b){b=jQuery(b);e.each(i.trunk,function(c,d){d.length&&!d.not(b).length&&(a._idle.show(b),a._idle.trunk.splice(c,1))});i.trunk.length||(i.removeEvent(),f.clearTimer("idle"))},addEvent:function(){i.bound=!0;a.$("container").bind("mousemove click",i.showAll)},
removeEvent:function(){i.bound=!1;a.$("container").unbind("mousemove click",i.showAll)},addTimer:function(){f.addTimer("idle",function(){a._idle.hide()},a._options.idleTime)},hide:function(){a._options.idleMode&&(a.trigger(g.IDLE_ENTER),e.each(i.trunk,function(b,c){var d=c.data("idle");if(d)c.data("idle").complete=!1,f.animate(c,d.to,{duration:a._options.idleSpeed})}))},showAll:function(){f.clearTimer("idle");e.each(a._idle.trunk,function(b,c){a._idle.show(c)})},show:function(b){var c=b.data("idle");
if(!c.busy&&!c.complete)c.busy=!0,a.trigger(g.IDLE_EXIT),f.clearTimer("idle"),f.animate(b,c.from,{duration:a._options.idleSpeed/2,complete:function(){e(this).data("idle").busy=!1;e(this).data("idle").complete=!0}});i.addTimer()}},h=this._lightbox={width:0,height:0,initialized:!1,active:null,image:null,elems:{},keymap:!1,init:function(){a.trigger(g.LIGHTBOX_OPEN);if(!h.initialized){h.initialized=!0;var b={},c=a._options,d="",c={overlay:"position:fixed;display:none;opacity:"+c.overlayOpacity+";filter:alpha(opacity="+
c.overlayOpacity*100+");top:0;left:0;width:100%;height:100%;background:"+c.overlayBackground+";z-index:99990",box:"position:fixed;display:none;width:400px;height:400px;top:50%;left:50%;margin-top:-200px;margin-left:-200px;z-index:99991",shadow:"position:absolute;background:#000;width:100%;height:100%;",content:"position:absolute;background-color:#fff;top:10px;left:10px;right:10px;bottom:10px;overflow:hidden",info:"position:absolute;bottom:10px;left:10px;right:10px;color:#444;font:11px/13px arial,sans-serif;height:13px",
close:"position:absolute;top:10px;right:10px;height:20px;width:20px;background:#fff;text-align:center;cursor:pointer;color:#444;font:16px/22px arial,sans-serif;z-index:99999",image:"position:absolute;top:10px;left:10px;right:10px;bottom:30px;overflow:hidden;display:block;",prevholder:"position:absolute;width:50%;top:0;bottom:40px;cursor:pointer;",nextholder:"position:absolute;width:50%;top:0;bottom:40px;right:-1px;cursor:pointer;",prev:"position:absolute;top:50%;margin-top:-20px;height:40px;width:30px;background:#fff;left:20px;display:none;text-align:center;color:#000;font:bold 16px/36px arial,sans-serif",
next:"position:absolute;top:50%;margin-top:-20px;height:40px;width:30px;background:#fff;right:20px;left:auto;display:none;font:bold 16px/36px arial,sans-serif;text-align:center;color:#000",title:"float:left",counter:"float:right;margin-left:8px;"},j={};o===8&&(c.nextholder+="background:#000;filter:alpha(opacity=0);",c.prevholder+="background:#000;filter:alpha(opacity=0);");e.each(c,function(a,b){d+=".galleria-lightbox-"+a+"{"+b+"}"});f.insertStyleTag(d);e.each("overlay box content shadow title info close prevholder prev nextholder next counter image".split(" "),
function(c,d){a.addElement("lightbox-"+d);b[d]=h.elems[d]=a.get("lightbox-"+d)});h.image=new g.Picture;e.each({box:"shadow content close prevholder nextholder",info:"title counter",content:"info image",prevholder:"prev",nextholder:"next"},function(a,b){var c=[];e.each(b.split(" "),function(a,b){c.push("lightbox-"+b)});j["lightbox-"+a]=c});a.append(j);e(b.image).append(h.image.container);e(v().body).append(b.overlay,b.box);f.optimizeTouch(b.box);(function(a){return a.hover(function(){e(this).css("color",
"#bbb")},function(){e(this).css("color","#444")})})(e(b.close).bind("click",h.hide).html("&#215;"));e.each(["Prev","Next"],function(a,c){var d=e(b[c.toLowerCase()]).html(/v/.test(c)?"&#8249;&nbsp;":"&nbsp;&#8250;"),f=e(b[c.toLowerCase()+"holder"]);f.bind("click",function(){h["show"+c]()});o<8||g.TOUCH?d.show():f.hover(function(){d.show()},function(){d.stop().fadeOut(200)})});e(b.overlay).bind("click",h.hide);if(g.IPAD)a._options.lightboxTransitionSpeed=0}},rescale:function(b){var c=Math.min(u.width()-
40,h.width),d=Math.min(u.height()-60,h.height),d=Math.min(c/h.width,d/h.height),c=Math.round(h.width*d)+40,d=Math.round(h.height*d)+60,c={width:c,height:d,"margin-top":Math.ceil(d/2)*-1,"margin-left":Math.ceil(c/2)*-1};b?e(h.elems.box).css(c):e(h.elems.box).animate(c,{duration:a._options.lightboxTransitionSpeed,easing:a._options.easing,complete:function(){var b=h.image,c=a._options.lightboxFadeSpeed;a.trigger({type:g.LIGHTBOX_IMAGE,imageTarget:b.image});e(b.container).show();f.show(b.image,c);f.show(h.elems.info,
c)}})},hide:function(){h.image.image=null;u.unbind("resize",h.rescale);e(h.elems.box).hide();f.hide(h.elems.info);a.detachKeyboard();a.attachKeyboard(h.keymap);h.keymap=!1;f.hide(h.elems.overlay,200,function(){e(this).hide().css("opacity",a._options.overlayOpacity);a.trigger(g.LIGHTBOX_CLOSE)})},showNext:function(){h.show(a.getNext(h.active))},showPrev:function(){h.show(a.getPrev(h.active))},show:function(b){h.active=b=typeof b==="number"?b:a.getIndex();h.initialized||h.init();if(!h.keymap)h.keymap=
e.extend({},a._keyboard.map),a.attachKeyboard({escape:h.hide,right:h.showNext,left:h.showPrev});u.unbind("resize",h.rescale);var c=a.getData(b),d=a.getDataLength();f.hide(h.elems.info);h.image.load(c.big||c.image,function(a){h.width=a.original.width;h.height=a.original.height;e(a.image).css({width:"100.5%",height:"100.5%",top:0,zIndex:99998});f.hide(a.image);h.elems.title.innerHTML=c.title||"";h.elems.counter.innerHTML=b+1+" / "+d;u.resize(h.rescale);h.rescale()});e(h.elems.overlay).show();e(h.elems.box).show()}};
return this};g.prototype={constructor:g,init:function(a,b){var c=this,b=I(b);this._original={target:a,options:b,data:null};this._target=this._dom.target=a.nodeName?a:e(a).get(0);z.push(this);this._target?(this._options={autoplay:!1,carousel:!0,carouselFollow:!0,carouselSpeed:400,carouselSteps:"auto",clicknext:!1,dataConfig:function(){return{}},dataSelector:"img",dataSource:this._target,debug:void 0,easing:"galleria",extend:function(){},fullscreenDoubleTap:!0,height:"auto",idleMode:!0,idleTime:3E3,
idleSpeed:200,imageCrop:!1,imageMargin:0,imagePan:!1,imagePanSmoothness:12,imagePosition:"50%",initialTransition:void 0,keepSource:!1,lightbox:!1,lightboxFadeSpeed:200,lightboxTransitionSpeed:200,linkSourceTmages:!0,maxScaleRatio:void 0,minScaleRatio:void 0,overlayOpacity:0.85,overlayBackground:"#0b0b0b",pauseOnInteraction:!0,popupLinks:!1,preload:2,protect:!1,queue:!0,show:0,showInfo:!0,showCounter:!0,showImagenav:!0,swipe:!0,thumbCrop:!0,thumbEventType:"click",thumbFit:!0,thumbMargin:0,thumbQuality:"auto",
thumbnails:!0,transition:"fade",transitionInitial:void 0,transitionSpeed:400,useCanvas:!1,width:"auto"},this._options.initialTransition=this._options.initialTransition||this._options.transitionInitial,b&&b.debug===!1&&(A=!1),e(this._target).children().hide(),typeof g.theme==="object"?this._init():f.wait({until:function(){return typeof g.theme==="object"},success:function(){c._init.call(c)},error:function(){g.raise("No theme found.",!0)},timeout:5E3})):g.raise("Target not found.",!0)},_init:function(){var a=
this;if(this._initialized)return g.raise("Init failed: Gallery instance already initialized."),this;this._initialized=!0;if(!g.theme)return g.raise("Init failed: No theme found."),this;e.extend(!0,this._options,g.theme.defaults,this._original.options);(function(a){"getContext"in a&&(t=t||{elem:a,context:a.getContext("2d"),cache:{},length:0})})(n.createElement("canvas"));this.bind(g.DATA,function(){this._original.data=this._data;this.get("total").innerHTML=this.getDataLength();var b=this.$("container"),
c={width:0,height:0},d=function(){return a.$("stage").height()};f.wait({until:function(){e.each(["width","height"],function(d,e){c[e]=a._options[e]&&typeof a._options[e]==="number"?a._options[e]:Math.max(f.parseValue(b.css(e)),f.parseValue(a.$("target").css(e)),b[e](),a.$("target")[e]());b[e](c[e])});return d()&&c.width&&c.height>10},success:function(){g.WEBKIT?l.setTimeout(function(){a._run()},1):a._run()},error:function(){d()?g.raise("Could not extract sufficient width/height of the gallery container. Traced measures: width:"+
c.width+"px, height: "+c.height+"px.",!0):g.raise("Could not extract a stage height from the CSS. Traced height: "+d()+"px.",!0)},timeout:2E3})});this.append({"info-text":["info-title","info-description"],info:["info-text"],"image-nav":["image-nav-right","image-nav-left"],stage:["images","loader","counter","image-nav"],"thumbnails-list":["thumbnails"],"thumbnails-container":["thumb-nav-left","thumbnails-list","thumb-nav-right"],container:["stage","thumbnails-container","info","tooltip"]});f.hide(this.$("counter").append(this.get("current"),
" / ",this.get("total")));this.setCounter("&#8211;");f.hide(a.get("tooltip"));this.$("container").addClass(g.TOUCH?"touch":"notouch");e.each(Array(2),function(b){var c=new g.Picture;e(c.container).css({position:"absolute",top:0,left:0});a.$("images").append(c.container);a._controls[b]=c});this.$("images").css({position:"relative",top:0,left:0,width:"100%",height:"100%"});this.$("thumbnails, thumbnails-list").css({overflow:"hidden",position:"relative"});this.$("image-nav-right, image-nav-left").bind("click",
function(b){a._options.clicknext&&b.stopPropagation();a._options.pauseOnInteraction&&a.pause();b=/right/.test(this.className)?"next":"prev";a[b]()});e.each(["info","counter","image-nav"],function(b,c){a._options["show"+c.substr(0,1).toUpperCase()+c.substr(1).replace(/-/,"")]===!1&&f.moveOut(a.get(c.toLowerCase()))});this.load();if(!this._options.keep_source&&!o)this._target.innerHTML="";this.$("target").append(this.get("container"));this._options.carousel&&this.bind(g.THUMBNAIL,function(){this.updateCarousel()});
this._options.swipe&&(function(b){var c=[0,0],d=[0,0],e=!1,g=0,i,h={start:"touchstart",move:"touchmove",stop:"touchend"},m=function(a){a.originalEvent.touches&&a.originalEvent.touches.length>1||(i=a.originalEvent.touches?a.originalEvent.touches[0]:a,d=[i.pageX,i.pageY],c[0]||(c=d),Math.abs(c[0]-d[0])>10&&a.preventDefault())},q=function(i){b.unbind(h.move,m);i.originalEvent.touches&&i.originalEvent.touches.length||e?e=!e:(f.timestamp()-g<1E3&&Math.abs(c[0]-d[0])>30&&Math.abs(c[1]-d[1])<100&&(i.preventDefault(),
a[c[0]>d[0]?"next":"prev"]()),c=d=[0,0])};b.bind(h.start,function(a){a.originalEvent.touches&&a.originalEvent.touches.length>1||(i=a.originalEvent.touches?a.originalEvent.touches[0]:a,g=f.timestamp(),c=d=[i.pageX,i.pageY],b.bind(h.move,m).one(h.stop,q))})}(a.$("images")),this._options.fullscreenDoubleTap&&this.$("stage").bind("touchstart",function(){var b,c,d,e,f,i;return function(h){i=g.utils.timestamp();c=(h.originalEvent.touches?h.originalEvent.touches[0]:h).pageX;d=(h.originalEvent.touches?h.originalEvent.touches[0]:
h).pageY;i-b<500&&c-e<20&&d-f<20?(a.toggleFullscreen(),h.preventDefault(),a.$("stage").unbind("touchend",arguments.callee)):(b=i,e=c,f=d)}}()));f.optimizeTouch(this.get("container"));return this},_createThumbnails:function(){this.get("total").innerHTML=this.getDataLength();var a,b,c,d,j,k=this,i=this._options,h=function(){var a=k.$("thumbnails").find(".active");if(!a.length)return!1;return a.find("img").attr("src")}(),m=typeof i.thumbnails==="string"?i.thumbnails.toLowerCase():null,q=function(a){return n.defaultView&&
n.defaultView.getComputedStyle?n.defaultView.getComputedStyle(c.container,null)[a]:j.css(a)},x=function(a,b,c){return function(){e(c).append(a);k.trigger({type:g.THUMBNAIL,thumbTarget:a,index:b})}},o=function(a){i.pauseOnInteraction&&k.pause();var b=e(a.currentTarget).data("index");k.getIndex()!==b&&k.show(b);a.preventDefault()},p=function(a){a.scale({width:a.data.width,height:a.data.height,crop:i.thumbCrop,margin:i.thumbMargin,canvas:i.useCanvas,complete:function(a){var b=["left","top"],c,d;e.each(["Width",
"Height"],function(f,g){c=g.toLowerCase();if((i.thumbCrop!==!0||i.thumbCrop===c)&&i.thumbFit)d={},d[c]=a[c],e(a.container).css(d),d={},d[b[f]]=0,e(a.image).css(d);a["outer"+g]=e(a.container)["outer"+g](!0)});f.toggleQuality(a.image,i.thumbQuality===!0||i.thumbQuality==="auto"&&a.original.width<a.width*3);k.trigger({type:g.THUMBNAIL,thumbTarget:a.image,index:a.data.order})}})};this._thumbnails=[];this.$("thumbnails").empty();for(a=0;this._data[a];a++)d=this._data[a],i.thumbnails===!0?(c=new g.Picture(a),
b=d.thumb||d.image,this.$("thumbnails").append(c.container),j=e(c.container),c.data={width:f.parseValue(q("width")),height:f.parseValue(q("height")),order:a},i.thumbFit&&i.thumbCrop!==!0?j.css({width:0,height:0}):j.css({width:c.data.width,height:c.data.height}),c.load(b,p),i.preload==="all"&&c.add(d.image)):m==="empty"||m==="numbers"?(c={container:f.create("galleria-image"),image:f.create("img","span"),ready:!0},m==="numbers"&&e(c.image).text(a+1),this.$("thumbnails").append(c.container),l.setTimeout(x(c.image,
a,c.container),50+a*20)):c={container:null,image:null},e(c.container).add(i.keepSource&&i.linkSourceImages?d.original:null).data("index",a).bind(i.thumbEventType,o),h===b&&e(c.container).addClass("active"),this._thumbnails.push(c)},_run:function(){var a=this;a._createThumbnails();f.wait({until:function(){g.OPERA&&a.$("stage").css("display","inline-block");a._stageWidth=a.$("stage").width();a._stageHeight=a.$("stage").height();return a._stageWidth&&a._stageHeight>50},success:function(){C.push(a);f.show(a.get("counter"));
a._options.carousel&&a._carousel.bindControls();if(a._options.autoplay){a.pause();if(typeof a._options.autoplay==="number")a._playtime=a._options.autoplay;a.trigger(g.PLAY);a._playing=!0}a._firstrun?typeof a._options.show==="number"&&a.show(a._options.show):(a._firstrun=!0,a._options.clicknext&&!g.TOUCH&&(e.each(a._data,function(a,c){delete c.link}),a.$("stage").css({cursor:"pointer"}).bind("click",function(){a._options.pauseOnInteraction&&a.pause();a.next()})),g.History&&g.History.change(function(b){b=
parseInt(b.value.replace(/\//,""),10);isNaN(b)?l.history.go(-1):a.show(b,void 0,!0)}),e.each(g.ready.callbacks,function(){this.call(a,a._options)}),a.trigger(g.READY),g.theme.init.call(a,a._options),a._options.extend.call(a,a._options),/^[0-9]{1,4}$/.test(G)&&g.History?a.show(G,void 0,!0):a._data[a._options.show]&&a.show(a._options.show))},error:function(){g.raise("Stage width or height is too small to show the gallery. Traced measures: width:"+a._stageWidth+"px, height: "+a._stageHeight+"px.",!0)}})},
load:function(a,b,c){var d=this;this._data=[];this._thumbnails=[];this.$("thumbnails").empty();typeof b==="function"&&(c=b,b=null);a=a||this._options.dataSource;b=b||this._options.dataSelector;c=c||this._options.dataConfig;/^function Object/.test(a.constructor)&&(a=[a]);if(a.constructor===Array)return this.validate(a)?(this._data=a,this._parseData().trigger(g.DATA)):g.raise("Load failed: JSON Array not valid."),this;e(a).find(b).each(function(a,b){var b=e(b),f={},g=b.parent(),m=g.attr("href"),g=g.attr("rel"),
q=/\.(png|gif|jpg|jpeg)(\?.*)?$/i;if(q.test(m))f.image=m,f.big=q.test(g)?g:m;else if(m)f.link=m;d._data.push(e.extend({title:b.attr("title")||"",thumb:b.attr("src"),image:b.attr("src"),big:b.attr("src"),description:b.attr("alt")||"",link:b.attr("longDesc"),original:b.get(0)},f,c(b)))});this.getDataLength()?this.trigger(g.DATA):g.raise("Load failed: no data found.");return this},_parseData:function(){var a=this;e.each(this._data,function(b,c){if("thumb"in c===!1)a._data[b].thumb=c.image;if(!1 in c)a._data[b].big=
c.image});return this},splice:function(){Array.prototype.splice.apply(this._data,f.array(arguments));return this._parseData()._createThumbnails()},push:function(){Array.prototype.push.apply(this._data,f.array(arguments));return this._parseData()._createThumbnails()},_getActive:function(){return this._controls.getActive()},validate:function(){return!0},bind:function(a,b){a=B(a);this.$("container").bind(a,this.proxy(b));return this},unbind:function(a){a=B(a);this.$("container").unbind(a);return this},
trigger:function(a){a=typeof a==="object"?e.extend(a,{scope:this}):{type:B(a),scope:this};this.$("container").trigger(a);return this},addIdleState:function(){this._idle.add.apply(this._idle,f.array(arguments));return this},removeIdleState:function(){this._idle.remove.apply(this._idle,f.array(arguments));return this},enterIdleMode:function(){this._idle.hide();return this},exitIdleMode:function(){this._idle.showAll();return this},enterFullscreen:function(){this._fullscreen.enter.apply(this,f.array(arguments));
return this},exitFullscreen:function(){this._fullscreen.exit.apply(this,f.array(arguments));return this},toggleFullscreen:function(){this._fullscreen[this.isFullscreen()?"exit":"enter"].apply(this,f.array(arguments));return this},bindTooltip:function(){this._tooltip.bind.apply(this._tooltip,f.array(arguments));return this},defineTooltip:function(){this._tooltip.define.apply(this._tooltip,f.array(arguments));return this},refreshTooltip:function(){this._tooltip.show.apply(this._tooltip,f.array(arguments));
return this},openLightbox:function(){this._lightbox.show.apply(this._lightbox,f.array(arguments));return this},closeLightbox:function(){this._lightbox.hide.apply(this._lightbox,f.array(arguments));return this},getActiveImage:function(){return this._getActive().image||void 0},getActiveThumb:function(){return this._thumbnails[this._active].image||void 0},getMousePosition:function(a){return{x:a.pageX-this.$("container").offset().left,y:a.pageY-this.$("container").offset().top}},addPan:function(a){if(this._options.imageCrop!==
!1){var a=e(a||this.getActiveImage()),b=this,c=a.width()/2,d=a.height()/2,g=parseInt(a.css("left"),10),k=parseInt(a.css("top"),10),i=g||0,h=k||0,m=0,q=0,l=!1,n=f.timestamp(),p=0,r=0,s=function(b,c,d){if(b>0&&(r=Math.round(Math.max(b*-1,Math.min(0,c))),p!==r))if(p=r,o===8)a.parent()["scroll"+d](r*-1);else b={},b[d.toLowerCase()]=r,a.css(b)},K=function(a){if(!(f.timestamp()-n<50))l=!0,c=b.getMousePosition(a).x,d=b.getMousePosition(a).y};o===8&&(a.parent().scrollTop(h*-1).scrollLeft(i*-1),a.css({top:0,
left:0}));this.$("stage").unbind("mousemove",K).bind("mousemove",K);f.addTimer("pan",function(){l&&(m=a.width()-b._stageWidth,q=a.height()-b._stageHeight,g=c/b._stageWidth*m*-1,k=d/b._stageHeight*q*-1,i+=(g-i)/b._options.imagePanSmoothness,h+=(k-h)/b._options.imagePanSmoothness,s(q,h,"Top"),s(m,i,"Left"))},50,!0);return this}},proxy:function(a,b){if(typeof a!=="function")return function(){};b=b||this;return function(){return a.apply(b,f.array(arguments))}},removePan:function(){this.$("stage").unbind("mousemove");
f.clearTimer("pan");return this},addElement:function(){var a=this._dom;e.each(f.array(arguments),function(b,c){a[c]=f.create("galleria-"+c)});return this},attachKeyboard:function(){this._keyboard.attach.apply(this._keyboard,f.array(arguments));return this},detachKeyboard:function(){this._keyboard.detach.apply(this._keyboard,f.array(arguments));return this},appendChild:function(a,b){this.$(a).append(this.get(b)||b);return this},prependChild:function(a,b){this.$(a).prepend(this.get(b)||b);return this},
remove:function(){this.$(f.array(arguments).join(",")).remove();return this},append:function(a){var b,c;for(b in a)if(a.hasOwnProperty(b))if(a[b].constructor===Array)for(c=0;a[b][c];c++)this.appendChild(b,a[b][c]);else this.appendChild(b,a[b]);return this},_scaleImage:function(a,b){b=e.extend({width:this._stageWidth,height:this._stageHeight,crop:this._options.imageCrop,max:this._options.maxScaleRatio,min:this._options.minScaleRatio,margin:this._options.imageMargin,position:this._options.imagePosition},
b);(a||this._controls.getActive()).scale(b);return this},updateCarousel:function(){this._carousel.update();return this},rescale:function(a,b,c){var d=this;typeof a==="function"&&(c=a,a=void 0);var e=function(){d._stageWidth=a||d.$("stage").width();d._stageHeight=b||d.$("stage").height();d._scaleImage();d._options.carousel&&d.updateCarousel();d.trigger(g.RESCALE);typeof c==="function"&&c.call(d)};g.WEBKIT&&!a&&!b?f.addTimer("scale",e,10):e.call(d);return this},refreshImage:function(){this._scaleImage();
this._options.imagePan&&this.addPan();return this},show:function(a,b,c){if(!(a===!1||!this._options.queue&&this._queue.stalled))if(a=Math.max(0,Math.min(parseInt(a,10),this.getDataLength()-1)),b=typeof b!=="undefined"?!!b:a<this.getIndex(),!c&&g.History)g.History.value(a.toString());else return this._active=a,Array.prototype.push.call(this._queue,{index:a,rewind:b}),this._queue.stalled||this._show(),this},_show:function(){var a=this,b=this._queue[0],c=this.getData(b.index);if(c){var d=this.isFullscreen()&&
"big"in c?c.big:c.image,j=this._controls.getActive(),k=this._controls.getNext(),i=k.isCached(d),h=this._thumbnails[b.index],m=function(b,c,d,h,i){return function(){a._queue.stalled=!1;f.toggleQuality(c.image,a._options.imageQuality);e(d.container).css({zIndex:0,opacity:0}).show();e(c.container).css({zIndex:1,opacity:1}).show();a._controls.swap();a._options.imagePan&&a.addPan(c.image);(b.link||a._options.lightbox)&&e(c.image).css({cursor:"pointer"}).bind("mouseup",function(){b.link?a._options.popupLinks?
l.open(b.link,"_blank"):l.location.href=b.link:a.openLightbox()});Array.prototype.shift.call(a._queue);a._queue.length&&a._show();a._playCheck();a.trigger({type:g.IMAGE,index:h.index,imageTarget:c.image,thumbTarget:i.image})}}(c,k,j,b,h);this._options.carousel&&this._options.carouselFollow&&this._carousel.follow(b.index);if(this._options.preload){var q,n,c=this.getNext(),o;try{for(n=this._options.preload;n>0;n--)q=new g.Picture,o=a.getData(c),q.add(this.isFullscreen()&&"big"in o?o.big:o.image),c=
a.getNext(c)}catch(p){}}f.show(k.container);e(a._thumbnails[b.index].container).addClass("active").siblings(".active").removeClass("active");a.trigger({type:g.LOADSTART,cached:i,index:b.index,imageTarget:k.image,thumbTarget:h.image});k.load(d,function(c){a._scaleImage(c,{complete:function(c){"image"in j&&f.toggleQuality(j.image,!1);f.toggleQuality(c.image,!1);a._queue.stalled=!0;a.removePan();a.setInfo(b.index);a.setCounter(b.index);a.trigger({type:g.LOADFINISH,cached:i,index:b.index,imageTarget:c.image,
thumbTarget:a._thumbnails[b.index].image});var d=j.image===null&&a._options.initialTransition!==void 0?a._options.initialTransition:a._options.transition;d in E===!1?m():E[d].call(a,{prev:j.container,next:c.container,rewind:b.rewind,speed:a._options.transitionSpeed||400},m)}})})}},getNext:function(a){a=typeof a==="number"?a:this.getIndex();return a===this.getDataLength()-1?0:a+1},getPrev:function(a){a=typeof a==="number"?a:this.getIndex();return a===0?this.getDataLength()-1:a-1},next:function(){this.getDataLength()>
1&&this.show(this.getNext(),!1);return this},prev:function(){this.getDataLength()>1&&this.show(this.getPrev(),!0);return this},get:function(a){return a in this._dom?this._dom[a]:null},getData:function(a){return a in this._data?this._data[a]:this._data[this._active]},getDataLength:function(){return this._data.length},getIndex:function(){return typeof this._active==="number"?this._active:!1},getStageHeight:function(){return this._stageHeight},getStageWidth:function(){return this._stageWidth},getOptions:function(a){return typeof a===
"undefined"?this._options:this._options[a]},setOptions:function(a,b){typeof a==="object"?e.extend(this._options,a):this._options[a]=b;return this},play:function(a){this._playing=!0;this._playtime=a||this._playtime;this._playCheck();this.trigger(g.PLAY);return this},pause:function(){this._playing=!1;this.trigger(g.PAUSE);return this},playToggle:function(a){return this._playing?this.pause():this.play(a)},isPlaying:function(){return this._playing},isFullscreen:function(){return this._fullscreen.active},
_playCheck:function(){var a=this,b=0,c=f.timestamp(),d="play"+this._id;if(this._playing){f.clearTimer(d);var e=function(){b=f.timestamp()-c;b>=a._playtime&&a._playing?(f.clearTimer(d),a.next()):a._playing&&(a.trigger({type:g.PROGRESS,percent:Math.ceil(b/a._playtime*100),seconds:Math.floor(b/1E3),milliseconds:b}),f.addTimer(d,e,20))};f.addTimer(d,e,20)}},setIndex:function(a){this._active=a;return this},setCounter:function(a){typeof a==="number"?a++:typeof a==="undefined"&&(a=this.getIndex()+1);this.get("current").innerHTML=
a;if(o){var a=this.$("counter"),b=a.css("opacity"),c=a.attr("style");c&&parseInt(b,10)===1?a.attr("style",c.replace(/filter[^\;]+\;/i,"")):this.$("counter").css("opacity",b)}return this},setInfo:function(a){var b=this,c=this.getData(a);e.each(["title","description"],function(a,e){var f=b.$("info-"+e);c[e]?f[c[e].length?"show":"hide"]().html(c[e]):f.empty().hide()});return this},hasInfo:function(a){var b="title description".split(" "),c;for(c=0;b[c];c++)if(this.getData(a)[b[c]])return!0;return!1},
jQuery:function(a){var b=this,c=[];e.each(a.split(","),function(a,d){d=e.trim(d);b.get(d)&&c.push(d)});var d=e(b.get(c.shift()));e.each(c,function(a,c){d=d.add(b.get(c))});return d},$:function(){return this.jQuery.apply(this,f.array(arguments))}};e.each(H,function(a,b){var c=/_/.test(b)?b.replace(/_/g,""):b;g[b.toUpperCase()]="galleria."+c});e.extend(g,{IE9:o===9,IE8:o===8,IE7:o===7,IE6:o===6,IE:!!o,WEBKIT:/webkit/.test(y),SAFARI:/safari/.test(y),CHROME:/chrome/.test(y),QUIRK:o&&n.compatMode&&n.compatMode===
"BackCompat",MAC:/mac/.test(navigator.platform.toLowerCase()),OPERA:!!l.opera,IPHONE:/iphone/.test(y),IPAD:/ipad/.test(y),ANDROID:/android/.test(y),TOUCH:"ontouchstart"in document});g.addTheme=function(a){a.name||g.raise("No theme name specified");a.defaults=typeof a.defaults!=="object"?{}:I(a.defaults);var b=!1,c;typeof a.css==="string"?(e("link").each(function(d,e){c=RegExp(a.css);if(c.test(e.href))return b=!0,g.theme=a,!1}),b||e("script").each(function(d,e){c=RegExp("galleria\\."+a.name.toLowerCase()+
"\\.");c.test(e.src)&&(b=e.src.replace(/[^\/]*$/,"")+a.css,f.addTimer("css",function(){f.loadCSS(b,"galleria-theme",function(){g.theme=a})},1))}),b||g.raise("No theme CSS loaded")):g.theme=a;return a};g.loadTheme=function(a,b){var c=!1,d=C.length;g.theme=void 0;f.loadScript(a,function(){c=!0});f.wait({until:function(){return c},error:function(){g.raise("Theme at "+a+" could not load, check theme path.",!0)},success:function(){if(d){var a=[];e.each(g.get(),function(c,d){var f=e.extend(d._original.options,
{data_source:d._data},b);d.$("container").remove();var m=new g;m._id=d._id;m.init(d._original.target,f);a.push(m)});C=a}},timeout:2E3})};g.get=function(a){if(z[a])return z[a];else if(typeof a!=="number")return z;else g.raise("Gallery index "+a+" not found")};g.addTransition=function(a,b){E[a]=b};g.utils=f;g.log=function(){try{l.console.log.apply(l.console,f.array(arguments))}catch(a){try{l.opera.postError.apply(l.opera,arguments)}catch(b){l.alert(f.array(arguments).split(", "))}}};g.ready=function(a){g.ready.callbacks.push(a)};
g.ready.callbacks=[];g.raise=function(a,b){var c=b?"Fatal error":"Error",d=function(a){var d='<div style="padding:4px;margin:0 0 2px;background:#'+(b?"811":"222")+'";>'+(b?"<strong>"+c+": </strong>":"")+a+"</div>";e.each(z,function(){var a=this.$("errors"),b=this.$("target");a.length||(b.css("position","relative"),a=this.addElement("errors").appendChild("target","errors").$("errors").css({color:"#fff",position:"absolute",top:0,left:0,zIndex:1E5}));a.append(d)})};if(A){if(d(a),b)throw Error(c+": "+
a);}else b&&!J&&(J=!0,b=!1,d("Image gallery could not load."))};g.Picture=function(a){this.id=a||null;this.image=null;this.container=f.create("galleria-image");e(this.container).css({overflow:"hidden",position:"relative"});this.original={width:0,height:0};this.loaded=this.ready=!1};g.Picture.prototype={cache:{},add:function(a){var b=0,c=this,d=new Image,f=function(){if((!this.width||!this.height)&&b<1E3)b++,e(d).load(f).attr("src",a+"?"+(new Date).getTime());c.original={height:this.height,width:this.width};
c.cache[a]=a;c.loaded=!0};e(d).css("display","block");if(c.cache[a])return d.src=a,f.call(d),d;e(d).load(f).error(function(){g.raise("image could not load: "+a)}).attr("src",a);return d},show:function(){f.show(this.image)},hide:function(){f.moveOut(this.image)},clear:function(){this.image=null},isCached:function(a){return!!this.cache[a]},load:function(a,b){var c=this;e(this.container).empty(!0);this.image=this.add(a);f.hide(this.image);e(this.container).append(this.image);f.wait({until:function(){return c.loaded&&
c.image.complete&&c.original.width&&c.image.width},success:function(){l.setTimeout(function(){b.call(c,c)},1)},error:function(){l.setTimeout(function(){b.call(c,c)},1);g.raise("image not loaded in 30 seconds: "+a)},timeout:3E4});return this.container},scale:function(a){a=e.extend({width:0,height:0,min:void 0,max:void 0,margin:0,complete:function(){},position:"center",crop:!1,canvas:!1},a);if(!this.image)return this.container;var b,c,d=this,j=e(d.container),k;f.wait({until:function(){b=a.width||j.width()||
f.parseValue(j.css("width"));c=a.height||j.height()||f.parseValue(j.css("height"));return b&&c},success:function(){var g=(b-a.margin*2)/d.original.width,h=(c-a.margin*2)/d.original.height,j={"true":Math.max(g,h),width:g,height:h,"false":Math.min(g,h)}[a.crop.toString()],g="";a.max&&(j=Math.min(a.max,j));a.min&&(j=Math.max(a.min,j));e.each(["width","height"],function(a,b){e(d.image)[b](d[b]=d.image[b]=Math.round(d.original[b]*j))});e(d.container).width(b).height(c);if(a.canvas&&t)t.elem.width=d.width,
t.elem.height=d.height,g=d.image.src+":"+d.width+"x"+d.height,d.image.src=t.cache[g]||function(a){t.context.drawImage(d.image,0,0,d.original.width*j,d.original.height*j);try{return k=t.elem.toDataURL(),t.length+=k.length,t.cache[a]=k}catch(b){return d.image.src}}(g);var l={},n={},g=function(a,b,c){var g=0;/\%/.test(a)?(a=parseInt(a,10)/100,b=d.image[b]||e(d.image)[b](),g=Math.ceil(b*-1*a+c*a)):g=f.parseValue(a);return g},o={top:{top:0},left:{left:0},right:{left:"100%"},bottom:{top:"100%"}};e.each(a.position.toLowerCase().split(" "),
function(a,b){b==="center"&&(b="50%");l[a?"top":"left"]=b});e.each(l,function(a,b){o.hasOwnProperty(b)&&e.extend(n,o[b])});l=l.top?e.extend(l,n):n;l=e.extend({top:"50%",left:"50%"},l);e(d.image).css({position:"relative",top:g(l.top,"height",c),left:g(l.left,"width",b)});d.show();d.ready=!0;a.complete.call(d,d)},error:function(){g.raise("Could not scale image: "+d.image.src)},timeout:1E3});return this}};e.extend(e.easing,{galleria:function(a,b,c,d,e){if((b/=e/2)<1)return d/2*b*b*b+c;return d/2*((b-=
2)*b*b+2)+c},galleriaIn:function(a,b,c,d,e){return d*(b/=e)*b+c},galleriaOut:function(a,b,c,d,e){return-d*(b/=e)*(b-2)+c}});e.fn.galleria=function(a){return this.each(function(){(new g).init(this,a)})};l.Galleria=g})(jQuery);

// Load the classic theme
    Galleria.loadTheme('http://www.wlv.ac.uk/files/galleries/themes/classic/galleria.classic.min.js');
    
    // Initialize Galleria
    $('.gallery').galleria({
	autoplay: 5000
	});
