/* ------------------------------------------------------------------------
	Class: prettyPhoto
	Use: Lightbox clone for jQuery
	Author: Stephane Caron (http://www.no-margin-for-errors.com)
	Version: 2.5.6
------------------------------------------------------------------------- */

(function($) {

	var defaults = {
		animationSpeed: 'normal', /* fast/slow/normal */
		opacity: 0.80, /* Value between 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		default_width: 720,
		default_height: 510,
		description_height: 60,
		counter_separator_label: ' of ', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
		wmode: 'opaque', /* Set the flash wmode attribute */
		autoplay: true, /* Automatically start videos: True/False */
		modal: false, /* If set to true, only the close button will close the window */
		changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
		callback: function(){}, /* Called when prettyPhoto is closed */
		markup_location: 'body',
		markup: '<div class="pp_pic_holder"> \
				<div class="pp_top"> \
					<div class="pp_left"></div> \
					<div class="pp_middle"></div> \
					<div class="pp_right"><a class="pp_close" href="#">Close</a></div> \
				</div> \
				<div class="pp_content_container"> \
					<div class="pp_left"> \
					<div class="pp_right"> \
						<div class="pp_content"> \
							<div class="pp_loaderIcon"></div> \
							<div class="pp_fade"> \
								<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
								<div class="pp_hoverContainer"> \
									<a class="pp_next" href="#">next</a> \
									<a class="pp_previous" href="#">previous</a> \
								</div> \
								<div class="pp_full_res"></div> \
								<div class="pp_details clearfix"> \
									<p class="pp_description"></p> \
									<div class="pp_nav"> \
										<p class="currentTextHolder">0/0</p> \
										<a href="#" class="pp_arrow_next">Next</a> \
										<a href="#" class="pp_arrow_previous">Previous</a> \
									</div> \
								</div> \
							</div> \
						</div> \
					</div> \
					</div> \
				</div> \
				<div class="pp_bottom"> \
					<div class="pp_left"></div> \
					<div class="pp_middle"></div> \
					<div class="pp_right"></div> \
				</div> \
			</div> \
			<div class="pp_overlay"></div> \
			<div class="ppt"></div>',
		image_markup: '<img class="fullResImage" src="" />',
		flash_markup: '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}"><param name="wmode" value="{wmode}" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="sameDomain" /><param name="movie" value="{path}" /><embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="sameDomain" width="{width}" height="{height}" wmode="{wmode}"></embed></object>',
		quicktime_markup: '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="{height}" width="{width}"><param name="src" value="{path}"><param name="autoplay" value="{autoplay}"><param name="type" value="video/quicktime"><embed src="{path}" height="{height}" width="{width}" autoplay="{autoplay}" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>',
		iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
		inline_markup: '<div class="pp_inline clearfix">{content}</div>'
	} ;

	$.fn.prettyPhoto = function( settings ) {
		var prettyPhoto = new $.prettyPhoto() ;
		prettyPhoto.init( settings ) ;
		return this.each( function() {
			$(this).data( 'prettyPhoto', prettyPhoto  ) ;
			$(this).bind('click',function(){
				var _self = this; // Fix scoping
				
				// Find out if the picture is part of a set
				var theRel = $(this).attr('rel');
				galleryRegExp = /\[(?:.*)\]/;
				var theGallery = galleryRegExp.exec(theRel);
				
				// Build the gallery array
				var images = new Array();
				var titles = new Array() ;
				var descriptions = new Array();
				if(theGallery){
					$('a[rel*='+theGallery+']').each(function(i){
						if($(this)[0] === $(_self)[0]) setPosition = i; // Get the position in the set
						images.push($(this).attr('href'));
						titles.push($(this).find('img').attr('alt'));
						descriptions.push($(this).attr('title'));
					});
				}else{
					images = $(this).attr('href');
					titles = ($(this).find('img').attr('alt')) ?  $(this).find('img').attr('alt') : '';
					descriptions = ($(this).attr('title')) ?  $(this).attr('title') : '';
				}

				$(this).data( 'prettyPhoto' ).open(images,titles,descriptions);
				return false;
			});
		})
	} ;

	$.prettyPhoto = function() {
	} ;

    $.prettyPhoto.fn = $.prettyPhoto.prototype = {
    		prettyPhoto: '2.5.6' 
    };
    
	$.prettyPhoto.prototype.init = function ( options ) {
		this.settings = $.extend({}, defaults, options );
		this.setPosition = 0 ;
		this.scrollPos = this.getScroll() ;
		this.doresize = true ;
		this.percentBased = false ;
		this.doresize = true ;
		this.handlersBound = false ;

		// 	Fallback to a supported theme for IE6
		if($.browser.msie && parseInt($.browser.version) == 6)
			this.settings.theme = "light_square";

		this.buildOverlay(); // If the overlay is not there, inject it!
		
		this.centerOverlay(); // Center it
	}
	
	$.prettyPhoto.prototype.buildOverlay = function (){
		// Inject the markup
		if($( this.settings.markup_location + ' .pp_overlay').size()==0) 
			$(this.settings.markup_location).append(this.settings.markup);
		
		// Set my global selectors
		this.pp_pic_holder = $(this.settings.markup_location + ' .pp_pic_holder');
		this.pp_pic_holder.attr('class','pp_pic_holder ' + this.settings.theme); // Set the proper theme
		this.ppt = $(this.settings.markup_location + ' .ppt');
		this.pp_overlay = $(this.settings.markup_location + ' div.pp_overlay');
		this.pp_overlay.css({ 'opacity':0, 'height':$(document).height() }) ;
	}

	$.prettyPhoto.prototype.bindHandlers = function (){
		if ( this.handlersBound )
			return ;
		
		this.handlersBound = true ;
		var self = this ;
		// Window/Keyboard events
		$(window).scroll(function(){
			self.scrollPos = self.getScroll();
			self.open( self.images, self.titles, self.descriptions ) ;
		});
		
		$(window).resize(function(){
			self.pp_overlay.css({ 'width': $(document).width(), 'height':$(document).height() }) ;
			self.open( self.images, self.titles, self.descriptions ) ;
		});
		
		$(document).keydown(function(e){
			if(self.pp_pic_holder.is(':visible'))
			switch(e.keyCode){
				case 37:
					self.changePage('previous');
					break;
				case 39:
					self.changePage('next');
					break;
				case 27:
					if(!self.settings.modal)
						self.close();
					break;
			};
	    });
		
		this.pp_overlay.bind('click',function(){
				if(!self.settings.modal)
					self.close();
				});

		this.pp_pic_holder.find('a.pp_close').bind('click',function(){ 
			self.close(); 
			return false; 
		});
		
		this.pp_pic_holder.find(' a.pp_expand').bind('click',function(){
			$this = $(this); // Fix scoping
			
			// Expand the image
			if($this.hasClass('pp_expand')){
				$this.removeClass('pp_expand').addClass('pp_contract');
				self.doresize = false;
			}else{
				$this.removeClass('pp_contract').addClass('pp_expand');
				self.doresize = true;
			};
		
			self.hideContent(function(){ self.open(self.images,self.titles,self.descriptions) });
			
			self.pp_pic_holder.find('.pp_fade').fadeOut(self.settings.animationSpeed);
	
			return false;
		});
	
		this.pp_pic_holder.find('.pp_previous, .pp_arrow_previous').bind('click',function(){
			self.changePage('previous');
			return false;
		});
	
		this.pp_pic_holder.find('.pp_next, .pp_arrow_next').bind('click',function(){
			self.changePage('next');
			return false;
		});
	}

	$.prettyPhoto.prototype.unbindHandlers = function (){
		if ( this.handlersBound ) {
			this.handlersBound = false ;
			$(window).unbind( 'scroll' ) ;
			$(window).unbind( 'resize' ) ;
			$(document).unbind( 'keydown' ) ;
			this.pp_overlay.unbind('click' ) ;
			this.pp_pic_holder.find('a.pp_close').unbind('click') ;
			this.pp_pic_holder.find(' a.pp_expand').unbind('click') ;
			this.pp_pic_holder.find('.pp_previous, .pp_arrow_previous').unbind('click') ;
			this.pp_pic_holder.find('.pp_next, .pp_arrow_next').unbind('click') ;
		}
	}

	$.prettyPhoto.prototype.close = function (){
		this.pp_pic_holder.find('object,embed').css('visibility','hidden');
		
		this.pp_pic_holder.find(' div.pp_pic_holder,div.ppt,.pp_fade').fadeOut(this.settings.animationSpeed);
		
		this.pp_overlay.fadeOut(settings.animationSpeed, function(){
			this.pp_pic_holder.find(' .pp_full_res').html(''); // Kill the opened content
			
			this.pp_pic_holder.attr('style','').find('div:not(.pp_hoverContainer)').attr('style',''); // Reset the width and everything that has been set.
			this.centerOverlay(); // Center it
		
			// To fix the bug with IE select boxes
			if($.browser.msie && $.browser.version == 6){
				$('select').css('visibility','visible');
			};
			
			// Show the flash
			if(settings.hideflash) 
				this.pp_pic_holder.find('object,embed').css('visibility','visible');
			
			this.setPosition = 0;
			this.settings.callback();
		});
		this.doresize = true;
	}

	$.prettyPhoto.prototype.centerOverlay = function (){
		if(this.doresize) {
			var titleHeight = this.ppt.height();
			var contentHeight = this.pp_pic_holder.height();
			var contentwidth = this.pp_pic_holder.width();
				
			var projectedTop = $(window).height()/2 + this.scrollPos['scrollTop'] - (contentHeight+titleHeight)/2;
			this.pp_pic_holder.animate( { 
					'top': projectedTop, 
					'left': ($(window).width()/2 + this.scrollPos['scrollLeft'] - contentwidth/2) },
				this.settings.animationSpeed, 'swing' );
				
			this.ppt.animate({
					'top' : projectedTop - titleHeight,
					'left': ($(window).width()/2) + this.scrollPos['scrollLeft'] - (contentwidth/2) + 20 },
				this.settings.animationSpeed, 'swing' );
		};
	};
    
	$.prettyPhoto.prototype.getScroll = function (){
		if (self.pageYOffset) {
			return {scrollTop:self.pageYOffset,scrollLeft:self.pageXOffset};
		} else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
			return {scrollTop:document.documentElement.scrollTop,scrollLeft:document.documentElement.scrollLeft};
		} else if (document.body) {// all other Explorers
			return {scrollTop:document.body.scrollTop,scrollLeft:document.body.scrollLeft};
		};
	};

	$.prettyPhoto.prototype.getFileType = function(itemSrc){
		if (itemSrc.match(/youtube\.com\/watch/i)) {
			return 'youtube';
		}else if (itemSrc.match(/vimeo\.com/i)) {
			return 'vimeo';
		}else if(itemSrc.indexOf('.mov') != -1){ 
			return 'quicktime';
		}else if(itemSrc.indexOf('.swf') != -1){
			return 'flash';
		}else if(itemSrc.indexOf('iframe') != -1){
			return 'iframe'
		}else if(itemSrc.substr(0,1) == '#'){
			return 'inline';
		}else{
			return 'image';
		};
	};

	/**
	* Get the containers dimensions according to the item size
	* @param width {integer} Width of the item to be opened
	* @param height {integer} Height of the item to be opened
	*/
	$.prettyPhoto.prototype.getDimensions = function(width,height){
		width = parseFloat(width);
		height = parseFloat(height);
		
		// Get the details height, to do so, I need to clone it since it's invisible
		this.pp_details = this.pp_pic_holder.find('.pp_details');
		var detailsHeight = parseFloat(this.pp_details.css('marginTop')) 
				+ parseFloat(this.pp_details.css('marginBottom'))
				+ this.settings.description_height;
		if($.browser.msie && $.browser.version==7) 
			detailsHeight+=8;
		
		// Get the container size, to resize the holder to the right dimensions
		return {
			pp_contentHeight: height + detailsHeight,
			pp_contentWidth: width,
			pp_containerHeight: height + detailsHeight 
				+ this.ppt.height() 
				+ this.pp_pic_holder.find('.pp_top').height() 
				+ this.pp_pic_holder.find('.pp_bottom').height(),
			pp_containerWidth: width } ;
	}

	
	/**
	* Resize the item dimensions if it's bigger than the viewport
	* @param width {integer} Width of the item to be opened
	* @param height {integer} Height of the item to be opened
	* @return An array containin the "fitted" dimensions
	*/
	$.prettyPhoto.prototype.fitToViewport = function(width,height){
		var hasBeenResized = false;
		var dimensions = this.getDimensions(width,height);
		
		// Define them in case there's no resize needed
		var imageWidth = dimensions.pp_contentWidth;
		var imageHeight = dimensions.pp_contentHeight;
		var containerWidth = dimensions.pp_containerWidth ;
		var containerHeight = dimensions.pp_containerHeight ;

		if( (containerWidth > $(window).width() || containerHeight > $(window).height() - 100 ) 
				&& this.doresize && this.settings.allowresize && ! this.percentBased) {
			hasBeenResized = true;
			var fitting = false ;
		
			while (!fitting){
				if(containerWidth > $(window).width() ){
					containerWidth -= 100 ;
					containerHeight = (height/width) * containerWidth;
					imageWidth -= 100;
					imageHeight = (height/width) * imageWidth;
				}
				else if(containerHeight > $(window).height() - 100){
					containerHeight -= 100;
					containerWidth = (width/height) * containerHeight;
					imageHeight -= 100;
					imageWidth = (width/height) * imageHeight;
				}
				else
					fitting = true ;
			};
		
		};
		dimensions = this.getDimensions(imageWidth,imageHeight);

		this.correctSizes = {
			width:Math.floor(imageWidth),
			height:Math.floor(imageHeight),
			containerHeight:Math.floor(dimensions.pp_containerHeight),
			containerWidth:Math.floor(dimensions.pp_containerWidth) + 40,
			contentHeight:Math.floor(dimensions.pp_contentHeight),
			contentWidth:Math.floor(dimensions.pp_contentWidth),
			resized:hasBeenResized
		};
	};
	
	/**
	* Check the item position in the gallery array, hide or show the navigation links
	* @param setCount {integer} The total number of items in the set
	*/
	$.prettyPhoto.prototype.checkPosition = function(setCount){
		// If at the end, hide the next link
		this.pp_pic_holder.find('a.pp_next').css('visibility','visible');
		this.pp_pic_holder.find('a.pp_previous').css('visibility','visible');
		
		// Hide the bottom nav if it's not a set.
		if(setCount > 1) {
			this.pp_pic_holder.find('.pp_nav').show();
		}else{
			this.pp_pic_holder.find('.pp_nav').hide();
		}
	};
	
	/**
	* Hide the content...DUH!
	*/
	$.prettyPhoto.prototype.hideContent = function(callback){
		// Fade out the current picture
		this.pp_pic_holder.find('.pp_full_res object,.pp_full_res embed').css('visibility','hidden');
		var self = this;
		this.pp_pic_holder.find('.pp_fade').fadeOut(
				this.settings.animationSpeed,
				function(){
					self.pp_pic_holder.find('.pp_loaderIcon').show();
					if(callback) callback();
				});
		
		// Hide the title
		this.ppt.fadeOut(this.settings.animationSpeed);
	}
	
	/**
	* Set the proper sizes on the containers and animate the content in.
	*/
	$.prettyPhoto.prototype.showContent = function(){
		this.pp_pic_holder.find('.pp_loaderIcon').hide();

		// Calculate the opened top position of the pic holder
		var projectedTop = this.scrollPos['scrollTop'] + (($(window).height()/2) - (this.correctSizes['containerHeight']/2));
		if(projectedTop < 0) projectedTop = 0 + this.ppt.height();

		// Resize the content holder
		this.pp_pic_holder.find('.pp_content').animate({'height':this.correctSizes['contentHeight']},this.settings.animationSpeed);
		
		// Resize picture the holder
		var self = this;
		this.pp_pic_holder.animate({
			'top': projectedTop,
			'left': ($(window).width()/2) - (this.correctSizes['containerWidth']/2),
			'width': this.correctSizes['containerWidth']
			}, 
			this.settings.animationSpeed,
			function(){
				self.pp_pic_holder.find('.pp_hoverContainer,.fullResImage')
						.height(self.correctSizes['height'])
						.width(self.correctSizes['width']);
	
				// Fade the new image
				self.pp_pic_holder.find('.pp_fade').fadeIn(self.settings.animationSpeed);
	
				// Show the nav
				var image_set = ($(self.images).size() > 0) ?  true : false; // Find out if it's a set
				if(image_set && self.getFileType(self.images[self.setPosition])=="image") { 
					self.pp_pic_holder.find('.pp_hoverContainer').show(); 
				}
				else{ 
					self.pp_pic_holder.find('.pp_hoverContainer').hide(); 
				}
	
				// Show the title
				if(self.settings.showTitle && self.hasTitle){
					self.ppt.css({
						'top' : self.pp_pic_holder.offset().top - 25,
						'left' : self.pp_pic_holder.offset().left + 20,
						'display' : 'none'
					});
	
					self.ppt.fadeIn(self.settings.animationSpeed);
				};
			
				// Fade the resizing link if the image is resized
				if(self.correctSizes['resized']) 
					self.pp_pic_holder.find('a.pp_expand,a.pp_contract').fadeIn(self.settings.animationSpeed);
				else
					self.pp_pic_holder.find('a.pp_expand,a.pp_contract').fadeOut(self.settings.animationSpeed);
				
				// Callback!
				self.settings.changepicturecallback();
			});
	};
	
	/**
	* Closes the prettyPhoto modal box.
	*/
	$.prettyPhoto.prototype.close = function(){
		this.unbindHandlers() ;
		this.pp_pic_holder.find('object,embed').css('visibility','hidden');
		this.pp_pic_holder.find('div.pp_pic_holder,div.ppt,.pp_fade').fadeOut(this.settings.animationSpeed);
		
		var self = this ;
		this.pp_overlay.fadeOut(this.settings.animationSpeed, 
				function(){
					self.pp_pic_holder.find( '.pp_full_res').html(''); // Kill the opened content
					self.pp_pic_holder.attr('style','').find('div:not(.pp_hoverContainer)').attr('style',''); // Reset the width and everything that has been set.
					self.centerOverlay(); // Center it
		
					// 	To fix the bug with IE select boxes
					if($.browser.msie && $.browser.version == 6){
						$('select').css('visibility','visible');
					};
			
					// Show the flash
					if(self.settings.hideflash) 
						$('object,embed').css('visibility','visible');
			
					self.setPosition = 0;
					self.settings.callback();
		});
		this.doresize = true;
	};

	/**
	* Change page in the prettyPhoto modal box
	* @param direction {String} Direction of the paging, previous or next.
	*/
	$.prettyPhoto.prototype.changePage = function(direction){
		if(direction == 'previous') {
			this.setPosition--;
			if (this.setPosition < 0){
				this.setPosition = 0;
				return;
			};
		}else{
			if(this.pp_pic_holder.find('.pp_arrow_next').is('.disabled_left')) return;
			this.setPosition++;
		};
		
		if ( this.setPosition < this.images.length -1 )
			this.pp_pic_holder.find('.pp_arrow_next').removeClass('disabled_left') ;
		else
			this.pp_pic_holder.find('.pp_arrow_next').addClass('disabled_left') ;

		if ( this.setPosition == 0 )
			this.pp_pic_holder.find('.pp_arrow_previous').addClass('disabled_right') ;
		else
			this.pp_pic_holder.find('.pp_arrow_previous').removeClass('disabled_right') ;

		// Allow the resizing of the images
		this.doresize = true;
		var self = this ;
		this.hideContent(function(){self.open(self.images,self.titles,self.descriptions); });
		this.pp_pic_holder.find('a.pp_expand,a.pp_contract').fadeOut(this.settings.animationSpeed);
		this.pp_pic_holder.find('a.pp_contract').removeClass('pp_contract').addClass('pp_expand');
	};

	/**
	* Opens the prettyPhoto modal box.
	* @param image {String,Array} Full path to the image to be open, can also be an array containing full images paths.
	* @param title {String,Array} The title to be displayed with the picture, can also be an array containing all the titles.
	* @param description {String,Array} The description to be displayed with the picture, can also be an array containing all the descriptions.
	*/
	$.prettyPhoto.prototype.open = function(gallery_images,gallery_titles,gallery_descriptions) {
		this.scrollPos = this.getScroll() ;
		// To fix the bug with IE select boxes
		if($.browser.msie && $.browser.version == 6){
			$('select').css('visibility','hidden');
		};
		
		if(this.settings.hideflash) 
			$('object,embed').css('visibility','hidden'); // Hide the flash
		
		// Convert everything to an array in the case it's a single item
		this.images = $.makeArray(gallery_images);
		this.titles = $.makeArray(gallery_titles);
		this.descriptions = $.makeArray(gallery_descriptions);

		var image_set = ($(this.images).size() > 0) ?  true : false; // Find out if it's a set

		// Hide the next/previous links if on first or last images.
		this.checkPosition($(this.images).size());
	
		this.pp_pic_holder.find('.pp_loaderIcon').show(); // Do I need to explain?
	
		// Fade the content in
		this.pp_overlay.show().fadeTo(this.settings.animationSpeed, this.settings.opacity);

		// Display the current position
		this.pp_pic_holder.find('.currentTextHolder').text((this.setPosition+1) + this.settings. counter_separator_label + $(this.images).size());

		// Set the description
		if(this.descriptions[this.setPosition]){
			this.pp_pic_holder.find('.pp_description').show().html(unescape(this.descriptions[this.setPosition]));
		}else{
			this.pp_pic_holder.find('.pp_description').hide().text('');
		};

		// Set the title
		if(this.titles[this.setPosition] && this.settings.showTitle){
			this.hasTitle = true;
			this.ppt.html(unescape(this.titles[this.setPosition]));
		}else{
			this.hasTitle = false;
		};
		
		// Get the dimensions
		var movie_width = ( parseFloat(this.grab_param('width',this.images[this.setPosition])) ) ? this.grab_param('width', this.images[this.setPosition]) : this.settings.default_width.toString();
		var movie_height = ( parseFloat(this.grab_param('height',this.images[this.setPosition])) ) ? this.grab_param('height',this.images[this.setPosition]) : this.settings.default_height.toString();
		
		// If the size is % based, calculate according to window dimensions
		if(movie_width.indexOf('%') != -1 || movie_height.indexOf('%') != -1){
			movie_height = parseFloat(($(window).height() * parseFloat(movie_height) / 100) - 100);
			movie_width = parseFloat(($(window).width() * parseFloat(movie_width) / 100) - 100);
			this.percentBased = true;
		}
		
		// Fade the holder
		this.bindHandlers() ;
		var self = this ;
		this.pp_pic_holder.fadeIn( function() {
				var toInject = null ;
				var curImage = self.images[self.setPosition] ;
				// Inject the proper content
				switch(self.getFileType( curImage )){
					case 'image':
						// preload the current image

						var imgPreloader = new Image();
						imgPreloader.onload = function(){
							// Fit item to viewport
							self.fitToViewport(imgPreloader.width, imgPreloader.height);
							self.showContent();
						};
						imgPreloader.onerror = function(){
							alert('Image cannot be loaded. Make sure the path is correct and image exist.');
							self.close();
						};
						imgPreloader.src = curImage;
					
						self.pp_pic_holder.find('.pp_full_res')[0].innerHTML = self.settings.image_markup;
						self.pp_pic_holder.find('.fullResImage').attr('src', curImage );

						// Preload the neighbour images
						var nextImage = new Image();
						if(image_set && self.setPosition > $(self.images).size()) 
							nextImage.src = self.images[self.setPosition + 1];
						var prevImage = new Image();
						if(image_set && self.images[self.setPosition - 1]) 
							prevImage.src = self.images[setPosition - 1];

						return ;
					break;
				
					case 'youtube':
						self.fitToViewport(movie_width,movie_height); // Fit item to viewport

						var movie = 'http://www.youtube.com/v/'+grab_param('v',images[setPosition]);
						if(self.settings.autoplay) 
							movie += "&autoplay=1";
					
						toInject = self.settings.flash_markup.replace(/{width}/g,self.correctSizes['width']).replace(/{height}/g,self.correctSizes['height']).replace(/{wmode}/g,settings.wmode).replace(/{path}/g,movie);
					break;
				
					case 'vimeo':
						self.fitToViewport(movie_width,movie_height); // Fit item to viewport
					
						movie = 'http://vimeo.com/moogaloop.swf?clip_id='+ curImage.replace('http://vimeo.com/','');
						if(self.settings.autoplay) 
							movie += "&autoplay=1";
				
						toInject = self.settings.flash_markup.replace(/{width}/g,self.correctSizes['width']).replace(/{height}/g,self.correctSizes['height']).replace(/{wmode}/g,settings.wmode).replace(/{path}/g,movie);
					break;
				
					case 'quicktime':
						self.fitToViewport(movie_width,movie_height); // Fit item to viewport
						self.correctSizes['height']+=15; 
						self.correctSizes['contentHeight']+=15; 
						self.correctSizes['containerHeight']+=15; // Add space for the control bar
				
						toInject = self.settings.quicktime_markup.replace(/{width}/g,self.correctSizes['width']).replace(/{height}/g,self.correctSizes['height']).replace(/{wmode}/g,self.settings.wmode).replace(/{path}/g,self.images[setPosition]).replace(/{autoplay}/g,self.settings.autoplay);
					break;
				
					case 'flash':
						self.fitToViewport(movie_width,movie_height); // Fit item to viewport
					
						var flash_vars = curImage.substring(curImage.indexOf('flashvars') + 10,curImage.length);
						var filename = curImage.substring(0,curImage.indexOf('?'));
					
						toInject =  self.settings.flash_markup.replace(/{width}/g,self.correctSizes['width']).replace(/{height}/g,self.correctSizes['height']).replace(/{wmode}/g,self.settings.wmode).replace(/{path}/g,filename+'?'+flash_vars);
					break;
				
					case 'iframe':
						self.fitToViewport(movie_width,movie_height); // Fit item to viewport
				
						var frame_url = curImage.substr(0,curImage.indexOf('iframe')-1);
				
						toInject = self.settings.iframe_markup.replace(/{width}/g,self.correctSizes['width']).replace(/{height}/g,self.correctSizes['height']).replace(/{path}/g,frame_url);
					break;
				
					case 'inline':
						// to get the item height clone it, apply default width, wrap it in the prettyPhoto containers , then delete
						myClone = $(curImage).clone().css({'width':self.settings.default_width}).wrapInner('<div id="pp_full_res"><div class="pp_inline clearfix"></div></div>').appendTo($('body'));
						self.fitToViewport($(myClone).width(),$(myClone).height());
						$(myClone).remove();
						toInject = self.settings.inline_markup.replace(/{content}/g,$(curImage).html());
					break;
				};

				self.pp_pic_holder.find('.pp_full_res')[0].innerHTML = toInject;
				self.showContent();
			});
	};

	$.prettyPhoto.prototype.grab_param = function(name,url){
		  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		  var regexS = "[\\?&]"+name+"=([^&#]*)";
		  var regex = new RegExp( regexS );
		  var results = regex.exec( url );
		  if( results == null )
		    return "";
		  else
		    return results[1];
		}

	function inspect( title, object ) {
		var str = '' ;
		for ( attr in object ) {
			str += attr + ': ' + object[ attr ] + '\n' ;
		}
		alert( 'Title - ' + title + '\n' + str ) ;
	}
	
})(jQuery);


