/* ------------------------------------------------------------------------
class: prettyphoto
use: lightbox clone for jquery
author: stephane caron (http://www.no-margin-for-errors.com)
version: 3.1.3
------------------------------------------------------------------------- */
(function($) {
$.prettyphoto = {version: '3.1.3'};
$.fn.prettyphoto = function(pp_settings) {
pp_settings = jquery.extend({
animation_speed: 'fast', /* fast/slow/normal */
slideshow: 5000, /* false or interval time in ms */
autoplay_slideshow: false, /* true/false */
opacity: 0.80, /* value between 0 and 1 */
show_title: true, /* true/false */
allow_resize: true, /* resize the photos bigger than viewport. true/false */
default_width: 500,
default_height: 344,
counter_separator_label: '/', /* the separator for the gallery counter 1 "of" 2 */
theme: 'pp_default', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
horizontal_padding: 20, /* the padding on each side of the picture */
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 */
deeplinking: true, /* allow prettyphoto to update the url to enable deeplinking. */
overlay_gallery: false, /* if set to true, a gallery will overlay the fullscreen image on mouse over */
keyboard_shortcuts: true, /* set to false if you open forms inside prettyphoto */
changepicturecallback: function(){}, /* called everytime an item is shown/changed */
callback: function(){}, /* called when prettyphoto is closed */
ie6_fallback: true,
markup: '
' /* html or false to disable */
}, pp_settings);
// global variables accessible only by prettyphoto
var matchedobjects = this, percentbased = false, pp_dimensions, pp_open,
// prettyphoto container specific
pp_contentheight, pp_contentwidth, pp_containerheight, pp_containerwidth,
// window size
windowheight = $(window).height(), windowwidth = $(window).width(),
// global elements
pp_slideshow;
doresize = true, scroll_pos = _get_scroll();
// window/keyboard events
$(window).unbind('resize.prettyphoto').bind('resize.prettyphoto',function(){ _center_overlay(); _resize_overlay(); });
if(pp_settings.keyboard_shortcuts) {
$(document).unbind('keydown.prettyphoto').bind('keydown.prettyphoto',function(e){
if(typeof $pp_pic_holder != 'undefined'){
if($pp_pic_holder.is(':visible')){
switch(e.keycode){
case 37:
$.prettyphoto.changepage('previous');
e.preventdefault();
break;
case 39:
$.prettyphoto.changepage('next');
e.preventdefault();
break;
case 27:
if(!settings.modal)
$.prettyphoto.close();
e.preventdefault();
break;
};
// return false;
};
};
});
};
/**
* initialize prettyphoto.
*/
$.prettyphoto.initialize = function() {
settings = pp_settings;
if(settings.theme == 'pp_default') settings.horizontal_padding = 16;
if(settings.ie6_fallback && $.browser.msie && parseint($.browser.version) == 6) settings.theme = "light_square"; // fallback to a supported theme for ie6
// find out if the picture is part of a set
therel = $(this).attr('data-pretty');
galleryregexp = /\[(?:.*)\]/;
isset = (galleryregexp.exec(therel)) ? true : false;
// put the srcs, titles, alts into an array.
pp_images = (isset) ? jquery.map(matchedobjects, function(n, i){ if($(n).attr('data-pretty').indexof(therel) != -1) return $(n).attr('href'); }) : $.makearray($(this).attr('href'));
pp_titles = (isset) ? jquery.map(matchedobjects, function(n, i){ if($(n).attr('data-pretty').indexof(therel) != -1) return ($(n).find('img').attr('alt')) ? $(n).find('img').attr('alt') : ""; }) : $.makearray($(this).find('img').attr('alt'));
pp_descriptions = (isset) ? jquery.map(matchedobjects, function(n, i){ if($(n).attr('data-pretty').indexof(therel) != -1) return ($(n).attr('title')) ? $(n).attr('title') : ""; }) : $.makearray($(this).attr('title'));
if(pp_images.length > 30) settings.overlay_gallery = false;
set_position = jquery.inarray($(this).attr('href'), pp_images); // define where in the array the clicked item is positionned
rel_index = (isset) ? set_position : $("a[rel^='"+therel+"']").index($(this));
_build_overlay(this); // build the overlay {this} being the caller
if(settings.allow_resize)
$(window).bind('scroll.prettyphoto',function(){ _center_overlay(); });
$.prettyphoto.open();
return false;
}
/**
* 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.open = function(event) {
if(typeof settings == "undefined"){ // means it's an api call, need to manually get the settings and set the variables
settings = pp_settings;
if($.browser.msie && $.browser.version == 6) settings.theme = "light_square"; // fallback to a supported theme for ie6
pp_images = $.makearray(arguments[0]);
pp_titles = (arguments[1]) ? $.makearray(arguments[1]) : $.makearray("");
pp_descriptions = (arguments[2]) ? $.makearray(arguments[2]) : $.makearray("");
isset = (pp_images.length > 1) ? true : false;
set_position = 0;
_build_overlay(event.target); // build the overlay {this} being the caller
}
if($.browser.msie && $.browser.version == 6) $('select').css('visibility','hidden'); // to fix the bug with ie select boxes
if(settings.hideflash) $('object,embed,iframe[src*=youtube],iframe[src*=vimeo]').css('visibility','hidden'); // hide the flash
_checkposition($(pp_images).size()); // hide the next/previous links if on first or last images.
$('.pp_loadericon').show();
if(settings.deeplinking)
sethashtag();
// rebuild facebook like button with updated href
if(settings.social_tools){
facebook_like_link = settings.social_tools.replace('{location_href}', encodeuricomponent(location.href));
$pp_pic_holder.find('.pp_social').html(facebook_like_link);
}
// fade the content in
if($ppt.is(':hidden')) $ppt.css('opacity',0).show();
$pp_overlay.show().fadeto(settings.animation_speed,settings.opacity);
// display the current position
$pp_pic_holder.find('.currenttextholder').text((set_position+1) + settings.counter_separator_label + $(pp_images).size());
// set the description
if(pp_descriptions[set_position] != ""){
$pp_pic_holder.find('.pp_description').show().html(unescape(pp_descriptions[set_position]));
}else{
$pp_pic_holder.find('.pp_description').hide();
}
// get the dimensions
movie_width = ( parsefloat(getparam('width',pp_images[set_position])) ) ? getparam('width',pp_images[set_position]) : settings.default_width.tostring();
movie_height = ( parsefloat(getparam('height',pp_images[set_position])) ) ? getparam('height',pp_images[set_position]) : settings.default_height.tostring();
// if the size is % based, calculate according to window dimensions
percentbased=false;
if(movie_height.indexof('%') != -1) { movie_height = parsefloat(($(window).height() * parsefloat(movie_height) / 100) - 150); percentbased = true; }
if(movie_width.indexof('%') != -1) { movie_width = parsefloat(($(window).width() * parsefloat(movie_width) / 100) - 150); percentbased = true; }
// fade the holder
$pp_pic_holder.fadein(function(){
// set the title
(settings.show_title && pp_titles[set_position] != "" && typeof pp_titles[set_position] != "undefined") ? $ppt.html(unescape(pp_titles[set_position])) : $ppt.html(' ');
imgpreloader = "";
skipinjection = false;
// inject the proper content
switch(_getfiletype(pp_images[set_position])){
case 'image':
imgpreloader = new image();
// preload the neighbour images
nextimage = new image();
if(isset && set_position < $(pp_images).size() -1) nextimage.src = pp_images[set_position + 1];
previmage = new image();
if(isset && pp_images[set_position - 1]) previmage.src = pp_images[set_position - 1];
$pp_pic_holder.find('#pp_full_res')[0].innerhtml = settings.image_markup.replace(/{path}/g,pp_images[set_position]);
imgpreloader.onload = function(){
// fit item to viewport
pp_dimensions = _fittoviewport(imgpreloader.width,imgpreloader.height);
_showcontent();
};
imgpreloader.onerror = function(){
alert('image cannot be loaded. make sure the path is correct and image exist.');
$.prettyphoto.close();
};
imgpreloader.src = pp_images[set_position];
break;
case 'youtube':
pp_dimensions = _fittoviewport(movie_width,movie_height); // fit item to viewport
// regular youtube link
movie_id = getparam('v',pp_images[set_position]);
// youtu.be link
if(movie_id == ""){
movie_id = pp_images[set_position].split('youtu.be/');
movie_id = movie_id[1];
if(movie_id.indexof('?') > 0)
movie_id = movie_id.substr(0,movie_id.indexof('?')); // strip anything after the ?
if(movie_id.indexof('&') > 0)
movie_id = movie_id.substr(0,movie_id.indexof('&')); // strip anything after the &
}
movie = 'http://www.youtube.com/embed/'+movie_id;
(getparam('rel',pp_images[set_position])) ? movie+="?rel="+getparam('rel',pp_images[set_position]) : movie+="?rel=1";
if(settings.autoplay) movie += "&autoplay=1";
toinject = settings.iframe_markup.replace(/{width}/g,pp_dimensions['width']).replace(/{height}/g,pp_dimensions['height']).replace(/{wmode}/g,settings.wmode).replace(/{path}/g,movie);
break;
case 'vimeo':
pp_dimensions = _fittoviewport(movie_width,movie_height); // fit item to viewport
movie_id = pp_images[set_position];
var regexp = /http:\/\/(www\.)?vimeo.com\/(\d+)/;
var match = movie_id.match(regexp);
movie = 'http://player.vimeo.com/video/'+ match[2] +'?title=0&byline=0&portrait=0';
if(settings.autoplay) movie += "&autoplay=1;";
vimeo_width = pp_dimensions['width'] + '/embed/?moog_width='+ pp_dimensions['width'];
toinject = settings.iframe_markup.replace(/{width}/g,vimeo_width).replace(/{height}/g,pp_dimensions['height']).replace(/{path}/g,movie);
break;
case 'quicktime':
pp_dimensions = _fittoviewport(movie_width,movie_height); // fit item to viewport
pp_dimensions['height']+=15; pp_dimensions['contentheight']+=15; pp_dimensions['containerheight']+=15; // add space for the control bar
toinject = settings.quicktime_markup.replace(/{width}/g,pp_dimensions['width']).replace(/{height}/g,pp_dimensions['height']).replace(/{wmode}/g,settings.wmode).replace(/{path}/g,pp_images[set_position]).replace(/{autoplay}/g,settings.autoplay);
break;
case 'flash':
pp_dimensions = _fittoviewport(movie_width,movie_height); // fit item to viewport
flash_vars = pp_images[set_position];
flash_vars = flash_vars.substring(pp_images[set_position].indexof('flashvars') + 10,pp_images[set_position].length);
filename = pp_images[set_position];
filename = filename.substring(0,filename.indexof('?'));
toinject = settings.flash_markup.replace(/{width}/g,pp_dimensions['width']).replace(/{height}/g,pp_dimensions['height']).replace(/{wmode}/g,settings.wmode).replace(/{path}/g,filename+'?'+flash_vars);
break;
case 'iframe':
pp_dimensions = _fittoviewport(movie_width,movie_height); // fit item to viewport
frame_url = pp_images[set_position];
frame_url = frame_url.substr(0,frame_url.indexof('iframe')-1);
toinject = settings.iframe_markup.replace(/{width}/g,pp_dimensions['width']).replace(/{height}/g,pp_dimensions['height']).replace(/{path}/g,frame_url);
break;
case 'ajax':
doresize = false; // make sure the dimensions are not resized.
pp_dimensions = _fittoviewport(movie_width,movie_height);
doresize = true; // reset the dimensions
skipinjection = true;
$.get(pp_images[set_position],function(responsehtml){
toinject = settings.inline_markup.replace(/{content}/g,responsehtml);
$pp_pic_holder.find('#pp_full_res')[0].innerhtml = toinject;
_showcontent();
});
break;
case 'custom':
pp_dimensions = _fittoviewport(movie_width,movie_height); // fit item to viewport
toinject = settings.custom_markup;
break;
case 'inline':
// to get the item height clone it, apply default width, wrap it in the prettyphoto containers , then delete
myclone = $(pp_images[set_position]).clone().append(' ').css({'width':settings.default_width}).wrapinner('
').appendto($('body')).show();
doresize = false; // make sure the dimensions are not resized.
pp_dimensions = _fittoviewport($(myclone).width(),$(myclone).height());
doresize = true; // reset the dimensions
$(myclone).remove();
toinject = settings.inline_markup.replace(/{content}/g,$(pp_images[set_position]).html());
break;
};
if(!imgpreloader && !skipinjection){
$pp_pic_holder.find('#pp_full_res')[0].innerhtml = toinject;
// show content
_showcontent();
};
});
return false;
};
/**
* change page in the prettyphoto modal box
* @param direction {string} direction of the paging, previous or next.
*/
$.prettyphoto.changepage = function(direction){
currentgallerypage = 0;
if(direction == 'previous') {
set_position--;
if (set_position < 0) set_position = $(pp_images).size()-1;
}else if(direction == 'next'){
set_position++;
if(set_position > $(pp_images).size()-1) set_position = 0;
}else{
set_position=direction;
};
rel_index = set_position;
if(!doresize) doresize = true; // allow the resizing of the images
$('.pp_contract').removeclass('pp_contract').addclass('pp_expand');
_hidecontent(function(){ $.prettyphoto.open(); });
};
/**
* change gallery page in the prettyphoto modal box
* @param direction {string} direction of the paging, previous or next.
*/
$.prettyphoto.changegallerypage = function(direction){
if(direction=='next'){
currentgallerypage ++;
if(currentgallerypage > totalpage) currentgallerypage = 0;
}else if(direction=='previous'){
currentgallerypage --;
if(currentgallerypage < 0) currentgallerypage = totalpage;
}else{
currentgallerypage = direction;
};
slide_speed = (direction == 'next' || direction == 'previous') ? settings.animation_speed : 0;
slide_to = currentgallerypage * (itemsperpage * itemwidth);
$pp_gallery.find('ul').animate({left:-slide_to},slide_speed);
};
/**
* start the slideshow...
*/
$.prettyphoto.startslideshow = function(){
if(typeof pp_slideshow == 'undefined'){
$pp_pic_holder.find('.pp_play').unbind('click').removeclass('pp_play').addclass('pp_pause').click(function(){
$.prettyphoto.stopslideshow();
return false;
});
pp_slideshow = setinterval($.prettyphoto.startslideshow,settings.slideshow);
}else{
$.prettyphoto.changepage('next');
};
}
/**
* stop the slideshow...
*/
$.prettyphoto.stopslideshow = function(){
$pp_pic_holder.find('.pp_pause').unbind('click').removeclass('pp_pause').addclass('pp_play').click(function(){
$.prettyphoto.startslideshow();
return false;
});
clearinterval(pp_slideshow);
pp_slideshow=undefined;
}
/**
* closes prettyphoto.
*/
$.prettyphoto.close = function(){
if($pp_overlay.is(":animated")) return;
$.prettyphoto.stopslideshow();
$pp_pic_holder.stop().find('object,embed').css('visibility','hidden');
$('div.pp_pic_holder,div.ppt,.pp_fade').fadeout(settings.animation_speed,function(){ $(this).remove(); });
$pp_overlay.fadeout(settings.animation_speed, function(){
if($.browser.msie && $.browser.version == 6) $('select').css('visibility','visible'); // to fix the bug with ie select boxes
if(settings.hideflash) $('object,embed,iframe[src*=youtube],iframe[src*=vimeo]').css('visibility','visible'); // show the flash
$(this).remove(); // no more need for the prettyphoto markup
$(window).unbind('scroll.prettyphoto');
clearhashtag();
settings.callback();
doresize = true;
pp_open = false;
delete settings;
});
};
/**
* set the proper sizes on the containers and animate the content in.
*/
function _showcontent(){
$('.pp_loadericon').hide();
// calculate the opened top position of the pic holder
projectedtop = scroll_pos['scrolltop'] + ((windowheight/2) - (pp_dimensions['containerheight']/2));
if(projectedtop < 0) projectedtop = 0;
$ppt.fadeto(settings.animation_speed,1);
// resize the content holder
$pp_pic_holder.find('.pp_content')
.animate({
height:pp_dimensions['contentheight'],
width:pp_dimensions['contentwidth']
},settings.animation_speed);
// resize picture the holder
$pp_pic_holder.animate({
'top': projectedtop,
'left': (windowwidth/2) - (pp_dimensions['containerwidth']/2),
width:pp_dimensions['containerwidth']
},settings.animation_speed,function(){
$pp_pic_holder.find('.pp_hovercontainer,#fullresimage').height(pp_dimensions['height']).width(pp_dimensions['width']);
$pp_pic_holder.find('.pp_fade').fadein(settings.animation_speed); // fade the new content
// show the nav
if(isset && _getfiletype(pp_images[set_position])=="image") { $pp_pic_holder.find('.pp_hovercontainer').show(); }else{ $pp_pic_holder.find('.pp_hovercontainer').hide(); }
if(pp_dimensions['resized']){ // fade the resizing link if the image is resized
$('a.pp_expand,a.pp_contract').show();
}else{
$('a.pp_expand').hide();
}
if(settings.autoplay_slideshow && !pp_slideshow && !pp_open) $.prettyphoto.startslideshow();
settings.changepicturecallback(); // callback!
pp_open = true;
});
_insert_gallery();
};
/**
* hide the content...duh!
*/
function _hidecontent(callback){
// fade out the current picture
$pp_pic_holder.find('#pp_full_res object,#pp_full_res embed').css('visibility','hidden');
$pp_pic_holder.find('.pp_fade').fadeout(settings.animation_speed,function(){
$('.pp_loadericon').show();
callback();
});
};
/**
* 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
*/
function _checkposition(setcount){
(setcount > 1) ? $('.pp_nav').show() : $('.pp_nav').hide(); // hide the bottom nav if it's not a set.
};
/**
* 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
*/
function _fittoviewport(width,height){
resized = false;
_getdimensions(width,height);
// define them in case there's no resize needed
imagewidth = width, imageheight = height;
if( ((pp_containerwidth > windowwidth) || (pp_containerheight > windowheight)) && doresize && settings.allow_resize && !percentbased) {
resized = true, fitting = false;
while (!fitting){
if((pp_containerwidth > windowwidth)){
imagewidth = (windowwidth - 200);
imageheight = (height/width) * imagewidth;
}else if((pp_containerheight > windowheight)){
imageheight = (windowheight - 200);
imagewidth = (width/height) * imageheight;
}else{
fitting = true;
};
pp_containerheight = imageheight, pp_containerwidth = imagewidth;
};
_getdimensions(imagewidth,imageheight);
if((pp_containerwidth > windowwidth) || (pp_containerheight > windowheight)){
_fittoviewport(pp_containerwidth,pp_containerheight)
};
};
return {
width:math.floor(imagewidth),
height:math.floor(imageheight),
containerheight:math.floor(pp_containerheight),
containerwidth:math.floor(pp_containerwidth) + (settings.horizontal_padding * 2),
contentheight:math.floor(pp_contentheight),
contentwidth:math.floor(pp_contentwidth),
resized:resized
};
};
/**
* 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
*/
function _getdimensions(width,height){
width = parsefloat(width);
height = parsefloat(height);
// get the details height, to do so, i need to clone it since it's invisible
$pp_details = $pp_pic_holder.find('.pp_details');
$pp_details.width(width);
detailsheight = parsefloat($pp_details.css('margintop')) + parsefloat($pp_details.css('marginbottom'));
$pp_details = $pp_details.clone().addclass(settings.theme).width(width).appendto($('body')).css({
'position':'absolute',
'top':-10000
});
detailsheight += $pp_details.height();
detailsheight = (detailsheight <= 34) ? 36 : detailsheight; // min-height for the details
if($.browser.msie && $.browser.version==7) detailsheight+=8;
$pp_details.remove();
// get the titles height, to do so, i need to clone it since it's invisible
$pp_title = $pp_pic_holder.find('.ppt');
$pp_title.width(width);
titleheight = parsefloat($pp_title.css('margintop')) + parsefloat($pp_title.css('marginbottom'));
$pp_title = $pp_title.clone().appendto($('body')).css({
'position':'absolute',
'top':-10000
});
titleheight += $pp_title.height();
$pp_title.remove();
// get the container size, to resize the holder to the right dimensions
pp_contentheight = height + detailsheight;
pp_contentwidth = width;
pp_containerheight = pp_contentheight + titleheight + $pp_pic_holder.find('.pp_top').height() + $pp_pic_holder.find('.pp_bottom').height();
pp_containerwidth = width;
}
function _getfiletype(itemsrc){
if (itemsrc.match(/youtube\.com\/watch/i) || itemsrc.match(/youtu\.be/i)) {
return 'youtube';
}else if (itemsrc.match(/vimeo\.com/i)) {
return 'vimeo';
}else if(itemsrc.match(/\b.mov\b/i)){
return 'quicktime';
}else if(itemsrc.match(/\b.swf\b/i)){
return 'flash';
}else if(itemsrc.match(/\biframe=true\b/i)){
return 'iframe';
}else if(itemsrc.match(/\bajax=true\b/i)){
return 'ajax';
}else if(itemsrc.match(/\bcustom=true\b/i)){
return 'custom';
}else if(itemsrc.substr(0,1) == '#'){
return 'inline';
}else{
return 'image';
};
};
function _center_overlay(){
if(doresize && typeof $pp_pic_holder != 'undefined') {
scroll_pos = _get_scroll();
contentheight = $pp_pic_holder.height(), contentwidth = $pp_pic_holder.width();
projectedtop = (windowheight/2) + scroll_pos['scrolltop'] - (contentheight/2);
if(projectedtop < 0) projectedtop = 0;
if(contentheight > windowheight)
return;
$pp_pic_holder.css({
'top': projectedtop,
'left': (windowwidth/2) + scroll_pos['scrollleft'] - (contentwidth/2)
});
};
};
function _get_scroll(){
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};
};
};
function _resize_overlay() {
windowheight = $(window).height(), windowwidth = $(window).width();
if(typeof $pp_overlay != "undefined") $pp_overlay.height($(document).height()).width(windowwidth);
};
function _insert_gallery(){
if(isset && settings.overlay_gallery && _getfiletype(pp_images[set_position])=="image" && (settings.ie6_fallback && !($.browser.msie && parseint($.browser.version) == 6))) {
itemwidth = 52+5; // 52 beign the thumb width, 5 being the right margin.
navwidth = (settings.theme == "facebook" || settings.theme == "pp_default") ? 50 : 30; // define the arrow width depending on the theme
itemsperpage = math.floor((pp_dimensions['containerwidth'] - 100 - navwidth) / itemwidth);
itemsperpage = (itemsperpage < pp_images.length) ? itemsperpage : pp_images.length;
totalpage = math.ceil(pp_images.length / itemsperpage) - 1;
// hide the nav in the case there's no need for links
if(totalpage == 0){
navwidth = 0; // no nav means no width!
$pp_gallery.find('.pp_arrow_next,.pp_arrow_previous').hide();
}else{
$pp_gallery.find('.pp_arrow_next,.pp_arrow_previous').show();
};
gallerywidth = itemsperpage * itemwidth;
fullgallerywidth = pp_images.length * itemwidth;
// set the proper width to the gallery items
$pp_gallery
.css('margin-left',-((gallerywidth/2) + (navwidth/2)))
.find('div:first').width(gallerywidth+5)
.find('ul').width(fullgallerywidth)
.find('li.selected').removeclass('selected');
gotopage = (math.floor(set_position/itemsperpage) < totalpage) ? math.floor(set_position/itemsperpage) : totalpage;
$.prettyphoto.changegallerypage(gotopage);
$pp_gallery_li.filter(':eq('+set_position+')').addclass('selected');
}else{
$pp_pic_holder.find('.pp_content').unbind('mouseenter mouseleave');
// $pp_gallery.hide();
}
}
function _build_overlay(caller){
// inject social tool markup into general markup
if(settings.social_tools)
facebook_like_link = settings.social_tools.replace('{location_href}', encodeuricomponent(location.href));
settings.markup=settings.markup.replace('{pp_social}',(settings.social_tools)?facebook_like_link:'');
$('body').append(settings.markup); // inject the markup
$pp_pic_holder = $('.pp_pic_holder') , $ppt = $('.ppt'), $pp_overlay = $('div.pp_overlay'); // set my global selectors
// inject the inline gallery!
if(isset && settings.overlay_gallery) {
currentgallerypage = 0;
toinject = "";
for (var i=0; i < pp_images.length; i++) {
if(!pp_images[i].match(/\b(jpg|jpeg|png|gif)\b/gi)){
classname = 'default';
img_src = '';
}else{
classname = '';
img_src = pp_images[i];
}
toinject += "
";
};
toinject = settings.gallery_markup.replace(/{gallery}/g,toinject);
$pp_pic_holder.find('#pp_full_res').after(toinject);
$pp_gallery = $('.pp_pic_holder .pp_gallery'), $pp_gallery_li = $pp_gallery.find('li'); // set the gallery selectors
$pp_gallery.find('.pp_arrow_next').click(function(){
$.prettyphoto.changegallerypage('next');
$.prettyphoto.stopslideshow();
return false;
});
$pp_gallery.find('.pp_arrow_previous').click(function(){
$.prettyphoto.changegallerypage('previous');
$.prettyphoto.stopslideshow();
return false;
});
$pp_pic_holder.find('.pp_content').hover(
function(){
$pp_pic_holder.find('.pp_gallery:not(.disabled)').fadein();
},
function(){
$pp_pic_holder.find('.pp_gallery:not(.disabled)').fadeout();
});
itemwidth = 52+5; // 52 beign the thumb width, 5 being the right margin.
$pp_gallery_li.each(function(i){
$(this)
.find('a')
.click(function(){
$.prettyphoto.changepage(i);
$.prettyphoto.stopslideshow();
return false;
});
});
};
// inject the play/pause if it's a slideshow
if(settings.slideshow){
$pp_pic_holder.find('.pp_nav').prepend('play')
$pp_pic_holder.find('.pp_nav .pp_play').click(function(){
$.prettyphoto.startslideshow();
return false;
});
}
$pp_pic_holder.attr('class','pp_pic_holder ' + settings.theme); // set the proper theme
$pp_overlay
.css({
'opacity':0,
'height':$(document).height(),
'width':$(window).width()
})
.bind('click',function(){
if(!settings.modal) $.prettyphoto.close();
});
$('a.pp_close').bind('click',function(){ $.prettyphoto.close(); return false; });
$('a.pp_expand').bind('click',function(e){
// expand the image
if($(this).hasclass('pp_expand')){
$(this).removeclass('pp_expand').addclass('pp_contract');
doresize = false;
}else{
$(this).removeclass('pp_contract').addclass('pp_expand');
doresize = true;
};
_hidecontent(function(){ $.prettyphoto.open(); });
return false;
});
$pp_pic_holder.find('.pp_previous, .pp_nav .pp_arrow_previous').bind('click',function(){
$.prettyphoto.changepage('previous');
$.prettyphoto.stopslideshow();
return false;
});
$pp_pic_holder.find('.pp_next, .pp_nav .pp_arrow_next').bind('click',function(){
$.prettyphoto.changepage('next');
$.prettyphoto.stopslideshow();
return false;
});
_center_overlay(); // center it
};
if(!pp_alreadyinitialized && gethashtag()){
pp_alreadyinitialized = true;
// grab the rel index to trigger the click on the correct element
hashindex = gethashtag();
hashrel = hashindex;
hashindex = hashindex.substring(hashindex.indexof('/')+1,hashindex.length-1);
hashrel = hashrel.substring(0,hashrel.indexof('/'));
// little timeout to make sure all the prettyphoto initialize scripts has been run.
// useful in the event the page contain several init scripts.
settimeout(function(){ $("a[rel^='"+hashrel+"']:eq("+hashindex+")").trigger('click'); },50);
}
return this.unbind('click.prettyphoto').bind('click.prettyphoto',$.prettyphoto.initialize); // return the jquery object for chaining. the unbind method is used to avoid click conflict when the plugin is called more than once
};
function gethashtag(){
url = location.href;
hashtag = (url.indexof('#!') != -1) ? decodeuri(url.substring(url.indexof('#!')+2,url.length)) : false;
return hashtag;
};
function sethashtag(){
if(typeof therel == 'undefined') return; // therel is set on normal calls, it's impossible to deeplink using the api
location.hash = '!' + therel + '/'+rel_index+'/';
};
function clearhashtag(){
// clear the hashtag only if it was set by prettyphoto
url = location.href;
hashtag = (url.indexof('#!prettyphoto')) ? true : false;
if(hashtag) location.hash = "!prettyphoto";
}
function getparam(name,url){
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexs = "[\\?&]"+name+"=([^]*)";
var regex = new regexp( regexs );
var results = regex.exec( url );
return ( results == null ) ? "" : results[1];
}
})(jquery);
var pp_alreadyinitialized = false; // used for the deep linking to make sure not to call the same function several times.