/// ImgBox is written by Jarosław Pendowski
/// this product is NOT free to use
/// if you want to use it - please contact me at: shw@shwsite.org
/// copyright (c) 2007

var imgbox = {
	hideflash : false
};

jQuery(document).ready(function() 
{
	jQuery('a.imgbox').click(function()
	{
		imgbox_show(this.href);
		return false;
	});
});

function imgbox_show(img)
{
	var bodyh = jQuery.browser.msie ? document.getElementsByTagName('body')[0].clientHeight : jQuery('body').height(); //jQuery(document).height();//jQuery.browser.msie ? document.body.offsetWidth : window.innerWidth;
	var bodyw = jQuery('body').width();//jQuery.browser.msie ? document.body.offsetHeight : window.innerHeight;
	var window_height = jQuery.browser.msie ? document.documentElement.clientHeight : window.innerHeight;
	
	var window_scroll = document.documentElement.scrollTop;
	//jQuery(document).scroll(function() { document.documentElement.scrollTop = window_scroll; }); // block scrolling Doesn't work in IE. Ugly in the rest
	
	jQuery('body').append('<div id="imgbox_window" style="height: ' + bodyh + 'px; width: ' + bodyw + 'px"></div>');
	//jQuery('body').css({ 'overflow' : 'hidden' , 'height' : '100%' , 'width' : '100%'});
	if(imgbox.hideflash)
	{
		jQuery('object , embed').hide();
	}
	
	var imgp = new Image();
	imgp.onload = function()
	{	
		var mleft = Math.floor((bodyw - imgp.width) / 2);
		//var mtop = Math.floor((winh - imgp.height) / 2);
		var mtop = Math.floor(window_scroll + (window_height - imgp.height) / 2);
		var imgh = imgp.height;
		var imgw = imgp.width;
		
		jQuery('body').append('<div id="imgbox"><a href="javascript:void(0)" onclick="imgbox_close()"><img src="img/close.png" alt="Zamknij okienko" /></a><div></div></div>');
		jQuery('#imgbox').css({ 'top' : mtop + 'px', 'left' : mleft + 'px'});
		jQuery('#imgbox div').css({ 'background-image' : 'url(' + img + ')' , 'height': imgh + 'px' , 'width': imgw + 'px'});
		
		jQuery('#imgbox a, #imgbox').click(function() 
			{
				imgbox_close();
				document.body.scrollTop = scroll;
			});
		// MSIE png hack
		if(jQuery.browser.msie) { jQuery('#imgbox img').pngfix(); }
	}
	imgp.src = img;

	return false;
}

function imgbox_close()
{
	if(imgbox.hideflash)
	{
		jQuery('object , embed').show();
	}
	jQuery('#imgbox , #imgbox_window').remove(); 
	//jQuery('body').css({ 'overflow' : 'visible' , 'height' : 'auto' , 'width' : 'auto'});
}