/**
* name: pirobox v.1.2.2
* date: may 2010
* autor: diego valobra (http://www.pirolab.it)
* version: 1.2.2
* licence: cc-by-sa http://creativecommons.org/licenses/by-sa/2.5/it/
**/
(function($) {
$.fn.pirobox = function(opt) {
opt = jquery.extend({
my_speed : null,
close_speed : 300,
bg_alpha : 0.5,
close_all : '.piro_close,.piro_overlay',
slideshow : null,
slidespeed : null
}, opt);
function start_pirobox() {
var corners =
'
'+
' | '+
'
'+
''+
' | '+
' | '+
' | '+
'
'+
''+
' | '+
' | '+
' | '+
'
'+
''+
' | '+
' | '+
' | '+
'
'+
''+
' | '+
'
';
var window_height = $(document).height();
var bg_overlay = $(jquery('').hide().css({'opacity':+opt.bg_alpha,'height':window_height+'px'}));
var main_cont = $(jquery(''));
var caption = $(jquery(''));
var piro_nav = $(jquery(''));
var piro_close = $(jquery(''));
var piro_play = $(jquery(''));
var piro_stop = $(jquery(''));
var piro_prev = $(jquery(''));
var piro_next = $(jquery(''));
$('body').append(bg_overlay).append(main_cont);
main_cont.append(corners);
$('.pirobox_up').append(piro_close);
$('.pirobox_down').append(piro_nav);
$('.pirobox_down').append(piro_play);
piro_play.hide();
$('.pirobox_down').append(piro_prev).append(piro_next);
piro_nav.append(caption);
var my_nav_w = piro_prev.width();
main_cont.hide();
var my_gall_classes = $("a[class^='pirobox']");
var map = new object();
for (var i=0; i').css({'background':'url('+val+')'/*,'width':'600px','height':'200px'*/}).appendto(hidden);
});
var piro_gallery = $(my_gall_classes);
$.fn.fixpng = function() {
return this.each(function () {
var image = $(this).css('backgroundimage');
if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) {
image = regexp.$1;
$(this).css({
'backgroundimage': 'none',
'filter': "progid:dximagetransform.microsoft.alphaimageloader(enabled=true, sizingmethod=" + ($(this).css('backgroundrepeat') == 'no-repeat' ? 'crop' : 'scale') + ", src='" + image + "')"
}).each(function () {
var position = $(this).css('position');
if (position != 'absolute' && position != 'relative')
$(this).css('position', 'relative');
});
}
});
};
$.browser.msie6 =($.browser.msie && /msie 6\.0/i.test(window.navigator.useragent));
if( $.browser.msie6 && !/msie 8\.0/i.test(window.navigator.useragent)) {
$('.t_l,.t_c,.t_r,.c_l,.c_r,.b_l,.b_c,.b_r,a.piro_next, a.piro_prev,a.piro_prev_out,a.piro_next_out,.c_c,.piro_close,a.play,a.stop').fixpng();
var ie_w_h = $(document).height();
bg_overlay.css('height',ie_w_h+ 'px');
}
if( $.browser.msie) {
opt.close_speed = 0;
}
$(window).resize(function(){
var new_w_bg = $(document).height();
bg_overlay.css({'visibility':'visible','height':+ new_w_bg +'px'});
});
piro_prev.add(piro_next).bind('click',function(c) {
c.preventdefault();
var image_count = parseint($(piro_gallery).filter('.item').attr('rev'));
var start = $(this).is('.piro_prev_out,.piro_prev') ? $(piro_gallery).eq(image_count - 1) : $(piro_gallery).eq(image_count + 1);
if(!start.size()) {
start = $(this).is('.piro_prev_out,.piro_prev') ? $(piro_gallery).eq($(piro_gallery).size() - 1) : $(piro_gallery).eq(0);
}
start.click();
piro_close.add(caption).add(piro_next).add(piro_prev).css('visibility','hidden');
});
$(piro_gallery).each(function(array) {
var item = $(this);
item.unbind();
item.bind('click',function(c) {
c.preventdefault();
piro_open(item.attr('href'));
var this_url = item.attr('href');
//var descr = item.children('span').html();
var descr = item.attr('title');
var number = item.attr('rel');
if( descr == ""){
caption.html(''+ this_url+'' + number + '
');
}else{
caption.html(''+ descr+'' + number + '
');
}
if(item.is('.last')){
$('.number').css('text-decoration','underline');
}else{
$('.number').css('text-decoration','none');
}
if(item.is('.first')){
piro_prev.hide();
piro_next.show();
}else{
piro_next.add(piro_prev).show();
}
if(item.is('.last')){
piro_prev.show();
piro_next.hide();
piro_play.css('width','0');
}else{
piro_play.css('width','40px');
}
if(item.is('.last') && item.is('.first') ){
piro_prev.add(piro_next).hide();
$('.number').hide();
piro_play.remove();
}
$(piro_gallery).filter('.item').removeclass('item');
item.addclass('item');
$('.c_c').removeclass('unique');
});
});
var piro_open = function(my_url) {
piro_play.add(piro_stop).hide();
piro_close.add(caption).add(piro_next).add(piro_prev).css('visibility','hidden');
if(main_cont.is(':visible')) {
$('.c_c div').children().fadeout(300, function() {
$('.c_c div').children().remove();
load_img(my_url);
});
} else {
$('.c_c div').children().remove();
main_cont.show();
bg_overlay.fadein(300,function(){
load_img(my_url);
});
}
}
var load_img = function(my_url) {
if(main_cont.is('.loading')) {return;}
main_cont.addclass('loading');
var img = new image();
img.onerror = function (){
var main_cont_h = $(main_cont).height();
main_cont.css({margintop : parseint($(document).scrolltop())-(main_cont_h/1.9)});
$('.c_c div').append('there seems to be an error: close pirobox
');
$('.close_pirobox').bind('click',function(c) {
c.preventdefault();
piro_close.add(bg_overlay).add(main_cont).add(caption).add(piro_next).add(piro_prev).hide(0,function(){ img.src = '';});
main_cont.removeclass('loading');
});
}
img.onload = function() {
var imgh = img.height;
var imgw = img.width;
var main_cont_h = $(main_cont).height();
var w_h = $(window).height();
var w_w = $(window).width();
$(img).height(imgh).width(imgw).hide();
$('.c_c div').animate({height:imgh+'px',width:imgw+'px'},opt.my_speed);
var fix = imgh/w_h*2.3;
if(w_h < imgh){h_fix = fix;}else{h_fix = 2;}
main_cont.animate({
height : (imgh+40) + 'px' ,
width : (imgw+40) + 'px' ,
marginleft : '-' +((imgw)/2+20) +'px',
margintop : parseint($(document).scrolltop())-(imgh/h_fix)},opt.my_speed, function(){
$('.piro_nav,.caption').css({width:(imgw)+'px','margin-bottom':'10px'});
$('.piro_nav').css('margin-left','-'+(imgw)/2+'px');
var caption_height = caption.height();
$('.c_c div').append(img);
piro_close.css('display','block');
piro_next.add(piro_prev).add(piro_close).css('visibility','visible');
caption.css({'visibility':'visible','display':'block','opacity':'0.8','overflow':'hidden'});
main_cont.hover(function(){
caption.stop().fadeto(200,0.8);},
function(){caption.stop().fadeto(200,0);
});
$(img).fadein(300);
main_cont.removeclass('loading');
if(opt.slideshow === true){
piro_play.add(piro_stop).show();
}else{
piro_play.add(piro_stop).hide();
}
});
}
img.src = my_url;
$('html').bind("keyup", function (c) {
if(c.keycode == 27) {
c.preventdefault();
if($(img).is(':visible') || $('.c_c>div>p>a').is('.close_pirobox')){
$(piro_gallery).removeclass('slideshow').removeclass('item');
piro_close.add(bg_overlay).add(main_cont).add(caption).add(piro_next).add(piro_prev).hide(0,function(){ img.src = '';});
main_cont.removeclass('loading');
cleartimeout(timer);
$(piro_gallery).children().removeattr('class');
$('.stop').remove();
$('.c_c').append(piro_play);
$('.sc_menu').css('display','none');
$('ul.sc_menu li a').removeclass('img_active').css('opacity','0.4');
piro_next.add(piro_prev).show().css({'top':'50%'});
$(piro_gallery).children().fadeto(100,1);
}
}
});
$('html').bind("keyup" ,function(e) {
if ($('.item').is('.first')){
}else if(e.keycode == 37){
e.preventdefault();
if($(img).is(':visible')){
cleartimeout(timer);
$(piro_gallery).children().removeattr('class');
$('.stop').remove();
$('.c_c').append(piro_play);
piro_prev.click();
}
}
});
$('html').bind("keyup" ,function(z) {
if ($('.item').is('.last')){
}else if(z.keycode == 39){
z.preventdefault();
if($(img).is(':visible')){
cleartimeout(timer);
$(piro_gallery).children().removeattr('class');
$('.stop').remove();
$('.c_c').append(piro_play);
piro_next.click();
//alert('click')
}
}
});
var win_h = $(window).height();
piro_stop.bind('click',function(x){
x.preventdefault();
cleartimeout(timer);
$(piro_gallery).removeclass('slideshow');
$('.stop').remove();
$('.pirobox_down').append(piro_play);
piro_next.add(piro_prev).css('width',my_nav_w+'px');
});
piro_play.bind('click',function(w){
w.preventdefault();
cleartimeout(timer);
if($(img).is(':visible')){
$(piro_gallery).addclass('slideshow');
$('.play').remove();
$('.pirobox_down').append(piro_stop);
}
piro_next.add(piro_prev).css({'width':'0px'});
return slideshow();
});
$(opt.close_all).bind('click',function(c) {
$(piro_gallery).removeclass('slideshow');
cleartimeout(timer);
if($(img).is(':visible')){
c.preventdefault();
piro_close.add(bg_overlay).add(main_cont).add(caption).add(piro_next).add(piro_prev).hide(0,function(){ img.src = '';});
main_cont.removeclass('loading');
$(piro_gallery).removeclass('slideshow');
piro_next.add(piro_prev).css('width',my_nav_w+'px').hide();
$('.stop').remove();
$('.pirobox_down').append(piro_play);
piro_play.hide();
}
});
if(opt.slideshow === true){
function slideshow(){
if( $(piro_gallery).filter('.item').is('.last')){
cleartimeout(timer);
$(piro_gallery).removeclass('slideshow');
$('.stop').remove();
$('.pirobox_down').append(piro_play);
piro_next.add(piro_prev).css('width',my_nav_w+'px');
} else if($(piro_gallery).is('.slideshow' ) && $(img).is(':visible')){
cleartimeout(timer);
piro_next.click();
}
}
var timer = setinterval(slideshow,opt.slidespeed*1000 );
}
}
}
start_pirobox();
}
})(jquery);