function SetGlobalOnLoad(f)
{
	var root = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null;
	if (root)
	{
		if(root.addEventListener)
		{
			root.addEventListener("load", f, false);
		}
		else if(root.attachEvent)
		{
			root.attachEvent("onload", f);
		}
	}
	else
	{
		if(typeof window.onload == 'function')
		{
			var existing = window.onload;
			window.onload = function()
			{
				existing();
				f();
			}
		}
		else
		{
			window.onload = f;
		}
	}
}

function OnLoadSite()
{
	jQuery('table.colorme').find('tr.colorme:odd td').addClass('colorme_odd');
}

SetGlobalOnLoad(OnLoadSite);

function GetScreenDim()
{
	var arr={x:0,y:0};
	if( typeof( window.innerHeight ) == 'number' )
	{
		//Non-IE
		arr['x'] = window.innerWidth;
		arr['y'] = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		//IE 6+ in 'standards compliant mode'
		arr['x'] = document.documentElement.clientWidth;
		arr['y'] = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//IE 4 compatible
		arr['x'] = document.body.clientWidth;
		arr['y'] = document.body.clientHeight;
	}
	return arr;
}

function ResizeImg()
{
	var s=GetScreenDim();
	var ht=s['y'];
	var w=s['x'];

	jQuery('#fullimgoverlay').height(ht);

	var rh=oldheight;
	var rw=oldwidth;
	var r2=rw/rh;
	if((40+rw)>w)
	{
		rw=w-40;
		rh=parseInt(rw/r2);
		r2=-1;
	}
	if((40+rh)>ht)
	{
		rh=ht-40;
		rw=parseInt(rh*r2);
		r2=-1;
	}
	if(r2==-1)
	{
		var fi=jQuery('#fullimg');
		fi.width(rw);
		fi.height(rh);
	}
}

var oldwidth;
var oldheight;

function ShowFullSize(link)
{
	var s=GetScreenDim();
	var ht=s['y'];
	var w=s['x'];

	var src=jQuery(link).attr('href');
	jQuery('body').append('<div id="fullimgoverlay" style="filter:progid:DXImageTransform.Microsoft.Alpha(opacity=70);-moz-opacity:0.7;-khtml-opacity: 0.7;opacity:0.7;background-color:#000;position:fixed;top:0;left:0;width:100%;height:'+ht+'px;z-index:999">&nbsp;</div>\
							<div id="fullimgwrapper" style="position:fixed;top:0;left:0;width:100%;height:'+ht+'px;z-index:1000;">\
							<img id="fullimg" style="padding-top:20px;position:relative;margin:0 auto;z-index:1000;cursor:pointer" alt="Закрыть" src="'+src+'" /></div>');
	var fi=jQuery('#fullimg');
	oldheight=fi.innerHeight();
	oldwidth=fi.innerWidth();
	ResizeImg();
	fi.click(function()
	{
		jQuery('#fullimgwrapper').remove();
		jQuery('#fullimgoverlay').remove();
		jQuery(window).unbind('resize.fullimg');
	});
	jQuery(window).bind('resize.fullimg',ResizeImg);
	return false;
}
