jQuery(function($){
    
  function getPageSize(){
       var xScroll, yScroll;
       if (window.innerHeight && window.scrollMaxY) {
                xScroll = document.body.scrollWidth;
                yScroll = window.innerHeight + window.scrollMaxY;
          	 } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
                   xScroll = document.body.scrollWidth;
                   yScroll = document.body.scrollHeight;
             } else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
                   xScroll = document.documentElement.scrollWidth;
                   yScroll = document.documentElement.scrollHeight;
             } else { // Explorer Mac...would also work in Mozilla and Safari
                   xScroll = document.body.offsetWidth;
                   yScroll = document.body.offsetHeight;
             }
  
             var windowWidth, windowHeight;
             if (self.innerHeight) { // all except Explorer
                  windowWidth = self.innerWidth;
                  windowHeight = self.innerHeight;
             } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
                  windowWidth = document.documentElement.clientWidth;
                  windowHeight = document.documentElement.clientHeight;
             } else if (document.body) { // other Explorers
                     windowWidth = document.body.clientWidth;
                     windowHeight = document.body.clientHeight;
             }
  

             // for small pages with total height less then height of the viewport
             if(yScroll < windowHeight){
                    pageHeight = windowHeight;
             } else {
                    pageHeight = yScroll;
             }

           // for small pages with total width less then width of the viewport
           if(xScroll < windowWidth){
                pageWidth = windowWidth;
        } else {
                 pageWidth = xScroll;
         }
 
         return [pageWidth,pageHeight,windowWidth,windowHeight];
  }
  
		function showPupop(){
			var PageSize=getPageSize();
			var pageheight=PageSize[1];
			$(".shadow_my").css('height',pageheight);
			$(".bigwi_my").text('<img src="http://'+site+$(".photo-photo img").attr('src')+'" alt="'+$(".photo-source").text()+'"/>');
			$(".shadow_my").show();
			$(".code_my").show();
	    }
		function hidePupop(){
			$(".shadow_my").hide();
			$(".code_my").hide();
		}
	

  
  
  function getGroupItems(opts) {
    var imageList = [];
    len = $('#prv a').length;
    if(len==1) {$('body').addClass('singlefancy');}
    for(var i=0; i<=len-1; i++) {
      titlee = $('#prv a').eq(i).children('b').text();
      imgurl = titlee.split('|')[4];
      imageList.push({url:imgurl, title: titlee});
    }

    jQuery.each(imageList, function(i, val) {
      opts.itemArray.push(val);

    });
    var indexofactive = $('.prv li a').index($('.activephoto'));
    if (indexofactive < 0) {
        opts.itemNum = 0;
    } else {
        opts.itemNum = indexofactive;
    }

  }
  
  
  
if(jQuery().jCarouselLiteMy)   {
  $("#prv").jCarouselLiteMy({
    btnNext: ".next",
    btnPrev: ".prev",
    circular: false,
    visible: 3.7,
    speed:500,
    kremlin_mode: 'photo_set'
  });
  
  $("#prv li a").hover(function() {
    $(this).addClass("hover");
  },
                       function() {
                         $(this).removeClass("hover");
                       });
}




//vars
n = $('#prv li').length;
lis = $('#prv li a');
var canon = true;
if($('#display .fotonomer strong')) {
  $('#display .fotonomer strong').text(lis.index($('.activephoto')) + 1);
}


$("#display .photo-photo").fancybox({
  overlayShow: true,
  hideOnContentClick: true,
  itemLoadCallback: getGroupItems
});

function showittome(obj){
  $('#prv a').removeClass('activephoto');
  obj.addClass('activephoto');
  // retrieve data
  var update = obj.children('b').text().split('|');

  $('#display').fadeOut(250, function () {
    var display = $('#display');
    /*display.find('.photo-toblog').attr({'href':update[5], 'title':update[1]});*/
    display.find('.photo-copy').attr('href', update[4]);
    display.find('.fotonomer strong').text((lis.index($('.activephoto')) + 1));
    display.find('.moretext').empty().append(update[1] + '<span class="photo-date">' + update[3] + '</span>');
    display.find('.photo-photo').attr('href', update[4]);
    display.find('.photo-photo img').attr({'src': update[5], 'alt':update[1]});
    display.find('.photo-source').empty().append(update[0]);
  });
  
  $('#display').fadeIn(250, function() {
    canon = true;
    $("#display .photo-photo").fancybox({										
      overlayShow: true,
      hideOnContentClick: true,
      itemLoadCallback: getGroupItems
    });
  });
  
}
function checkit(){
  nomer = lis.index($('.activephoto')) + 1;
  $('.prev,.next').removeClass('disabled');
  if(nomer==1){$('.prev').addClass('disabled');}
  if(nomer==n){$('.next').addClass('disabled');$('.photo-shadow').hide();} else{$('.photo-shadow').show();}
}

$('#prv a').click(function() {
  if($(this).hasClass('activephoto')){return false;}
  showittome($(this));
  checkit();
  return false;
});
								$(".photo-toblog").live('click', function(){
									  showPupop();
								});					
								$(".shadow_my").click(function(){
									  hidePupop();
								 });
								$(".tt-close_my").click(function(){
									  hidePupop();
								 });

$('#display').hoverIntent(function() {
  $('.photo-actions').slideDown();
  
}, function(){
  $('.photo-actions').slideUp();
});
$('.mg-img').hoverIntent(function() {
  $('.mg-photo-actions').slideDown();
}, function(){
  $('.mg-photo-actions').slideUp();
});
$('.next').click(function() {
  if(canon){
    canon = false;
    bubu = $('.activephoto');
    actualnomer = lis.index(bubu) +1;
    if(actualnomer!=n){
      eltoshow = $('#prv a').get(actualnomer);
      showittome($(eltoshow));
    }
    else{canon=true}
    checkit();
    return false;
  }
});
$('.prev').click(function() {
  if(canon){
    canon = false;
    bubu = $('.activephoto');
    actualnomer = lis.index(bubu) + 1;
    if(actualnomer!=1){
      eltoshow = $('#prv a').get(actualnomer-2);
      showittome($(eltoshow));
    }
    else{canon=true}
    checkit();
    return false;
  }
});


$('span.showmore').click(function(){
  $('.moretext').slideToggle();
  $('.showmore').toggleClass('photomoreshowed');
  a = $('#display span.txt-jsdonor').text().split('|||')[0];
  b = $('#display span.txt-jsdonor').text().split('|||')[1];
  $('.showmore').text(jQuery('.showmore').text() == a ? b : a);
  return false;
});

});