function close_notice (key)
	{
	$("#notice_" + key).slideUp ('slow');
	}

function start_bbcode (target)
	{
	$(function () {
		$('.' + target).bbcodeeditor ({
			bold: $('.bbbtn-b'),
			italic: $('.bbbtn-i'),
			underline: $('.bbbtn-u'),
			link: $('.bbbtn-link'),
			quote: $('.bbbtn-quote'),
			code: $('.bbbtn-code'),
			image: $('.bbbtn-img'),
			usize: $('.bbbtn-increase'),
			dsize: $('.bbbtn-decrease'),
			nlist: $('.bbbtn-list-num'),
			blist: $('.bbbtn-list-bul'),
			litem: $('.bbbtn-list-item'),
			back: $('.bbbtn-undo'),
			forward: $('.bbbtn-redo'),
			back_disable: 'bbcode-button bbbtn-undo-off',
			forward_disable: 'bbcode-button bbbtn-redo-off',
			exit_warning: false,
			preview: $('.bbcode-preview')
			});
		});
	}

function slide_switch (slide_id)
	{
	/* Figure out what slide to display */
	if (slide_id)
		var next = $('#' + slide_id);
		else
		/* No slide was specified, get the next slide */
		if ($('.slide.current').next('.slide').length)
			var next = $('.slide.current').next('.slide');
			else
			var next = $('#banners .slide:first');
	
	/* Make sure we didn't click on the current slide */
	if ($(next).hasClass ("current")) { return false; }
	
	/* Fade out the current slide and fade in the new one */
	$("#banners .current").fadeOut ('slow').removeClass ("current");
	$(next).fadeIn ('slow').addClass ("current");
	
	/* Do the same for this buttons */
	$("#controls .active").removeClass ("active");
	$('#controls a[rel=' + $(next).attr ('id') + ']').parents("li").addClass ("active");
	}

function string_to_width (str, width, className)
	{
	function _escTag(s) { return s.replace ("<", "&lt;").replace (">", "&gt;"); }

	var span = document.createElement ("span");

	if (className) span.className = className;
	
	span.style.display		= 'inline';
	span.style.visibility	= 'hidden';
	span.style.padding		= '0px';
	
	document.body.appendChild (span);

	var result = _escTag (str);

	span.innerHTML = result;

	if (span.offsetWidth > width)
		{
		var posStart = 0, posMid, posEnd = str.length, posLength;
		
		while (posLength = (posEnd - posStart) >> 1)
			{
			posMid = posStart + posLength;
			span.innerHTML = _escTag (str.substring (0, posMid)) + '&hellip;';

			if ( span.offsetWidth > width ) posEnd = posMid; else posStart = posMid;
			}

		result = '<span title="'
			+ str.replace ("\"", "&quot;") + '">'
			+ _escTag (str.substring (0, posStart))
			+ '&hellip;<\/span>';
		}
	
	document.body.removeChild (span);

	return result;
	}

$(document).ready (function ()
	{
	setTimeout (function () { $('.fadeout').fadeOut (); }, 5000);
	setTimeout (function () { $('.slideup').slideUp (); }, 5000);
	
	reload_popups ();
	
	$('#navigation-search-input').focus (function () {
		$(this).css ('color', '#000000');
		
		if ($(this).val () == 'Search the Internet')
			$(this).val ('');
		});
	
	$('#navigation-search-input').blur (function () {
		$(this).css ('color', '#898989');
		
		if ($(this).val () == '')
			$(this).val ('Search the Internet');
		});
	
	if (jQuery().colorbox)
		{
		$("a.photobox").colorbox ({
			photo: 		true,
			maxWidth:	'85%',
			maxHeight:	'85%',
			opacity:	0.50
			});
		}
	
	$('div.block .edit-link').click (function (event) {
		event.preventDefault ();
		
		$(this).parents ('div.block').children ('div.edit').slideToggle ('fast');
		});
	
	$('div.block input[type=button]').click (function (event) {
		$(this).parents ('div.block').children ('div.edit').slideToggle ('fast');
		});
	});
