function jBoxInit(){
$('.jbox').on('click', function() {
jBox($(this));
return false;
/*}).on('mouseover', function() {
$(this).find('div.thumb').stop(true,false).animate({'height':$(this).find('img').height() + 'px'}, 500);
}).on('mouseout', function() {
$(this).find('div.thumb').stop(true,false).animate({'height':'120px'}, 500);*/
});
}
function jBox(element){
//na pewno nie ma innych
$('.jbox-overlay').remove();
//Tworzenie szablonu
var foto = element.attr('href'),
thumb = element.find('img').attr('src'),
close = '
',
box = '',
prev = '',
next = '';
if (element.siblings('.pelen-opis').html())
var description = ''+ element.siblings('.pelen-opis').html() + '
';
else var description = '';
//$('body').append('' + prev + box + next + close + '
').hide().fadeIn();;
$('body').append(
''
/*+ prev + box + next + description + close */
+ box + close
+ '
').hide().fadeIn();
//duza fotka
$('#jbox-foto').append('
');
// wyświetlanie się jBoxa
$('#jbox-foto img').load(function(){
//alert($(this).height());
var wrapper = $('#jbox-wrapper');
wrapper.css({
top: ($(window).height() - $('#jbox-wrapper img').innerHeight()) / 2 + 'px',
left: ($(window).width()/2) -(wrapper.innerWidth() / 2) + 'px'
});
$('#jbox-wrapper img').load(function(){
wrapper.css({
top: ($(window).height() - $('#jbox-wrapper img').innerHeight()) / 2 + 'px'
});
});
var prev = $('#jbox-prev');
prev.css({
top: ($(window).height()/2) -(prev.innerHeight() / 2) + 'px',
left: ($(window).width()/2) -(wrapper.innerWidth() / 2) - prev.innerWidth() - 10 + 'px'
});
var next = $('#jbox-next');
next.css({
top: ($(window).height()/2) -(prev.innerHeight() / 2) + 'px',
right: ($(window).width()/2) -(wrapper.innerWidth() / 2) - next.innerWidth() - 10 + 'px'
});
$('#jbox-wrapper, #jbox-prev ,#jbox-next').css('visibility','visible');
});
//miniaturki
var thumblist = thumb.replace('1.png', 'thumb/');
var fotolist = foto.replace('1.png', '');
for (i=1; i<=3; i++){
$('#jbox-thumbs').append('
');
}
$('#jbox-thumbs li a img').each(function(){
if ($(this).width() == 0){
$(this). parent().parent('li').css('border','none');
}
});
//pojawiający się pełen opis
$('.description').append('');
$('.close-desc').click(function(){
var descHeight = $('.description').innerHeight();
$('.description').animate({
display: 'block',
opacity: '1',
bottom: -descHeight
},500);
});
$('.description').animate({
display: 'block',
opacity: '1',
bottom: 0
},1000);
//zmiany fotek
$('#jbox-thumbs li a').on('click', function() {
changePhoto($(this));
return false;
});
//nowy slajd
$('#jbox-prev').on('click', function() {
var rozmiar = $('.jbox').size() - 1;
var index = $('.jbox').index(element);
if (index == 0){
var poprzedni = $('.jbox').eq(rozmiar);
}
else{
var poprzedni = $('.jbox').eq(index - 1);
}
jBox(poprzedni);
/*$('#jbox-wrapper img').load(function(){
$('#jbox-wrapper').css({
top: ($(window).height() - $('#jbox-wrapper img').innerHeight()) / 2 + 'px'
});
}); */
});
$('#jbox-next').on('click', function() {
var rozmiar = $('.jbox').size() - 1;
var index = $('.jbox').index(element);
if (index == rozmiar){
var poprzedni = $('.jbox').eq(0);
}
else{
var poprzedni = $('.jbox').eq(index +1);
}
jBox(poprzedni);
/*$('#jbox-wrapper img').load(function(){
$('#jbox-wrapper').css({
top: ($(window).height() - $('#jbox-wrapper img').innerHeight()) / 2 + 'px'
});
});*/
});
//zamykanie
$('.jbox-close').click(function(){
$(this).parent('.jbox-overlay').fadeOut();
});
}
function changePhoto(photo){
var newphoto = photo.attr('href');
//alert(newphoto);
$.ajax({
url: newphoto,
timeout: 2500,
cache: true,
success: function(html){
//$('#jbox-foto').empty();
$('#jbox-foto').children('img').attr("src", newphoto).hide().fadeIn();
//$('#jbox-foto').append('