$(document).ready(function () {
    $('#big-photo-container').click(function(){
	$(this).css('display', 'none');
	if(interval) clearInterval(interval)
    });

     $('.photo').
              click(function(){
              	var top = 0;
              	if(window.document.body.scrollTop) top = window.document.body.scrollTop
              	ch = document.body.clientHeight
              	if(top <= window.document.documentElement.scrollTop) { top = window.document.documentElement.scrollTop; ch = window.document.documentElement.clientHeight; }
              	//alert(top + "---" + ch + "===" + $(this).attr('big_height'))
              	interval = $(this).attr('big_reload') ? setInterval ( "reloadImage('" + $(this).attr('big_address') + "')", $(this).attr('big_reload') ) : 0 ;
                      $('#big-photo-container div').remove();
                      $('#big-photo-container').css({
                              'display':'block',
                              'z-index':'1000',
                              'width':$(this).attr('big_width')+'px',
                              'margin-left':(-$(this).attr('big_width')/2)+'px',
                              'height':(parseInt($(this).attr('big_height'))+35)+'px',
		'top':top+ch/2-$(this).attr('big_height')/2+'px'
                      });
                      $(this).attr('orig_address') ? $('<div style="text-align: center"><img src="'+$(this).attr('big_address')+'" id="img_photo" height="' + $(this).attr('big_height') + '" width="' + $(this).attr('big_width')+ '" /><p class="pimg"><a href="#" onclick="origOpen(\'' + $(this).attr('orig_address') + '\',' + $(this).attr('orig_height') + ',' + $(this).attr('orig_width') + ');return false;">фото в полный размер ('+$(this).attr('orig_width')+'x'+$(this).attr('orig_height')+' пикселей)</a></div>').appendTo('#big-photo-container') : $('<div style="text-align: center"><img src="'+$(this).attr('big_address')+'" id="img_photo"  /></div>').appendTo('#big-photo-container');
              });
});
function reloadImage(src)
{
	var img = document.getElementById('img_photo')
	var d = new Date();
	var t = d.getTime();
	if(img) {
	
		img.src = src + "?cache=" + t
	}
}
function popupOpen(img)
{
	var w = 20 + parseFloat(img.attributes['big_width'].value)
	var h = 20 + parseFloat(img.attributes['big_height'].value) 
	window.open(img.attributes['big_address'].value, 'img_popup', 'height=' + h + ',width=' + w + ',status=no,toolbar=no')
}
function origOpen(addr,h,w)
{
	window.open(addr, 'img_popup', 'height=' + (20+h) + ',width=' + (20+w) + ',status=no,toolbar=no')
}