var emptyLeftColumn = false;
var currentTab = 1;
var oldTab = 0;
function showTab( value )
{
	if ( document.getElementById( 'tab1' ) )
	{
		oldTab = currentTab;
		currentTab = value;

		cookieWrite();
		
		document.getElementById( 'tab1' ).style.display = 'none';
		document.getElementById( 'tab2' ).style.display = 'none';
		document.getElementById( 'tab3' ).style.display = 'none';
		document.getElementById( 'tab4' ).style.display = 'none';
		document.getElementById( 'tab5' ).style.display = 'none';
		document.getElementById( 'tab' + value ).style.display = 'block';
	}
	if ( mnObj = document.getElementById( 't-tab' + oldTab) )
	{      	mnObj.style.backgroundColor='#888888';
	}
	if ( mnObj = document.getElementById( 't-tab' + currentTab) )
	{      	mnObj.style.backgroundColor='#D81E05';
	}
}

function init()
{
	var url		= document.location.pathname.substring(1);
	var section	= url.substring( 0, url.indexOf('/') );
	
	//alert( section );
	
	if ( section.length == 0 )
	{
		section = 'home';
		
		if ( document.getElementById( 'tab1' ) )
		{
			section = 'teams';
		}
	}
	
	if ( mnObj = document.getElementById( 'm-' + section ) )
	{
		mnObj.onmouseover = null;
		mnObj.onmouseout = null;
		mnObj.style.backgroundColor='#D81E05';
	}
	
	if ( bgObj = document.getElementById( 'rightcolumn' ) )
	{
		setBackgroundImage( bgObj );
	}
	else if ( bgObj = document.getElementById( 'mannetje' ) )
	{
		setBackgroundImage( bgObj );
	}
	
	//if ( section == "teams" )
	//{
		cookieRead();
		showTab( currentTab );
	//}
}

function setBackgroundImage( bgObj )
{
		images	= ['01.png', '02.png', '03.png', '04.png', '05.png', '06.png', '07.png', '08.png'];
		randomi	= Math.floor(Math.random() * images.length);
		bgObj.style.background = 'url(/fileadmin/template/images/mannetjes/' + images[randomi] + ') no-repeat bottom';
		
		if ( emptyLeftColumn )
		{
			bgObj = document.getElementById( 'leftcolumn' );
			images.splice( randomi, 1 );
			randomi	= Math.floor(Math.random() * images.length);
			bgObj.style.background = 'url(/fileadmin/template/images/mannetjes/' + images[randomi] + ') center 53px no-repeat';
		}
}




/**
 * Write cookies
 */
function cookieWrite()
{
	var date = new Date();
	date.setTime( date.getTime() + (31536000000) );

	document.cookie = "jeka_tab=" + escape( currentTab ) + "; expires=" + date.toGMTString() + "; path=/; domain=.www.rkvvjeka.nl";
	
	cookieRead();
}


function cookieRead()
{
	var cky = document.cookie.split('; ');
	
	for(var i = 0; i < cky.length; i++)
	{
		var str = cky[i];

		// strip all whitespace
		while (str.charAt(0) == ' ')
		{
			str = str.substring(1, str.length);
		}

		// find the cookie
		if (str.indexOf('jeka_tab=') == 0)
		{
			var mck = unescape(str.substring(9, str.length));
			if (mck.length > 0) currentTab = mck;
		}
	}
}


