function my_getbyid(id)
{
 itm = null;

 if (document.getElementById)
 {
 itm = document.getElementById(id);
 }
 else if (document.all)
 {
 itm = document.all[id];
 }
 else if (document.layers)
 {
 itm = document.layers[id];
 }

 return itm;
}
function toggleview(id)
{
 if ( ! id ) return;

 if ( itm = my_getbyid(id) )
 {
 if (itm.style.display == "none")
 {
 my_show_div(itm);
 }
 else
 {
 my_hide_div(itm);
 }
 }
}

function my_hide_div(itm)
{
 if ( ! itm ) return;
 itm.style.display = "none";
}

function my_show_div(itm)
{
 if ( ! itm ) return;
 itm.style.display = "";
}

var endW = 0, endH = 0, myWidth = 0, myHeight = 0, myScroll = 0; myScrollWidth = 0; myScrollHeight = 0;


function getSize() {

	// Window Size

	if (self.innerHeight) { // Everyone but IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		myScroll = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.clientHeight) { // IE6 Strict
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		myScroll = document.documentElement.scrollTop;
	} else if (document.body) { // Other IE, such as IE7
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		myScroll = document.body.scrollTop;
	}

	// Page size w/offscreen areas

	if (window.innerHeight && window.scrollMaxY) {	
		myScrollWidth = document.body.scrollWidth;
		myScrollHeight = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // All but Explorer Mac
		myScrollWidth = document.body.scrollWidth;
		myScrollHeight = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		myScrollWidth = document.body.offsetWidth;
		myScrollHeight = document.body.offsetHeight;
	}
}
function showimagepreview(srcimg, ptitle, pdate, p_id, endW, endH)
{
	if (parseInt(endW) > 100 && parseInt(endH) > 100)
	{
		endW = parseInt(endW) - 30;
		endH = parseInt(endH) - 30;
	}
	
	endH = endH - 30;
	getSize();
	mW = 800;
	mH = 600;
	if ((endW > mW)||(endH > mH))
	{
		if (endW > endH)
		{
			endH = parseInt(((mW/endW)*endH));
			endW = mW;
			if (endH>mH)
			{
				endW = parseInt(((mH/endH)*endW));
				endH = mH;
			}
		}
		else
		{
			endW = parseInt(((mH/endH)*endW));
			endH = mH;
			if (endW>mW)
			{
				endH = parseInt(((mW/endW)*endW));
				endW = mW;
			}
		}
	}

	sizeRatio = endW / endH;
	if (endW > myWidth) {
		endW = myWidth;
		endH = endW / sizeRatio;
	}
	if (endH > myHeight) {
		endH = myHeight;
		endW = endH * sizeRatio;
	}
	zoomChangeX = ((myWidth / 2) - (endW / 2) );
	zoomChangeY = (((myHeight / 2) - (endH / 2) ) + myScroll);
	a = my_getbyid('image_preview');
	a.style.visibility = 'visible';
	a.style.width = parseInt(endW) + 'px';
	a.style.height = parseInt(endH) + 30 + 'px';
	a.style.left = zoomChangeX + 'px';
	a.style.top = zoomChangeY + 'px';
	a.innerHTML = '<DIV style="float : left;"> &nbsp; &nbsp; '+((ptitle!="")?'<B>'+ptitle+'</B>':'')+' [ '+pdate+' ] &nbsp; &nbsp; </DIV> <DIV style="float : right;"> <A class="link_black" onclick="hideimagepreview();"><IMG src="/images/closebox.png" ></A> </DIV>'+'<IMG width="'+endW+'" height="'+endH+'" src="images/gallery/'+srcimg+'" onclick="hideimagepreview();"><BR><A style="background-color:white;" href="gallery.php?act=photo&id='+p_id+'" class="link_black">Подробнее</A>';
	return false;
}

function hideimagepreview()
{
	a = my_getbyid('image_preview');
	a.style.visibility = 'hidden';
}