function FC(Elt)
{
	//return First Child;
	for(var i=0;i<Elt.childNodes.length;i++)
		if (typeof(Elt.childNodes[i].tagName)!= "undefined")
			return Elt.childNodes[i];
	return null;
}
function CFixStyle(d)
{
	var me=this;
	var debug=d;
	var old_w=0;
	var h_size=10;
	var ie_content_height_fix=150;
	var v_size=15;
	var p1,p2,p3;
	var fStart=1;
	var tmp=null;
	CFixStyle.prototype.window_load=function()
	{
		//return ;
		if(tmp) clearTimeout(tmp);
		tmp=null;
		me.MSG('Start');
		if (fStart)
		{
			me.CheckRootWidth(760);
			me.CheckRootWidth(null);
		}
		else
			me.CheckRootWidth(null);
		
		me.CheckWidth();
		me.CheckHeight();
		
		me.CheckPositionsMain();
		me.ShowData();
		var root=$('root');
		if(root) root.style.top="0px";
		//me.ShowAreas();
		return;
		me.CheckRootWidth(null);
		
		
		me.MSG('End');
		if (fStart)
		{
			fStart=0;
			tmp=setTimeout(me.window_load,300);
		}
	}
	CFixStyle.prototype.ShowAreas=function()
	{
	 var a=['header','leftzone','rightzone','news','content','footer','photo','search','header_main'];
	 var x;
	 for(var i=0;i<a.length;i++)
	 {
	  x=$(a[i]);
	  if (x) x.style.display='block';
	 }
	}
	CFixStyle.prototype.ShowData=function()
	{
		var data=$("data_out");
		if(data)
		{
			var d=new Date();
			var YYYY=d.getFullYear();
			var DD=d.getDate();
			var Day=d.getDay();
			var MM=d.getMonth()+1;
			var sDay,sMM;
			switch(Day)
			{
				case 0:sDay="воскресенье";break;
				case 1:sDay="понедельник";break;
				case 2:sDay="вторник";break;
				
				case 3:sDay="среда";break;
				case 4:sDay="четверг";break;
				case 5:sDay="пятница";break;
				
				case 6:sDay="суббота";break;
			}
			switch(MM)
			{
				case 1:sMM="января";break;
				case 2:sMM="февраля";break;
				case 3:sMM="марта";break;
				
				case 4:sMM="мая";break;
				case 5:sMM="апреля";break;
				case 6:sMM="июня";break;
				
				case 7:sMM="июля";break;
				case 8:sMM="августа";break;
				case 9:sMM="сентября";break;
				
				case 10:sMM="октября";break;
				case 11:sMM="ноября";break;
				case 12:sMM="декабря";break;
			}
			data.innerHTML="<span>"+DD.toString()+" "+sMM+" "+YYYY.toString()+", "+sDay+"</span>";
		}
	}
	CFixStyle.prototype.CheckRootWidth=function(pW)
	{
		var w=document.documentElement.clientWidth?document.documentElement.clientWidth-25:document.body.clientWidth-25;
		//var w=window.innerWidth;
		//me.MSG("---------------");
		//for(var p in window.Image) me.MSG(p+' '+window.Image[p]);
		//me.MSG("---------------");
		//var w=window.innerWidth-25;
		if(pW) w=pW;
		me.MSG("W= "+w);
		me.MSG("pW= "+pW);
		var root=$('root');
		if(root)
		{
			if (w>1240)
				root.style.width="1240px";
			else
				if (w<760)
					root.style.width="760px";
				else
					root.style.width=w.toString()+"px";
		}
		FC(FC(FC($("header")))).style.width=(root.offsetWidth-23-25-3).toString()+"px";
		me.MSG("root.offsetWidth= "+root.offsetWidth);
		p1=Math.floor(root.offsetWidth*261/1024);
		p3=Math.floor(root.offsetWidth*243/1024);
		
		p2=root.offsetWidth-23-25-p1-p3-20;
	}
	CFixStyle.prototype.CheckPositionsMain=function()
	{
		var content=$('content');
		var news=$('news');
		var rightzone=$('rightzone');
		
		var leftzone=$('leftzone');
		var search=$('search');
		var root=$('root');
		var footer=$('footer');
		var header=$('header');
		var header_main=$('header_main');
		var photo=$('photo');
		var links=$('links');
		
		if(news)
		{
			var h_top=leftzone.offsetHeight+v_size*2+photo.offsetHeight+search.offsetHeight
			rightzone.style.top="-"+h_top.toString()+'px';
			rightzone.style.left=(2*h_size+p1+p2).toString()+'px';
			
			h_top+=rightzone.offsetHeight;
			content.style.top="-"+h_top.toString()+"px";
			content.style.left=(h_size+p1).toString()+"px";
			
			h_top-=v_size;
			news.style.top="-"+h_top.toString()+"px";
			news.style.left=(h_size+p1).toString()+"px";
			
			//h_top+=news.offsetHeight+content.offsetHeight;
			
			h_top+=links.offsetHeight;
			
			links.style.top="-"+h_top.toString()+'px';
			links.style.left=(2*h_size+p1+p2).toString()+'px';
			
			footer.style.top="-"+h_top.toString()+"px";

		}
		else
		{
			var h_top=leftzone.offsetHeight+v_size*2+photo.offsetHeight+search.offsetHeight
			
			content.style.top="-"+h_top.toString()+"px";
			content.style.left=(p1+h_size).toString()+"px";
			footer.style.top="-"+h_top.toString()+"px";
		}

		root.style.height=(header_main.offsetHeight+header.offsetHeight+leftzone.offsetHeight+photo.offsetHeight+search.offsetHeight+footer.offsetHeight+v_size*3).toString()+'px';
	}
	CFixStyle.prototype.CheckWidth=function()
	{
		var leftzone=$('leftzone');
		var content=$('content');
		var news=$('news');
		var search=$('search');
		var rightzone=$('rightzone');
		var photo=$('photo');
		var links=$('links');
		
		if(news)
		{
			leftzone.style.width=p1.toString()+"px";
			search.style.width=p1.toString()+"px";
			
			content.style.width=p2.toString()+"px";
			news.style.width=p2.toString()+"px";
			
			rightzone.style.width=p3.toString()+"px";
			links.style.width=p3.toString()+"px";
		}
		else
		{
			leftzone.style.width=p1.toString()+"px";
			search.style.width=p1.toString()+"px";
			
			content.style.width=(p2+p3+h_size).toString()+"px";
			
		}
		if(photo) photo.style.width=p1.toString()+"px";
	}
	CFixStyle.prototype.CheckHeight=function()
	{
		var content=$('content');
		var news=$('news');
		var rightzone=$('rightzone');
		var leftzone=$('leftzone');
		var search=$('search');
		var root=$('root');
		var footer=$('footer');
		var header=$('header');
		var photo=$('photo');
		var header_main=$('header_main');
		var links=$('links');
		if(news)
		{
			var h1=FC(FC(FC(leftzone))).offsetHeight+v_size*2+search.offsetHeight+photo.offsetHeight;
			var h2=FC(FC(FC(content))).offsetHeight+v_size+FC(FC(FC(news))).offsetHeight;
			var h3=FC(FC(FC(rightzone))).offsetHeight+FC(FC(FC(links))).offsetHeight+v_size*2;

			var h=h1>h2?h1:h2;
			h=h>h3?h:h3;
			me.MSG("h="+h);
			me.MSG("h1="+h1);
			me.MSG("h2="+h2);
			me.MSG("h3="+h3);
			
			var r_h=(h-links.offsetHeight).toString()+"px";
			var r_h2=(h-links.offsetHeight-2).toString()+"px";
			
			rightzone.style.height=r_h;
			FC(rightzone).style.height=r_h;
			FC(FC(rightzone)).style.height=r_h2;
			
			var l_h=links.offsetHeight.toString()+"px";
			var l_h2=(links.offsetHeight-2).toString()+"px";
			
			links.style.height=l_h;
			FC(links).style.height=l_h;
			FC(FC(links)).style.height=l_h2;
			
			
			var n_h=(h-FC(content).offsetHeight-2).toString()+"px";
			var n_h2=(h-FC(content).offsetHeight-2-2).toString()+"px";
			news.style.height=n_h;
			FC(news).style.height=n_h;
			FC(FC(news)).style.height=n_h2;
			
			leftzone.style.height=(h-search.offsetHeight-photo.offsetHeight-v_size).toString()+"px";
			FC(leftzone).style.height=(h-search.offsetHeight-photo.offsetHeight-v_size).toString()+"px";
			FC(FC(leftzone)).style.height=(h-search.offsetHeight-photo.offsetHeight-v_size-2).toString()+"px";
			
		}
		else
		{
			var h1=FC(FC(FC(leftzone))).offsetHeight+2*v_size+search.offsetHeight+photo.offsetHeight;
			var h2=FC(FC(FC(content))).offsetHeight;
			if (navigator.appName=="Microsoft Internet Explorer") {h2+=ie_content_height_fix;}
			var h=h1>h2?h1:h2;
			
			leftzone.style.height=(h-search.offsetHeight-photo.offsetHeight-v_size*2).toString()+"px";
			FC(leftzone).style.height=(h-search.offsetHeight-photo.offsetHeight-v_size*2).toString()+"px";
			FC(FC(leftzone)).style.height=(h-search.offsetHeight-photo.offsetHeight-v_size*2-2).toString()+"px";
			
			content.style.height=h.toString()+"px";
			FC(content).style.height=h.toString()+"px";
			FC(FC(content)).style.height=(h-17+v_size).toString()+"px";
		}
		
	}
	CFixStyle.prototype.MSG=function(Par)
	{
		if(!debug) return;
		debug.MSG(Par);
	}
}

var fix_style;
var fix_style_debug=null;

function fix_style_start()
{
	//fix_style_debug=new CDebug(300,300,0,0,"Выравнивание");
	fix_style=new CFixStyle(fix_style_debug);
	fix_style.window_load();
	addEvent(window, 'resize', fix_style.window_load, false);
}
pushLoadEvent(fix_style_start);
//addEvent(window, 'load', fix_style_start, false);