/*This file is part of SLIRK Layout.
SLIRK Layout is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
SLIRK Layout is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SLIRK Layout. If not, see <http://www.gnu.org/licenses/>.*/

function slirk()
	{
		window.document.body.style.overflow = 'hidden';
		var container = document.getElementById('container');
		var header = document.getElementById('header');
		var h = header.clientHeight;
		container.style.overflow = 'hidden';
		container.style.height = '100%';
		maxInnerColumnHeight = 0;
		var innerHeightColumn = new Array();
		var columnId = new Array();
		var nCol = 0;
		var column = container.getElementsByTagName('DIV')[nCol];
		while(column)
			{
				if(column.className == 'slirk_column')
					{
						column.style.height = '100%';
						column.style.overflow = 'hidden';
						column.style.cssFloat = 'left';
						column.style.styleFloat = 'left';
						columnId[nCol] = column.getAttribute('id');
						var first = column.getElementsByTagName('DIV')[0];
						first.style.position = 'relative';
						first.style.width = '100%';
						innerHeightColumn[nCol] = first.clientHeight;
						if(innerHeightColumn[nCol] > maxInnerColumnHeight)
							{
								maxInnerColumnHeight = innerHeightColumn[nCol];
							}
						nCol++;
					}
				column = column.nextSibling;
			}
		var scrollbar = document.createElement('div');
		scrollbar.style.position = 'absolute';
		scrollbar.style.top = '0';
		scrollbar.style.right = '0';
		scrollbar.style.width = '100%';
		scrollbar.style.height = '100%';
		scrollbar.style.overflow = 'auto';
		scrollbar.style.overflowx = 'hidden';
		window.document.body.appendChild(scrollbar);
		var scrollbarContent = document.createElement('div');
		scrollbarContent.style.height = maxInnerColumnHeight + h;
		scrollbar.appendChild(scrollbarContent);
		scrollbar.style.width = scrollbar.offsetWidth - scrollbar.clientWidth + 1;
		container.style.width = container.clientWidth + scrollbar.offsetWidth - 1;
		scrollbar.scrollTop = 0;
		for(i=0;i<nCol;i++)
			{
				document.getElementById(columnId[i]).scrollTop = scrollbar.scrollTop;
			}
		if(scrollbar.addEventListener)
			{
				scrollbar.addEventListener('scroll',function()
					{
						if(scrollbar.scrollTop > h)
							{
								container.scrollTop = h;
								for(i=0;i<nCol;i++)
									{
										document.getElementById(columnId[i]).scrollTop = (scrollbar.scrollTop-h)*(innerHeightColumn[i]-scrollbar.clientHeight)/(maxInnerColumnHeight-scrollbar.clientHeight);
									}
							}
						else
							{
								container.scrollTop = scrollbar.scrollTop;
								for(i=0;i<nCol;i++)
									{
										document.getElementById(columnId[i]).scrollTop = 0;
									}
							}
					},false);
			}
		else if(scrollbar.attachEvent)
			{
				scrollbar.attachEvent('onscroll',function()
					{
						if(scrollbar.scrollTop > h)
							{
								container.scrollTop = h;
								for(i=0;i<nCol;i++)
									{
										document.getElementById(columnId[i]).scrollTop = (scrollbar.scrollTop-h)*(innerHeightColumn[i]-scrollbar.clientHeight)/(maxInnerColumnHeight-scrollbar.clientHeight);
									}
							}
						else
							{
								container.scrollTop = scrollbar.scrollTop;
								for(i=0;i<nCol;i++)
									{
										document.getElementById(columnId[i]).scrollTop = 0;
									}
							}
					});
			}
		if(window.addEventListener) window.addEventListener('DOMMouseScroll',wheel,false);
		window.onmousewheel = document.onmousewheel = wheel;
		function wheel(event)
			{
				var delta=0;
				if(!event) event = window.event;
				if(event.wheelDelta)
					{
						delta = event.wheelDelta/120;
						if(window.opera) delta = -delta;
					}
				else if(event.detail)
					{
						delta = -event.detail/3;
					}
				if(delta)
					{
						scrollbar.scrollTop -= maxInnerColumnHeight/100*delta;
					}
				if(event.preventDefault) event.preventDefault();
				event.returnValue = false;
			}
	}