
function forumImgSize()
{
	$( 'TABLE.forumi DIV.posttext IMG.bbcode' ).load( function() {
		if( $( this ).outerWidth() > 695 )
		{
			$( this )
				.data( 'orig', $( this ).outerWidth() )
				.attr( 'width', 695 )
				.wrap( '<span class="imgcontainer"></span>' )
				.toggle( function() { imgBig( $( this ) ); }, function() { imgSml( $( this ) ); })
				.before( '<div class="imgtoolbar">Kuva on <strong>pienennetty</strong> jotta se mahtuis kokonaan n&auml;kyville. Kuvaa klikkaamalla n&auml;et sen originaalikokoisena.</div>' );
		}
	});
}

function imgBig( elm )
{
	elm.attr( 'width', elm.data( 'orig' ) );
}

function imgSml( elm )
{
	elm.attr( 'width', 695 );
}

function toggleNewPosts()
{
	if( $( 'DIV#newposts-wrap' ).attr( 'class' ) == 'closed' )
	{
		$( 'DIV#newposts-wrap' ).attr( 'class', 'open' );
		$( 'A#newposts-toggle' ).attr( 'class', 'open' );
		createCookie( 'gifunewposts', 'open', 365 );
	}
	else
	{
		$( 'DIV#newposts-wrap' ).attr( 'class', 'closed' );
		$( 'A#newposts-toggle' ).attr( 'class', 'closed' );
		createCookie( 'gifunewposts', 'closed', 365 );
	}
}

function createCookie( name, value, days )
{
	if( days )
	{
		var date = new Date();
		date.setTime( date.getTime() + ( days * 24 * 60 * 60 * 1000 ) );
		var expires = "; expires=" + date.toGMTString();
	}
	else
		var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie( name )
{
	var nameEQ = name + "=";
	var ca = document.cookie.split( ';' );

	for( var i = 0; i < ca.length; i++ )
	{
		var c = ca[ i ];
		while( c.charAt( 0 ) == ' ')
			c = c.substring( 1, c.length );

		if( c.indexOf( nameEQ ) == 0)
			return c.substring( nameEQ.length, c.length );
	}
	return null;
}

