var _boxCount = 0;
var _hasPNG = true;
var _siw = -1;

function fixBoxSize(BoxIdentifier)
{
	var boxContent = document.getElementById(BoxIdentifier + '_Content');
	if( boxContent == null )
	{
		return false;
	}

	document.getElementById(BoxIdentifier + '_Top').style.width = boxContent.offsetWidth + 'px';
	document.getElementById(BoxIdentifier + '_Bottom').style.width = boxContent.offsetWidth + 'px';
	
	document.getElementById(BoxIdentifier + '_Left').style.height = boxContent.offsetHeight + 'px';
	document.getElementById(BoxIdentifier + '_Right').style.height = boxContent.offsetHeight + 'px';
}

function fixBoxes()
{
	for( var i = 0; i < _boxCount; i++ )
	{
		fixBoxSize('Box' + i);
	}
}

function createBox(Content,Header)
{
	var Ext = "png";
	if( _hasPNG == false )
	{
		Ext = "gif";
	}
	var Identifier = 'Box' + _boxCount;
	var NewBox = '<table class="box" border="0" cellpadding="0" cellspacing="0" width="260"><tr><td width="23"><img src="img/site/box/topleft.' + Ext + '" alt="" border="0" width="23" height="23" /></td>';
	NewBox += '<td width="*"><img id="' + Identifier + '_Top" src="img/site/box/top.' + Ext + '" alt="" border="0" width="23" height="23" /></td>';
	NewBox += '<td width="23"><img src="img/site/box/topright.' + Ext + '" alt="" border="0" width="23" height="23" /></td>';
	NewBox += '</tr><tr><td><img id="' + Identifier + '_Left" src="img/site/box/left.' + Ext + '" alt="" border="0" width="23" height="23" /></td>';
	NewBox += '<td id="' + Identifier + '_Content" style="background-image:url(\'img/site/box/background.gif\')">';
	NewBox += Header + '<div class="content">' + Content;
	NewBox += '</div></td><td width="23"><img id="' + Identifier + '_Right" src="img/site/box/right.' + Ext + '" alt="" border="0" width="23" height="23" /></td>';
	NewBox += '</tr><tr><td><img src="img/site/box/bottomleft.' + Ext + '" alt="" border="0" width="23" height="23" /></td>';
	NewBox += '<td><img id="' + Identifier + '_Bottom" src="img/site/box/bottom.' + Ext + '" alt="" border="0" width="23" height="23" /></td>';
	NewBox += '<td><img src="img/site/box/bottomright.' + Ext + '" alt="" border="0" width="23" height="23" /></td></tr></table>';
	
	_boxCount++;
	
	return NewBox;
}

function splendidResize()
{
	var viewportWidth = document.body.clientWidth;
	var viewportHeight = document.body.clientHeight;
	var leftcolumnWidth = document.getElementById('leftcolumn').offsetWidth;
	var rightcolumnWidth = document.getElementById('rightcolumn').offsetWidth;
	var themaHeight = document.getElementById('thema').offsetHeight;
	var contentbackgroundWidth = (viewportWidth-leftcolumnWidth-rightcolumnWidth);
	
	var moveleft = 0;
	if( contentbackgroundWidth < 650 )
	{
		// Niet smaller dan 650 pixels
		moveleft = 650-contentbackgroundWidth;
		if( moveleft > 67 )
		{
			// En niet meer dan 67 pixels naar links verschuiven
			moveleft = 67;
		}
		contentbackgroundWidth = 650;
	}
	var topbarWidth = viewportWidth;
	if( topbarWidth < 1024 )
	{
		topbarWidth = 1024;
	}
	var rightcolumnLeft = contentbackgroundWidth+leftcolumnWidth;
	
	// Website schalen
	document.getElementById('topbar').style.width = topbarWidth + 'px';
	document.getElementById('contentbackground').style.width = contentbackgroundWidth + 'px';
	document.getElementById('rightcolumn').style.left = (-moveleft+rightcolumnLeft) + 'px';
	document.getElementById('contentdropshadowright').style.left = (-moveleft+rightcolumnLeft) + 'px';
	document.getElementById('kop').style.marginLeft = (contentbackgroundWidth-650) + 'px';
	
	var kopbackgroundWidth = document.getElementById('kopholder').offsetWidth-450;
	if( kopbackgroundWidth < 1 )
	{
		document.getElementById('kopbackground').style.display = 'none';
	}
	else
	{
		document.getElementById('kopbackground').style.display = '';
		document.getElementById('kopbackground').style.width = kopbackgroundWidth + 'px';
	}
	
	var contentbackgroundHeight = document.getElementById('contentbackground').offsetHeight;

	if( document.getElementById('content').offsetHeight < viewportHeight )
	{
		contentbackgroundHeight = document.getElementById('content').offsetHeight;
		contentbackgroundHeight = viewportHeight-75;
		if( contentbackgroundHeight < (themaHeight+88) )
		{
			contentbackgroundHeight = themaHeight+88;
		}
		document.getElementById('contentbackground').style.height = contentbackgroundHeight + 'px';
	}
	
	//document.getElementById('thema').style.height = (contentbackgroundHeight-88) + 'px';
	document.getElementById('themafiller').style.height = (contentbackgroundHeight-606-88) + 'px';
	
		
	// Schaduwen	
	document.getElementById('contentdropshadowleft').style.height = (contentbackgroundHeight-17) + 'px';
	document.getElementById('contentdropshadowright').style.height = contentbackgroundHeight + 'px';
	document.getElementById('topbardropshadow').style.width = (topbarWidth-200) + 'px';
	
	// Decoratie
	document.getElementById('deconoteright').style.top = (contentbackgroundHeight-216) + 'px';
	document.getElementById('decostarleft').style.top = (contentbackgroundHeight-248-33) + 'px';
	document.getElementById('deconotestopbarright').style.left = (topbarWidth-240) + 'px';
		
	// Eventueel de zaak naar links verschuiven
	document.getElementById('topbar').style.left = (-moveleft) + 'px';
	document.getElementById('topbarexp').style.left = (-moveleft) + 'px';
	document.getElementById('topbardropshadow').style.left = ((-moveleft)+200) + 'px';
	document.getElementById('topbarexpdropshadow').style.left = (-moveleft) + 'px';
	document.getElementById('leftcolumn').style.left = (-moveleft) + 'px';
	document.getElementById('contentbackground').style.left = (-moveleft+100) + 'px';
	document.getElementById('menubar').style.left = (-moveleft+198) + 'px';
	document.getElementById('logo').style.left = (-moveleft+70) + 'px';
	document.getElementById('logodropshadow').style.left = (-moveleft+46) + 'px';
	document.getElementById('contentdropshadowleft').style.left = (-moveleft+86) + 'px';
	document.getElementById('photofadeleft').style.left = (-moveleft+371) + 'px';
	
	var topbarphotowidth = topbarWidth-rightcolumnWidth-390;
	var topbarphotoleft = parseInt(document.getElementById('topbarphoto').offsetLeft);
	document.getElementById('topbarphoto').style.width = topbarphotowidth + 'px';
	document.getElementById('photofaderight').style.left = (-moveleft+topbarphotowidth+topbarphotoleft-60) + 'px';
	
	// scaleimage resizen?
	var si = document.getElementById('scaleimage');
	if( si != null )
	{
		if( _siw > -1 )
		{
			var nw = contentbackgroundWidth-300;
			if( nw > _siw )
			{
				nw = _siw;
			}
			si.style.width = nw + 'px';	
		}	
	}
}

function initSIW()
{
	var si = document.getElementById('scaleimage');
	if( si != null )
	{
		_siw = si.offsetWidth;
	}
	
	splendidResize();
}

function pngCheck()
{
	var version = 0
	if( navigator.appVersion.indexOf("MSIE") != -1 )
	{
		var temp = navigator.appVersion.split("MSIE");
		version = parseFloat(temp[1]);
		
		if( version < 5.5 )
		{
			// Geen PNG support in internet explorer < 5.5
			_hasPNG = false;
		}
	}
}

function init()
{
	if( _hasPNG != false )
	{
		document.getElementById('contentdropshadowleft').style.display = 'block';
		document.getElementById('contentdropshadowright').style.display = 'block';
		document.getElementById('topbardropshadow').style.display = 'block';
		document.getElementById('topbarexpdropshadow').style.display = 'block';
		document.getElementById('logodropshadow').style.display = 'block';
		document.getElementById('deconotestopbarleft').style.display = 'block';
		document.getElementById('deconotestopbarright').style.display = 'block';
		document.getElementById('decostarleft').style.display = 'block';
		document.getElementById('deconoteright').style.display = 'block';
		document.getElementById('photofadeleft').style.display = 'block';
		document.getElementById('photofaderight').style.display = 'block';
	}
	
	splendidResize();
	fixBoxes();
	
	setTimeout("updateTopbarPhoto()",500);
}

// Eerst PNG/IE check uitvoeren
pngCheck();

// ******************************************************************
// Topbar photo functies

var _stsleft = 0;
var _stsdir = 0;
var _stshold = 0;

function updateTopbarPhoto()
{
	var topbarphoto = document.getElementById('topbarphoto');
	var sts = document.getElementById('sts');
	
	if( sts == undefined )
	{
		topbarphoto.innerHTML = topbarPhotosData;
		setTimeout("updateTopbarPhoto()",60);
		return;
	}
	
	var stsWidth = sts.offsetWidth;
	var topbarphotoWidth = topbarphoto.offsetWidth;
	
	if(( stsWidth > topbarphotoWidth ) && ( _stshold != 1 ))
	{	
		if( _stsdir == 0 )
		{
			// naar links
			_stsleft--;
			
			if( _stsleft <= topbarphotoWidth-stsWidth )
			{
				_stsdir = 1;
			}
		}
		else
		{
			// naar rechts
			_stsleft++;
			if( _stsleft == 0 )
			{
				_stsdir = 0;
			}
		}
	}
	
	sts.style.left = _stsleft + 'px';
	
	setTimeout("updateTopbarPhoto()",60);
}

function topbarphotohold(state)
{
	_stshold = state;
}

function confirmRedirect(Text,URL)
{
	if( confirm(Text) )
	{
		location.href = URL;
		return true;
	}
	return false;
}
