/* IE or NS? */
	function isIE()
	{
		return window.event;
	}

/* grab function */
	function grab( id )
	{
		return document.getElementById(id);
	}

/* ctrlbox toggler */
	var ctrlbox_open = null;
	function ctrlbox_toggle(object_id)
	{
		if( object_id == ctrlbox_open )
		{
			toggle_display( ctrlbox_open );
			ctrlbox_open = null;
			return null;
		}
		// else
		if( ctrlbox_open != null )
		{
			toggle_display( ctrlbox_open );
		}
		if( object_id != null )
		{
			ctrlbox_open = object_id;
			toggle_display( object_id );
		}
	}

	function ctrlbox_cancel()
	{
		if( ctrlbox_open != null )
		{
			toggle_display( ctrlbox_open );
			ctrlbox_open = null;
		}
	}

/* display toggler */
	function display_toggle(object_id, type)
	{
		type = (type?type:'block');
		var object = grab( object_id ).style;
		if( object.display == '' )
		{
			object.display = 'none';
		}
		else if( object.display == 'none' )
		{
			object.display = '';
		}
		return true;
	}
	
	function display_show(object_id, type)
	{
		type = (type?type:'block');
		grab( object_id ).style.display = type;
		return true;
	}
	
	function display_hide(object_id)
	{
		grab( object_id ).style.display = 'none';
		return true;
	}
	
/* toggle and set focus */
	function toggle_display_focus(object_id, type)
	{
		toggle_display(object_id, type);
		setfocus(object_id);
	}

/* focus */
	function setfocus( object_id )
	{
		grab(object_id).select();
		grab(object_id).focus();
	}

/* confirm */
	function gconfirm( msg, on_accept )
	{
		if( confirm(msg) )
		{
			window.location = on_accept;
		}
		else
		{
			return false;
		}
	}

/* str_random */
	function str_random( length )
	{
		// vars
		length = (length<1 ? 64 : length);
		feed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*-+=:;?0123456789';
		// build
		result = '';
		for( i=0; i < length; i++ )
			result = result + feed.substr( Math.floor(Math.random()*feed.length), 1 );
		// output
		return result;
	}

/* (array).in_array */
	in_array = function( find, array_data )
	{
		for( var m in array_data )
		{
			if( array_data[m] === find )
			{
				return true;
			}
		}
		return false;
	}

/* go_back */
	function go_back()
	{
		return history.go(-1);
	}

/* qpop */
	function qpop( url, id, width, height, xtra )
	{
		if( xtra != '' )
			xtra = ',' + xtra;
		return window.open(url, id, 'width=' + width + ',height=' + height + xtra );
	}

/* topflow */
	var topflow_cur = 0;
	var topflow_max = '';
	function topflow_init( interval )
	{
		// get list of images
		list = grab('flow').getElementsByTagName('img');
		// ensure list is more than one
		if( list.length <= 1 )
			return null;
		// set max and cur
		topflow_max = (list.length-1);
		topflow_cur = (list.length-1);
		// loop through to set an id and opacity to 100%;
		for( i=0; i < list.length; i++ )
		{
			list[i].id = '_topflow_'+i;
			list[i].style.zIndex = 200+i;
			setOpacity(100, '_topflow_'+i);
		}
		// start setTimeout
		setTimeout('topflow('+interval+')', interval);
	}
	
	function topflow( interval )
	{
		// timer
		var timer = 0;

		if( topflow_cur == 0 )
		{
		// fade into beginning
			for( i=0; i <= 100; i++)
			{
				setTimeout('setOpacity(' + i + ',\'_topflow_' +topflow_max+ '\')', (timer*12));
				timer++;
			}
			// reset opacities!
			for( i=0; i < topflow_max; i++)
				setTimeout('setOpacity(100, \'_topflow_'+i+'\')', (timer*12));
			// inc timer
			timer++;
			// reset current
			topflow_cur = topflow_max;
		}
		else
		{
		// fade current
			for( i=100; i >= 0; i--)
			{
				setTimeout('setOpacity(' + i + ',\'_topflow_' +topflow_cur+ '\')', (timer*12));
				timer++;
			}
			// step
			topflow_cur--;
		}

	// continue on in a loop
		setTimeout('topflow('+interval+')', interval+(timer*12));
	}

/* cross browser opacity changer */
	function setOpacity(opacity, object_id)
	{
		var obj = document.getElementById(object_id).style;
			obj.opacity = (opacity / 100);
			obj.MozOpacity = (opacity / 100);
			obj.KhtmlOpacity = (opacity / 100);
			obj.filter = 'alpha(opacity=' + opacity + ')';
	}

/* photoscroll */
	function photoscroll_start( id )
	{
		// vars
		var scrollbox = grab( id );
		var fullWidth = 0;
		// figure out some widths
		var children = scrollbox.childNodes;
		for( i=0; i < children.length; i++ )
			fullWidth+=children[i].offsetWidth;
		// don't bother if we don't have to!
		if( fullWidth <= scrollbox.offsetWidth )
			return false;
		// set whitespace: nowrap; overflow: hidden;
		scrollbox.style.whiteSpace = 'nowrap';
		scrollbox.style.overflow = 'hidden';
		// double up! yea, yea -- should use DOM, but innerHTML is so easy!
		scrollbox.innerHTML+= scrollbox.innerHTML;
		// loop stepper
		setInterval( 'photoscroll_step(\'' +id+ '\', ' +fullWidth+ ')', 60);
	}
	
	function photoscroll_step( id, fullWidth )
	{
		var scrollbox = grab( id );
		scrollbox.scrollLeft+=1;
		if( scrollbox.scrollLeft == fullWidth )
			scrollbox.scrollLeft = 0;
	}
	
	function set_lgphoto( file )
	{
		grab('largephoto').style.backgroundImage = 'url(\'/articleimg/'+file+'.jpg/420x315\')';
		grab('enlarger').href = '/articleimg/'+file+'.jpg/750x563';
	}

/* fullPhoto */
	function fullPhoto( file )
	{
		grab('fullPhotoin').src = file;
		grab('fullPhoto').style.display = 'block';
		grab('fullPhoto').style.width = document.documentElement.scrollWidth+'px';
		grab('fullPhoto').style.height = document.documentElement.scrollHeight+'px';
		return false;
	}
	
	function fullPhoto_hide()
	{
		grab('fullPhoto').style.display = 'none';
		grab('fullPhotoin').src = '/theme/blank.gif';
	}

/* bookmark */
	function bookmarkPage( )
	{
		var title = grab('ptitle').innerHTML;
		if( (navigator.appName == 'Microsoft Internet Explorer') && (parseInt(navigator.appVersion) >= 4) )
		{
			window.external.AddFavorite(window.location, title);
		}
		else if( navigator.appName == 'Netscape' )
		{
			window.sidebar.addPanel(title, window.location, '');
		}
		else
		{
			alert('Press CTRL-D in Netscape or CTRL-T in Opera to Bookmark this page.');
		}
	}

