/*	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 strip_width;		var wrapper_width;		var item_count = 0;		var slide_method;		var img_path;		var paused = false;		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);					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*i)+'px');						} else if (i<=(item_count-strip_size)) {							i = (i%item_count)+item_count;							iterator = i;							j_filmstrip.css('left','-'+(opts.frame_width*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+'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;}			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() {						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',				'overflow':'hidden',				'display':'none'			});			$('.panel iframe',j_panels).css({				'width':opts.panel_width+'px',				'height':(opts.panel_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);			}			j_filmstrip.css({				'width':strip_width+'px'			});			var pointer = $('<div></div>');			pointer.attr('id','pointer').appendTo(j_gallery);			j_pointer = $('#pointer',j_gallery);			if(has_panels) {				var pointerArrow = $('<img />');				pointerArrow.attr('src',img_path+opts.nav_theme+'/selectFrame.png').appendTo($('#pointer'));				pointerArrow.addClass('png');			}						//If the filmstrip is animating, move the strip to the middle third			if(slide_method=='strip') {				j_filmstrip.css('left','-'+(opts.frame_width*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			$('<span />').addClass('slideBannerRightBtn').appendTo(j_gallery).click(showNextItem);			$('<span />').addClass('slideBannerLeftBtn').appendTo(j_gallery).click(showPrevItem);		};/************************************************//*	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(/jquery\.galleryview/)){					img_path = s.attr('src').split('jquery.galleryview')[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 = j_panels.length;						strip_size = 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 = opts.panel_width;										//Height of gallery block = screen + filmstrip					gallery_height = opts.panel_height+opts.frame_height;										//Width of filmstrip					if(slide_method == 'pointer') {strip_width = (opts.frame_width*item_count);}					else {strip_width = (opts.frame_width*item_count*3);}										//Width of filmstrip wrapper (to hide overflow)					wrapper_width = strip_size*opts.frame_width;						/************************************************/			/*	Build filmstrip and/or panels				*/			/************************************************/					if(has_filmstrip) {						buildFilmstrip();					}					if(has_panels) {						buildPanels();					}						/************************************************/			/*	Add events to various elements				*/			/************************************************/					if(has_filmstrip) enableFrameClicking();									/************************************************/			/*	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: 400,		panel_height: 300,		frame_width: 80,		frame_height: 80,		filmstrip_size: 3,		transition_speed: 400,		transition_interval: 6000,		background_color: 'black',		border: '1px solid black',		nav_theme: 'dark',		easing: 'swing',		filmstrip_position: 'bottom',		fade_panels: true,		pause_on_hover: false	};})(jQuery);
