

var LSStartup;
LSStartup = false;

var LSGlobals;
if ( LSGlobals ) { }
else
{
	LSGlobals = {};
	LSStartup = true;
}

function LSNotifySuccess()
{
	LSGlobals.lsTestState = true;
	if ( document.notifySuccess != null )
	{
		document.notifySuccess();
	}
}

function LSNotifyFailure()
{
	LSGlobals.lsTestState = false; 
	if ( document.notifyFailure != null )
	{
		document.notifyFailure();
	}
}

function LS_AddWhiteSpace( str )
{
    var outStr = '';
    var consec = 0;
    for( i = 0; i < str.length; i++ )
    {
        var ch = str.substr( i, 1 );
        if ( ch == ' ' || ch == '\r' || ch == '\n' )
            consec=0;
        else
            consec++;
        
        outStr += ch;
        if ( consec >= 35 ) {
            outStr += '<wbr></wbr>';
            consec = 0;
        }
    }
    return outStr;
}

function LSParseText( str, addBRs )
{
	str = str.toString();
	str = str.replace( /<\w+.*?>/ig, '' );
	str = str.replace( /<\/\w+.*?>/ig, '' );
	str = LS_AddWhiteSpace( str );
	str = str.replace( /\r/g, '' );
	str = str.replace( /\n\n/g, "\n" );
	if ( addBRs ) {
    	str = str.replace( /\n\n+/g, '<br/><br/>' );
    	str = str.replace( /\n/g, '<br/>' );
    } else {
    	str = str.replace( /\n\n+/g, ' ' );
    	str = str.replace( /\n/g, ' ' );
    }
	return str;
}

function LSGetPixels( str )
{
	str = str.toString();
	str = str.replace( /px/g, '' );
	return parseInt( str );
}

function LSEventManager()
{
	this.events = {};
}

LSEventManager.prototype.addEventListener = function( obj, message, callback )
{
	if ( this.events[obj] == null )
		this.events[obj] = {};
	if ( this.events[obj][message] == null )
		this.events[obj][message] = [];
	this.events[obj][message].push( callback );	
}

LSEventManager.prototype.sendMessage = function( obj, message, data )
{
	if ( this.events[obj] == null || this.events[obj][message] == null )
		return;

	var listeners = this.events[obj][message];
	for( var l in listeners )
		listeners[l]( data );
}

var LSEvent;
if ( LSEvent == null ) LSEvent = new LSEventManager();

function LSupdateSizes() { LSEvent.sendMessage( window, 'resize', null ); }
function LSonLoad() { LSGlobals.onLoadedFired = true; LSEvent.sendMessage( window, 'load', null ); }

if ( LSStartup )
{
	LSGlobals.baseScriptPath = "http://mycommunity.leveragesoftware.com/scripts/";
	LSGlobals.imagePath = "http://mycommunity.leveragesoftware.com/scripts/images/";
	LSGlobals.clientID = "mycommunity";
	LSGlobals.clientName = "mycommunity";
	LSGlobals.hostDomain = "leveragesoftware";
	LSGlobals.devid = '';
	LSGlobals.servicePath = "http://web.services.leveragesoftware.com/rest/";
	LSGlobals.scriptReader = new LSScriptReader();
	LSGlobals.activeCodeBuilder = null;
	LSGlobals.data = new LSDataHandler();
	LSGlobals.poweredBy = null;
    LSGlobals.onLoadedFired = false;
    LSGlobals.appUrl = 'http://mycommunity.leveragesoftware.com/';
    LSGlobals.uniqueID = 0;

	if ( window.addEventListener )
	{
		window.addEventListener( "resize", LSupdateSizes, false );
		window.addEventListener( "load", LSonLoad, false );
	}
	else
	{
		window.attachEvent( "onload", LSonLoad );
	}
}

function LSSetClientID( clientID )
{
	var origClient = LSGlobals.clientID;
	LSGlobals.clientID = clientID;
	LSGlobals.imagePath = LSGlobals.imagePath.replace( origClient, clientID ); 
	LSGlobals.servicePath = LSGlobals.servicePath.replace( origClient, clientID ); 
	LSGlobals.appUrl = LSGlobals.appUrl.replace( origClient, clientID ); 
	LSClearCache();
}

function LSClearCache()
{
	LSGlobals.data.clear();
}

function LSSetOpacity( element, opacity )
{
	element.style.MozOpacity = opacity / 100;
	element.style.filter = "alpha(opacity="+opacity+")";
}

function LSResizeImage( link, width, height )
{
	if ( width == null && height == null )
		return LS_FixLink(link);

	if ( link.match( /&w=/ ) == null )
		link += '&w='+((width==null)?height:width);
	if ( link.match( /&h=/ ) == null )
		link += '&h='+((height==null)?width:height);

	if ( width != null && height != null )
	{
		link = link.replace( /&h=(\d+)/, "&h="+height );
		link = link.replace( /&w=(\d+)/, "&w="+width );
	}
	else if ( width )
	{
		link = link.replace( /&h=(\d+)/, "&h="+width );
		link = link.replace( /&w=(\d+)/, "&w="+width );
	}
	else if ( height )
	{
		link = link.replace( /&h=(\d+)/, "&h="+height );
		link = link.replace( /&w=(\d+)/, "&w="+height );
	}
	
	return LS_FixLink(link);
}

function LS_FixLink(link)
{
    if ( window.location.href.match( /^https:/ ) )
      link = link.replace( /^http:/, "https:" );
    return link;
}

function LSLoadingGraphic()
{
}

LSLoadingGraphic.prototype.place = function( parent )
{
	this.loadingImage = document.createElement( 'img' );
	this.loadingImage.src = LS_FixLink(LSGlobals.imagePath + '/loading.gif');
	this.loadingImage.width = 16;
	this.loadingImage.border = '0';
	this.loadingImage.height = 16;
	this.loadingImage.style.visibility = 'visible';
	parent.appendChild( this.loadingImage );
}

LSLoadingGraphic.prototype.hide = function( )
{
	this.loadingImage.style.visibility = 'hidden';
	this.loadingImage.style.display = 'none';
}

LSLoadingGraphic.prototype.show = function( )
{
	this.loadingImage.style.visibility = 'visible';
	this.loadingImage.style.display = 'block';
}

function LSUIElement()
{
}

LSUIElement.prototype.setParent = function( parent )
{
	this.parent = parent;
}

LSUIElement.prototype.getParent = function()
{
	if ( this.parent ) return this.parent;
	return null;
}

LSUIElement.prototype.addChild = function( child )
{
	if ( this.children == null )
		this.children = [];
	this.children.push( child );
}

LSUIElement.prototype.getChildren = function()
{
	if ( this.children ) return this.children;
	return [];
}

LSUIElement.prototype.getDataSource = function()
{
	for( var c in this.children )
	{
		if ( this.children[c].getDataSource() != null )
			return this.children[c].getDataSource();
	}
	return null;
}

LSUIElement.prototype.buildJavascript = function()
{
	return "";
}

LSUIElement.prototype.getHTMLContainerID = function()
{
	return "";
}


function LSDataHandler()
{
	this.datablocks = {};
	this.callbacks = {};
	this.inPreload = false;
}

LSDataHandler.prototype.clear = function( url, callback )
{
	this.datablocks = {};
	this.callbacks = {};
	this.inPreload = false;
}

LSDataHandler.prototype.registerCallback = function( url, callback )
{
	this.callbacks[ this.trimUrl( url ) ] = callback;
}

LSDataHandler.prototype.unregisterCallback = function( url )
{
	delete this.callbacks[ this.trimUrl( url ) ];
}

LSDataHandler.prototype.trimUrl = function( url )
{
	url = url.replace( /^.*\//, "" );
	url = url.replace( /\&rand=(\d+)/, "" );
	url = url.replace( /\&format=js/, "" );
	return url;
}

LSDataHandler.prototype.startPreload = function()
{
	this.inPreload = true;
}

LSDataHandler.prototype.endPreload = function()
{
	this.inPreload = false;
}

LSDataHandler.prototype.add = function( url, data )
{
	var turl = this.trimUrl( url );

	this.datablocks[ turl ] = data;
	
	if ( this.inPreload == false )
	{
		if ( this.callbacks[ turl ] != null )
			this.callbacks[ turl ]( url, data );
	}
}

LSDataHandler.prototype.get = function( url )
{
	var turl = this.trimUrl( url );
	if ( this.datablocks[ turl ] == null )
		return null;
	return this.datablocks[ turl ];
}


LSBox.prototype = new LSUIElement();

function LSBox( parent, title, content, buttons )
{
	this.parent = parent;
	this.title = title;
	this.content = content;

	this.buttons = buttons;
	for( var b in this.buttons )
		this.buttons[b].setParent( this );
	
	this.addChild( this.content );

	var self = this;
	if ( this.parent != null )
		LS_onContent( function() { self.place( self.parent ); } );
}

LSBox.prototype.getHTMLContainerID = function()
{
	return this.parent.id;
}

LSBox.prototype.buildJavascript = function()
{
	var uid = this.getHTMLContainerID();

	var html = "";

	var buttonScript = [];
	for( var b in this.buttons )
	{
		buttonScript.push( this.buttons[b].buildJavascript() );
	}
	
	html += "var "+uid+"_content = "+this.content.buildJavascript()+";\n";
	html += "var "+uid+"_buttons = [ "+buttonScript.join(', ')+" ];\n";
	html += "new LSBox( document.getElementById('"+uid+"'), '"+this.title+"',\n";
	html += "  "+uid+"_content, "+uid+"_buttons );";
	return html;
}

LSBox.prototype.place = function( parent )
{
	if ( parent == null ) parent = document.body;
		
	parent.innerHTML = '';
	
	var elTable = document.createElement( 'table' );
	elTable.cellSpacing = 0;
	elTable.cellPadding = 0;
	elTable.width = '100%';
	elTable.className = 'componentTable';

	var elTBody = document.createElement( 'tbody' );
	elTable.appendChild( elTBody );

	var elTRTitleBox = document.createElement( 'tr' );
	elTBody.appendChild( elTRTitleBox );
	var elTDTitleBox = document.createElement( 'td' );
	elTRTitleBox.appendChild( elTDTitleBox );

	var elTableTitle = document.createElement( 'table' );
	elTableTitle.width = '100%';
	elTableTitle.cellPadding = 0;
	elTableTitle.cellSpacing = 0;
	elTableTitle.className = 'componentTableTitle';
	elTDTitleBox.appendChild( elTableTitle );

	var elTBodyTitle = document.createElement( 'tbody' );
	elTableTitle.appendChild( elTBodyTitle );
	
	var elTRTitle = document.createElement( 'tr' );
	elTBodyTitle.appendChild( elTRTitle );
	
	var elTDTitleText = document.createElement( 'td' );
	elTDTitleText.appendChild( document.createTextNode( this.title ) );
	elTDTitleText.className = 'ls-box-title';
	elTRTitle.appendChild( elTDTitleText );
	
	var elTDTitleButtons = document.createElement( 'td' );
	elTDTitleButtons.align = 'right';
	
	if ( this.buttons != null )
	{
		for( var b in this.buttons )
			this.buttons[b].place( elTDTitleButtons );
	}
	
	elTRTitle.appendChild( elTDTitleButtons );

	var elTRContentBox = document.createElement( 'tr' );
	elTBody.appendChild( elTRContentBox );

	var elTDContentBox = document.createElement( 'td' );
	elTDContentBox.className = 'ls-box-content';
	elTRContentBox.appendChild( elTDContentBox );
	
	if ( this.content != null )
		this.content.place( elTDContentBox );
	
	parent.appendChild( elTable );
}

function LSTableEntry( originalObject, groupName, link, subject, description )
{
	this.originalObject = originalObject;
	this.groupName = groupName;
	this.link = link;
	this.subject = subject;
	this.description = description;
}

LSTableEntry.prototype.getGroupName = function()
{
    return this.groupName;
}


function LSTableColumn( className )
{
	this.className = className;
}

LSTableColumn.prototype.getClassName = function( )
{
	return this.className;
}

function LSTableItemFormatter()
{
}

LSTableItemFormatter.prototype.render = function( parent, item, parentObj, column )
{
	var titleNode = document.createElement( 'div' );
	titleNode.className = 'ls-table-element-title';
	var titleLink = document.createElement( 'a' );
	titleLink.href = LS_FixLink(item.link);
	if ( parentObj != null && parentObj.anchorTarget != null )
		titleLink.target = parentObj.anchorTarget;
	titleLink.className = 'ls-table-element-link';
  	titleLink.innerHTML = LSParseText( item.subject, false );
	titleNode.appendChild( titleLink );
	parent.appendChild( titleNode );

	var nodeTable = document.createElement( 'table' );
	nodeTable.cellSpacing = '0';
	nodeTable.cellPadding = '0';
	nodeTable.width = '100%';

	var nodeTbody = document.createElement( 'tbody' );
	nodeTable.appendChild( nodeTbody );
	
	var nodeTr = document.createElement( 'tr' );
	nodeTbody.appendChild( nodeTr );
	
	var nodeTd = document.createElement( 'td' );
	nodeTr.appendChild( nodeTd );

	if ( item.originalObject.MediaUrl != null )
	{
		var nodeAnchor = document.createElement( 'a' );
		if ( parentObj != null && parentObj.anchorTarget != null )
			nodeAnchor.target = parentObj.anchorTarget;
		nodeAnchor.href = LS_FixLink(item.link);
		
		var nodeImg = document.createElement( 'img' );
		var imgSrc = item.originalObject.MediaUrl.replace( /[\n\r]/, "" );
		nodeImg.border = 0;
		nodeImg.src = LSResizeImage( imgSrc, 50, 50 );
		nodeImg.width = 50;
		nodeImg.galleryImg = false;
		nodeImg.className = 'ls-table-image';
		nodeAnchor.appendChild( nodeImg );
		nodeTd.appendChild( nodeAnchor );
	}
		
	if ( item.description != null && item.description.length > 0 )
	{
		var pNode = document.createElement( 'p' );
		pNode.className = 'ls-table-element-body';
		pNode.innerHTML = LSParseText( item.description, true );
		nodeTd.appendChild( pNode );
	}
		
	parent.appendChild( nodeTable );
}

LSTableItemFormatter.prototype.renderGroup = function( parent, item, parentObj )
{
    var groupName= item.getGroupName();
    groupName= (groupName == null || groupName.length == 0) ? '' : groupName[0];

	var groupNode = document.createElement( 'div' );
	groupNode.className = 'ls-table-element-group';
	groupNode.appendChild( document.createTextNode( groupName ) );
	parent.appendChild( groupNode );
}


LSTable.prototype = new LSUIElement();

function LSTable( reader, parent, width, height, containerID, formatter, columns, anchorTarget )
{
	this.containerID = containerID;
	this.parent = parent;
	this.anchorTarget = ( anchorTarget != null ) ? anchorTarget : null;
	this.formatter = ( formatter != null ) ? formatter : new LSTableItemFormatter();

	this.reader = reader;
	if ( this.reader != null )
	{
		var self = this;
		this.reader.callback = function( data )
		{
			self.entries = [];
			for( var i in data.items )
			{
				var item = data.items[i];
				if ( item != null )
				{
					self.add( new LSTableEntry(
						item,
						( item.GroupName != null ) ? item.GroupName : null,
						( item.link != null ) ? item.link : '',
						( item.title != null ) ? item.title : '',
						( item.description != null ) ? item.description : '' ) );
				}
			}
			self.update();
		}
	}
		
	this.entries = [];
	this.width = width;
	this.height = height;
	
	this.columns = ( columns == null ) ? [ new LSTableColumn() ] : columns;
	
	if ( this.parent )
		this.place( this.parent );
}

LSTable.prototype.buildJavascript = function()
{
	var html = "";
	html += "new LSTable( ";
	html += this.reader.buildJavascript();
	html += ", null, ";
	html += ( this.width != null ) ? "+this.width+" : "null";
	html += ', ';
	html += ( this.height != null ) ? "+this.height+" : "null";
	html += ', ';
	html += ( this.containerID != null ) ? "'"+this.containerID+"'" : "null";
	html += ")";
	return html;
}

LSTable.prototype.getDataSource = function()
{
	return this.reader;
}

LSTable.prototype.onClick = function( tdNode )
{
	LSEvent.sendMessage( this, 'click', tdNode.data );
}

LSTable.prototype.add = function( entry )
{
	this.entries.push( entry );
}

LSTable.prototype.update = function()
{
	this.loading.hide();
	
	while( this.tableBodyNode.childNodes.length > 0 )
		this.tableBodyNode.removeChild( this.tableBodyNode.childNodes.item( 0 ) );
	
	var self = this;
	
	for( var e in this.entries )
	{
	    var groupName= this.entries[e].getGroupName();
	    groupName= (groupName == null || groupName.length == 0) ? '' : groupName[0];
	
		if (groupName.length > 0)
		{
			var trNode = this.tableNode.insertRow( -1 );
			var tdNode = trNode.insertCell( -1 );
			tdNode.colSpan = this.columns.length;

			this.formatter.renderGroup( tdNode, this.entries[e], this );
		}

		var trNode = this.tableNode.insertRow( -1 );

		for( var c in this.columns )
		{
			var tdNode = trNode.insertCell( -1 );
			tdNode.data = this.entries[e];
			tdNode.className = this.columns[c].getClassName();
			tdNode.onclick = function() { self.onClick( this ); };
			this.formatter.render( tdNode, this.entries[e], this, this.columns[c] );
		}
	}

	LSNotifySuccess();
}

LSTable.prototype.place = function( parent )
{
	if ( parent == null )
		parent = document.body;
	else
		parent.innerHTML = '';

	this.container = document.createElement( 'div' );
	if ( this.containerID != null )
		this.container.id = this.containerID;
	if ( this.width ) this.container.style.width = this.width;
	if ( this.height ) this.container.style.height = this.height;
	this.container.className = 'ls-container';
	if ( this.width || this.height )
		this.container.style.overflow = 'auto';
	
	this.loading = new LSLoadingGraphic();
	this.loading.place( this.container );
	
	this.tableNode = document.createElement( 'table' );
	this.tableNode.cellSpacing = '0';
	this.tableNode.cellPadding = '0';
	this.tableNode.className = 'ls-table';
	this.tableNode.width = '100%';
	this.container.appendChild( this.tableNode );
	
	this.tableBodyNode = document.createElement( 'tbody' );
	this.tableNode.appendChild( this.tableBodyNode );
	
	parent.appendChild( this.container );

	this.reader.start();
} 



function LSScriptReader()
{
	this.read_queue = [];
	this.running = false;
	this.loaded = false;

	var self = this;
	if ( window.attachEvent )
		window.attachEvent( 'onload', function() { self.startLoading(); } );
	else
		window.addEventListener( 'load', function() { self.startLoading(); }, false );
}

LSScriptReader.prototype.add = function( url, callback, allowCache )
{
	var data = LSGlobals.data.get( unescape( url ) );
	if ( data != null && allowCache )
	{
		callback( data );
	}
	else
	{
		var self = this;
		LSGlobals.data.registerCallback( unescape( url ), function( url, data ) { self.onLoaded( unescape( url ), data ); } );
		this.read_queue.push( { url: url, callback: callback } );
		if ( this.loaded )
			this.getNext();
	}
}

LSScriptReader.prototype.startLoading = function()
{
	this.loaded = true;
	this.getNext();
}

LSScriptReader.prototype.onLoaded = function( url, data )
{
	this.read_queue[0].callback( data );
	this.read_queue.shift();

	this.running = false;
	this.getNext();
}

LSScriptReader.prototype.getNext = function()
{
	if ( this.read_queue.length > 0 && this.running == false )
	{
		var sObject = document.createElement( 'script' );
		sObject.src = LS_FixLink( this.read_queue[0].url );
		document.body.appendChild( sObject );
		
		this.running = true;
	}
}


function LSFeedReader()
{
	this.request = null;
	this.objectName = null;
	this.methodName = null;
	this.params = {};
	this.callback = null;
	this.params1 = null;
	this.params2 = null;
	this.allowCache = true;
}

LSFeedReader.prototype.buildJavascript = function()
{
	var html = "";
	html += "new "+this.typeName+"( ";
	
	var params1 = [];
	if ( this.params1 != null )
	{
		for( var p in this.params1 )
			params1.push( "'"+this.params1[p]+"'" );
	}
	if ( params1.length > 0 )
	{
		html += params1.join( ', ' );
		html += ', ';
	}
	
	var params2 = [];
	if ( this.params2 != null )
	{
		for( var p in this.params2 )
			params2.push( p+":'"+this.params2[p]+"'" );
	}
	html += '{ '+params2.join( ', ' )+'}';
	
	html += ", null )";
	return html;
}

LSFeedReader.prototype.setup = function( typeName, objectName, methodName, params1, params2, callback )
{
	this.typeName = typeName;
	this.objectName = objectName;
	this.methodName = methodName;
	this.params1 = params1;
	this.params2 = params2;
	
	this.params = {};
	if ( params1 != null )
		for( var p1 in params1 ) this.params[ p1 ] = params1[p1];
	if ( params2 != null )
		for( var p2 in params2 ) this.params[ p2 ] = params2[p2];

	this.callback = callback;

	if ( this.callback != null )
		this.start();
}

LSFeedReader.prototype.getRDFUrl = function() { return this.buildUrl() + '&format=rss2'; }

LSFeedReader.prototype.buildUrl = function()
{
	var url = LSGlobals.servicePath+'service.aspx?method='+this.objectName+'.'+this.methodName+'&client='+LSGlobals.clientID;
	for( var p1 in this.params )
	{	
		url += '&'+p1+'='+escape(this.params[p1]);
	}
	return url;
}

LSFeedReader.prototype.getJavascriptUrl = function()
{
	var nowDate = new Date();
	return this.buildUrl() + '&format=js&rand=' + nowDate.valueOf();
}

LSFeedReader.prototype.onJavascriptDataRecieve = function( data )
{
	this.callback( data );
}

LSFeedReader.prototype.startRequest = function( url )
{
	var self = this;
	LSGlobals.scriptReader.add( this.getJavascriptUrl(), function( data ) { self.onJavascriptDataRecieve( data ); }, this.allowCache );
}

LSFeedReader.prototype.start = function()
{
	this.startRequest( this.getJavascriptUrl() );
}

LSAllGetAll.prototype = new LSFeedReader();
function LSAllGetAll( params, callback ) { this.setup( 'LSAllGetAll', 'All', 'GetAll', {}, params, callback ); }

LSTagsGetAll.prototype = new LSFeedReader();
function LSTagsGetAll( params, callback ) { this.setup( 'LSTagsGetAll', 'Tags', 'GetAll', { }, params, callback ); }

LSChatsGet.prototype = new LSFeedReader();
function LSChatsGet( chatid, callback ) { this.setup( 'LSChatsGet', 'Chats', 'Get', { chatid: chatid }, {}, callback ); }

LSChatsGetAll.prototype = new LSFeedReader();
function LSChatsGetAll( params, callback ) { this.setup( 'LSChatsGetAll', 'Chats', 'GetAll', {}, params, callback ); }

LSBlogsGet.prototype = new LSFeedReader();
function LSBlogsGet( blogid, callback ) { this.setup( 'LSBlogsGet', 'Blogs', 'Get', { blogid: blogid }, {}, callback ); }

LSBlogsGetAll.prototype = new LSFeedReader();
function LSBlogsGetAll( params, callback ) { this.setup( 'LSBlogsGetAll', 'Blogs', 'GetAll', {}, params, callback ); }

LSBlogPostsGet.prototype = new LSFeedReader();
function LSBlogPostsGet( blogpostid, callback ) { this.setup( 'LSBlogPostsGet', 'BlogPosts', 'Get', { blogpostid: blogpostid }, {}, callback ); }

LSBlogPostsGetAll.prototype = new LSFeedReader();
function LSBlogPostsGetAll( params, callback ) { this.setup( 'LSBlogPostsGetAll', 'BlogPosts', 'GetAll', {}, params, callback ); }

LSCustomersGet.prototype = new LSFeedReader();
function LSCustomersGet( customerid, callback ) { this.setup( 'LSCustomersGet', 'Customers', 'Get', { customerid: customerid }, {}, callback ); }

LSCustomersGetAll.prototype = new LSFeedReader();
function LSCustomersGetAll( params, callback ) { this.setup( 'LSCustomersGetAll', 'Customers', 'GetAll', {}, params, callback ); }

LSCustomerFilesGet.prototype = new LSFeedReader();
function LSCustomerFilesGet( fileid, callback ) { this.setup( 'LSCustomerFilesGet', 'CustomerFiles', 'Get', { fileid: fileid }, {}, callback ); }

LSCustomerFilesGetAll.prototype = new LSFeedReader();
function LSCustomerFilesGetAll( params, callback ) { this.setup( 'LSCustomerFilesGetAll', 'CustomerFiles', 'GetAll', {}, params, callback ); }

LSGroupsGet.prototype = new LSFeedReader();
function LSGroupsGet( groupid, callback ) { this.setup( 'LSGroupsGet', 'Groups', 'Get', { groupid: groupid }, {}, callback ); }

LSGroupsGetAll.prototype = new LSFeedReader();
function LSGroupsGetAll( params, callback ) { this.setup( 'LSGroupsGetAll', 'Groups', 'GetAll', {}, params, callback ); }

LSGroupMeetingsGet.prototype = new LSFeedReader();
function LSGroupMeetingsGet( meetingid, callback ) { this.setup( 'LSGroupMeetingsGet', 'GroupMeetings', 'Get', { meetingid: meetingid }, {}, callback ); }

LSGroupMeetingsGetAll.prototype = new LSFeedReader();
function LSGroupMeetingsGetAll( params, callback ) { this.setup( 'LSGroupMeetingsGetAll', 'GroupMeetings', 'GetAll', {}, params, callback ); }

LSGroupFilesGet.prototype = new LSFeedReader();
function LSGroupFilesGet( fileid, callback ) { this.setup( 'LSGroupFilesGet', 'GroupFiles', 'Get', { fileid: fileid }, {}, callback ); }

LSGroupFilesGetAll.prototype = new LSFeedReader();
function LSGroupFilesGetAll( params, callback ) { this.setup( 'LSGroupFilesGetAll', 'GroupFiles', 'GetAll', {}, params, callback ); }

LSGroupDiscussionsGet.prototype = new LSFeedReader();
function LSGroupDiscussionsGet( discussionid, callback ) { this.setup( 'LSGroupDiscussionsGet', 'GroupDiscussions', 'Get', { discussionid: discussionid }, {}, callback ); }

LSGroupDiscussionsGetAll.prototype = new LSFeedReader();
function LSGroupDiscussionsGetAll( params, callback ) { this.setup( 'LSGroupDiscussionsGetAll', 'GroupDiscussions', 'GetAll', {}, params, callback ); }

LSSchedulesGet.prototype = new LSFeedReader();
function LSSchedulesGet( scheduleid, callback ) { this.setup( 'LSSchedulesGet', 'Schedules', 'Get', { scheduleid: scheduleid }, {}, callback ); }

LSSchedulesGetAll.prototype = new LSFeedReader();
function LSSchedulesGetAll( plan, params, callback ) { this.setup( 'LSSchedulesGetAll', 'Schedules', 'GetAll', {plan:plan}, params, callback ); }

LSRSSProxyGet.prototype = new LSFeedReader();
function LSRSSProxyGet( url, callback ) { this.setup( 'LSRSSProxyGet', 'RSSProxy', 'Get', { url: url }, {}, callback ); }

LSGroupDiscussionMessagesGet.prototype = new LSFeedReader();
function LSGroupDiscussionMessagesGet( messageid, callback ) { this.setup( 'LSGroupDiscussionMessagesGet', 'GroupDiscussionMessages', 'Get', { messageid: messageid }, {}, callback ); }

LSGroupDiscussionMessagesGetAll.prototype = new LSFeedReader();
function LSGroupDiscussionMessagesGetAll( params, callback ) { this.setup( 'LSGroupDiscussionMessagesGetAll', 'GroupDiscussionMessages', 'GetAll', { }, params, callback ); }

LSGroupDiscussionMessagesGetByName.prototype = new LSFeedReader();
function LSGroupDiscussionMessagesGetByName( group, discussion, callback ) { this.allowCache = false; this.setup( 'LSGroupDiscussionMessagesGetByName', 'GroupDiscussionMessages', 'GetByName', { group: group, discussion: discussion }, { count: 50 }, callback ); }

LSWikisGetAll.prototype = new LSFeedReader();
function LSWikisGetAll( params, callback ) { this.setup( 'LSWikisGetAll', 'Wikis', 'GetAll', { }, params, callback ); }

LSWikisGet.prototype = new LSFeedReader();
function LSWikisGet( wikiid, callback ) { this.setup( 'LSWikisGet', 'Wikis', 'Get', { wikiid:wikiid }, {}, callback ); }

LSWikiTopicsGetAll.prototype = new LSFeedReader();
function LSWikiTopicsGetAll( params, callback ) { this.setup( 'LSWikiTopicsGetAll', 'WikiTopics', 'GetAll', { }, params, callback ); }

LSWikiTopicsGet.prototype = new LSFeedReader();
function LSWikiTopicsGet( wikitopicid, callback ) { this.setup( 'LSWikiTopicsGet', 'WikiTopics', 'Get', { wikitopicid:wikitopicid }, {}, callback ); }

LSWikiEntriesGetAll.prototype = new LSFeedReader();
function LSWikiEntriesGetAll( params, callback ) { this.setup( 'LSWikiEntriesGetAll', 'WikiEntries', 'GetAll', { }, params, callback ); }

LSWikiEntriesGet.prototype = new LSFeedReader();
function LSWikiEntriesGet( wikientryid, callback ) { this.setup( 'LSWikiEntriesGet', 'WikiEntries', 'Get', { wikientryid:wikientryid }, {}, callback ); }

LSStatusUpdatesGet.prototype = new LSFeedReader();
function LSStatusUpdatesGet( statusupdateid, callback ) { this.setup( 'LSStatusUpdatesGet', 'StatusUpdates', 'Get', { statusupdateid: statusupdateid }, {}, callback ); }

LSStatusUpdatesGetAll.prototype = new LSFeedReader();
function LSStatusUpdatesGetAll( params, callback ) { this.setup( 'LSStatusUpdatesGetAll', 'StatusUpdates', 'GetAll', { }, params, callback ); }


LSHTMLBuilder.prototype = new LSUIElement();

function LSHTMLBuilder()
{
	this.popClass = null;
	this.codeTextArea = null;
	this.linkImage = null;
}

LSHTMLBuilder.prototype.buildJavascript = function()
{
	return "new LSHTMLBuilder()";
}

LSHTMLBuilder.prototype.onClick = function()
{
	if ( this.popClass )
	{
		if ( this.popClass.style.visibility == 'hidden' )
		{
			if ( LSGlobals.activeCodeBuilder != this && LSGlobals.activeCodeBuilder != null )
			{
				LSGlobals.activeCodeBuilder.onClose();
			}
			
			this.popClass.style.top = '50px';
			this.popClass.style.left = '30px';
			this.popClass.style.visibility = 'visible';
			this.popClass.style.cursor = 'pointer';
			
			LSGlobals.activeCodeBuilder = this;
		}
		else
		{
			this.popClass.style.visibility = 'hidden';
			LSGlobals.activeCodeBuilder = null;
		}
	}
}

LSHTMLBuilder.prototype.onClose = function()
{
	if ( this.popClass )
		this.popClass.style.visibility = 'hidden';
	LSGlobals.activeCodeBuilder = null;
}

LSHTMLBuilder.prototype.place = function( parent )
{
	if ( parent == null ) parent = document.body;
	
	var code = '';
	code += '<link href="http://'+LSGlobals.clientID+'.leveragesoftware.com/Scripts/Scripts.css" rel="stylesheet" type="text/css" />\n';
	code += '<link href="http://'+LSGlobals.clientID+'.leveragesoftware.com/custom/'+LSGlobals.clientID+'/default.css" rel="stylesheet" type="text/css" />\n';
	code += '<script src="http://'+LSGlobals.clientID+'.leveragesoftware.com/Scripts/Scripts.js.aspx?clientid='+LSGlobals.clientID+'">\n</script>\n';
	code += '<div id="'+this.getParent().getHTMLContainerID()+'"></div>\n';
	code += '<script>\n';
	code += this.getParent().buildJavascript()+"\n";
	code += '</script>\n';
	
	var self = this;
	
	var nodeAnchor = document.createElement( 'a' );
	nodeAnchor.onclick = function() { self.onClick() };
	
	this.linkImage = document.createElement( 'img' );
	this.linkImage.src = LS_FixLink(LSGlobals.imagePath + '/grabHTML.gif');
	this.linkImage.width = 20;
	this.linkImage.border = '0';
	this.linkImage.height = 20;
	this.linkImage.style.cursor = 'pointer';
	this.linkImage.className = 'grabHTML';
	nodeAnchor.appendChild( this.linkImage );
	
	parent.appendChild( nodeAnchor );
	
	this.popClass = document.createElement( 'div' );
	this.popClass.style.background = '#cccccc';
	this.popClass.style.textAlign = 'left';
	this.popClass.style.position = 'absolute';
	this.popClass.style.left = '0px';
	this.popClass.style.top = '0px';
	this.popClass.style.visibility = 'hidden';
	this.popClass.style.border = '1px solid #666666';
	this.popClass.style.padding = '5px';
	this.popClass.style.width = '700';
	this.popClass.style.zIndex = '2000';
	
	var nodeP = document.createElement( 'p' );
	nodeP.style.textAlign = 'left';
	nodeP.style.fontFamily = 'arial, verdana, sans-serif';
	nodeP.style.fontSize = '11px';
	nodeP.style.margin = '0px';
	nodeP.style.padding = '0px';
	nodeP.appendChild( document.createTextNode( 'Add this code to your HTML page:' ) );
	this.popClass.appendChild( nodeP );

	this.codeTextArea = document.createElement( 'textarea' );
	this.codeTextArea.style.fontFamily = 'Courier New, Courier';
	this.codeTextArea.style.fontSize = '12px';
	this.codeTextArea.style.border = '0px';
	this.codeTextArea.style.width = '100%';
	this.codeTextArea.style.background = '#eeeeee';
	this.codeTextArea.rows = 14;
	this.codeTextArea.value = code;
	this.popClass.appendChild( this.codeTextArea );

	var nodeCloseP = document.createElement( 'p' );
	nodeCloseP.style.textAlign = 'right';
	nodeCloseP.style.margin = '0px';
	nodeCloseP.style.padding = '0px';

	var nodeClose = document.createElement( 'a' );
	nodeClose.style.fontFamily = 'arial, verdana, sans-serif';
	nodeClose.style.fontSize = '11px';
	nodeClose.style.textDecoration = 'underline';
	nodeClose.onclick = function() { self.onClose() };
	nodeClose.appendChild( document.createTextNode( 'close' ) );
	nodeCloseP.appendChild( nodeClose );
	
	this.popClass.appendChild( nodeCloseP );
	
	parent.appendChild( this.popClass );
}

LSRSSLink.prototype = new LSUIElement();

function LSRSSLink()
{
}

LSRSSLink.prototype.buildJavascript = function()
{
	return "new LSRSSLink()";
}

LSRSSLink.prototype.place = function( parent )
{
	if ( parent == null ) parent = document.body;
	
	var nodeAnchor = document.createElement( 'a' );
	
	if ( this.getParent() || this.getParent().getDataSource() )
	{
		nodeAnchor.href = this.getParent().getDataSource().getRDFUrl();
	}
	
	var nodeImg = document.createElement( 'img' );
	nodeImg.src = LS_FixLink(LSGlobals.imagePath + '/grabRSS.gif');
	nodeImg.width = 20;
	nodeImg.border = '0';
	nodeImg.height = 20;
	nodeImg.style.cursor = 'pointer';
	nodeImg.className = 'grabRSS';
	nodeAnchor.appendChild( nodeImg );
	
	parent.appendChild( nodeAnchor );
}

function LSProfileObject()
{
	this.profiles = [];
	this.image = null;
	this.image_width = 0;
	this.image_height = 0;
	this.description = '';
}


LSProfileObject.prototype.setId = function( id ) { this.id = id; }
LSProfileObject.prototype.getId = function() { return this.id; }

LSProfileObject.prototype.setTitle = function( title ) { this.title = title; }
LSProfileObject.prototype.getTitle = function() { return this.title; }

LSProfileObject.prototype.setDescription = function( description ) { this.description = description; }
LSProfileObject.prototype.getDescription = function() { return this.description; }

LSProfileObject.prototype.setLink = function( link ) { this.link = link; }
LSProfileObject.prototype.getLink = function() { return this.link; }

LSProfileObject.prototype.setImage = function( image ) { this.image = image; }
LSProfileObject.prototype.getImage = function() { return this.image; }

LSProfileObject.prototype.setImageWidth = function( image_width ) { this.image_width = image_width; }
LSProfileObject.prototype.getImageWidth = function() { return this.image_width; }

LSProfileObject.prototype.setImageHeight = function( image_height ) { this.image_height = image_height; }
LSProfileObject.prototype.getImageHeight = function() { return this.image_height; }

LSProfileObject.prototype.addProfile = function( id, name, value )
{
	if ( this.profiles[ id ] == null )
		this.profiles[ id ] = { name: name, values: [] };
	this.profiles[ id ].values.push( value );
}

LSProfileObject.prototype.getProfileKeys = function()
{
	var ids = [];
	for( var p in this.profiles ) ids.push( p );
	return ids;
}

LSProfileObject.prototype.getProfileValues = function( id )
{
	return this.profiles[ id ].values;
}


function LSScrollerPopup( popup_offset_x, popup_offset_y, width )
{
	this.popup_offset_x = popup_offset_x;
	this.popup_offset_y = popup_offset_y;
	this.width = ( width != null ) ? width : 300;
	this.popup = null;
	this.content = null;
}

LSScrollerPopup.prototype.show = function( obj )
{
	var pos = this.getXYTotal( obj );

	if ( this.popup != null )
	{
		this.popup.style.left = ( pos.x - this.popup_offset_x )+'px';
		this.popup.style.top = ( pos.y + this.popup_offset_y )+'px';
		this.popup.style.visibility = 'visible';
	}
}

LSScrollerPopup.prototype.getXYTotal = function( obj )
{
	var x = 0;
	var y = 0;

	while( obj != null )
	{
		x += obj.offsetLeft;
		y += obj.offsetTop;
		obj = obj.offsetParent;
	}

	return { x:x, y:y };
}

LSScrollerPopup.prototype.hide = function()
{
	if ( this.popup != null )
	 	this.popup.style.visibility = 'hidden';
}

LSScrollerPopup.prototype.place = function( parent )
{
	if ( parent == null ) parent = document.body;
	
	var nodeTable = document.createElement( 'table' );
	nodeTable.className = 'scroll-popup';
	nodeTable.style.visibility = 'hidden';
	nodeTable.style.position = 'absolute';
	nodeTable.style.left = '0px';
	nodeTable.style.top = '0px';
	nodeTable.style.width = this.width+'px';
	nodeTable.cellSpacing = '0';
	nodeTable.cellPadding = '0';
	
	var nodeBody = document.createElement( 'tbody' );
	nodeTable.appendChild( nodeBody );
	
	var nodeTopTR = document.createElement( 'tr' );

	var nodeTopTD = document.createElement( 'td' );
	nodeTopTD.colSpan = '3';
	nodeTopTD.height = '15';
	nodeTopTD.style.backgroundImage = "url('"+LSGlobals.imagePath+"floatboxtop2.gif')";
	nodeTopTD.className = 'nodeTopTD';

	nodeTopTR.appendChild( nodeTopTD );
	nodeBody.appendChild( nodeTopTR );

	var nodeMiddleTR = document.createElement( 'tr' );
	nodeMiddleTR.bgColor = '#999999';
	
	var nodeMiddleLeftTD = document.createElement( 'td' );
	nodeMiddleLeftTD.width = '1';
	nodeMiddleLeftTD.nowrap = true;
	nodeMiddleTR.appendChild( nodeMiddleLeftTD );
	
	var nodeMiddleCenterTD = document.createElement( 'td' );
	nodeMiddleCenterTD.width = '237';
	nodeMiddleCenterTD.bgColor = 'white';
	nodeMiddleCenterTD.style.padding = '5px';
	nodeMiddleCenterTD.nowrap = true;
	var nodeContentDiv = document.createElement( 'div' );
	nodeContentDiv.style.fontFamily = 'arial, verdana, sans-serif';
	nodeContentDiv.style.fontSize = 'xx-small';
	this.content = nodeContentDiv;
	nodeMiddleCenterTD.appendChild( nodeContentDiv );
	nodeMiddleTR.appendChild( nodeMiddleCenterTD );
	
	var nodeMiddleRightTD = document.createElement( 'td' );
	nodeMiddleRightTD.width = '1';
	nodeMiddleRightTD.nowrap = true;
	nodeMiddleTR.appendChild( nodeMiddleRightTD );

	nodeBody.appendChild( nodeMiddleTR );

	var nodeBottomTR = document.createElement( 'tr' );
	var nodeBottomTD = document.createElement( 'td' );
	nodeBottomTD.colSpan = '3';
	nodeBottomTD.bgColor = '#999999';
	nodeBottomTD.height = '1';
	nodeBottomTR.appendChild( nodeBottomTD );
	nodeBody.appendChild( nodeBottomTR );

	this.popup = nodeTable;
	
	parent.appendChild( nodeTable );
}



function LSScrollerPanes( controller, height, divid )
{
	this.divid = divid;
	this.controller = controller;
	this.height = height;
	this.commands = [];
	this.objects = [];
	this.index = 0;
	this.movecount = 1;
	this.steps = 5;
	this.itemwidth = 150;
	this.width = 0;

	this.extra = null;
	this.divs = [];
	this.itemcount = 3;
	this.resizeTimer = null;

	var self = this;
	window.setInterval( function() { self.idle(); }, 20 );
}

LSScrollerPanes.prototype.onResize = function( parent )
{
	if ( this.resizeTimer != null )
		window.clearTimeout( this.resizeTimer );
	var self = this;
	this.resizeTimer = window.setTimeout( function() { self.handleResize(); }, 500 );
}

LSScrollerPanes.prototype.onLoad = function( parent )
{
	this.handleResize();
}

LSScrollerPanes.prototype.onClick = function( divObj )
{
	LSEvent.sendMessage( this, 'click', divObj.data );
}

LSScrollerPanes.prototype.handleResize = function()
{
	if ( this.elSizer == null || this.elSizer.offsetWidth == null )
		return;
		
	this.onUpdatingImages();
	
	this.resizeTimer = null;
	this.commands = [];

	var width = this.elSizer.offsetWidth;
	if ( width == 0 )
		width = this.elSizer.clientWidth - 55;
	width -= - 50;

	this.itemcount = Math.floor( width / this.itemwidth );
	if ( this.itemcount < 0 ) this.itemcount = 0;
	
	this.width = this.itemcount * this.itemwidth;
	
	if ( ( this.itemcount * this.itemwidth ) > 0 )
		this.elMiddleTD.width = ( this.itemcount * this.itemwidth );
	this.elMiddleDiv.style.width = ( this.itemcount * this.itemwidth )+'px';
	this.elMiddleDiv.innerHTML = '';
	this.divs = [];

	var self = this;
	for( var i = 0; i < this.itemcount + 1; i++ )
	{
		var nodeItemDiv = document.createElement( 'div' );

		nodeItemDiv.className = 'scroll-item';
		nodeItemDiv.style.fontSize = '11px';
		nodeItemDiv.style.color = '#666';
		nodeItemDiv.style.position = 'absolute';
		nodeItemDiv.style.width = this.itemwidth + 'px';
		nodeItemDiv.style.height = '130px';
		nodeItemDiv.style.overflow = 'hidden';
		nodeItemDiv.style.top = '0px';
		nodeItemDiv.style.left = (i*this.itemwidth)+'px';
		nodeItemDiv.style.textAlign = 'center';
		nodeItemDiv.onclick = function() { self.onClick( this ); }
		this.elMiddleDiv.appendChild( nodeItemDiv );
		
		this.divs.push( nodeItemDiv );
	}
	
	this.setPositions();
	this.update();
}

LSScrollerPanes.prototype.place = function( parent )
{
	if ( parent == null ) parent = document.body;

	var self = this;
	LSEvent.addEventListener( window, 'resize', function( evData ) { self.onResize( evData ); } );
	LSEvent.addEventListener( window, 'load', function( evData ) { self.onLoad( evData ); } );

	this.elSizer = document.createElement( 'div' );
	this.elSizer.style.height = '0px';
	this.elSizer.style.width = '100%';
	this.elSizer.style.fontSize = '0px';
	this.elSizer.onresize = function() { self.onResize(); }
	parent.appendChild( this.elSizer );
	
	this.elMainContainer = document.createElement( 'div' );
	this.elMainContainer.style.width = '100%';
	this.elMainContainer.style.textAlign = 'center';
	this.elMainContainer.id = this.divid;
	
	this.loading = new LSLoadingGraphic();
	this.loading.place( this.elMainContainer );

	var elMainTable = document.createElement( 'table' );
	elMainTable.cellSpacing = '0';
	elMainTable.cellPadding = '0';
	elMainTable.className = 'scroll';
	this.elMainContainer.appendChild( elMainTable );

	var nodeTableBody = document.createElement( 'tbody' );
	elMainTable.appendChild( nodeTableBody );

	var nodeTR = document.createElement( 'tr' );
	
	var nodeLeftTD = document.createElement( 'td' );
	nodeLeftTD.valign = 'middle';
	nodeLeftTD.align = 'center';
	nodeLeftTD.width = '22';
	nodeLeftTD.height = '110';
	nodeLeftTD.className = 'scroll-left';

	var nodeLeftImage = document.createElement( 'img' );
	nodeLeftImage.src = LS_FixLink(LSGlobals.imagePath+'arrowLeft.gif');
	nodeLeftImage.width = '22';
	nodeLeftImage.height = '22';
	nodeLeftImage.style.visibility = 'hidden';

	var cnt1 = this.controller;
	nodeLeftImage.onclick = function() { cnt1.scrollLeft(); };

	nodeLeftTD.appendChild( nodeLeftImage );
	this.leftbutton = nodeLeftImage;
	nodeTR.appendChild( nodeLeftTD );

	this.elMiddleTD = document.createElement( 'td' );
	this.elMiddleTD.className = 'scroll-middle';

	this.elMiddleDiv = document.createElement( 'div' );
	this.elMiddleDiv.style.position = 'relative';
	this.elMiddleDiv.style.height = '120px';
	this.elMiddleDiv.style.overflow = 'hidden';
	this.elMiddleTD.appendChild( this.elMiddleDiv );

	nodeTR.appendChild( this.elMiddleTD );

	var nodeRightTD = document.createElement( 'td' );
	nodeRightTD.valign = 'middle';
	nodeRightTD.align = 'center';
	nodeRightTD.width = '22';
	nodeRightTD.height = '110';
	nodeRightTD.className = 'scroll-right';
	
	var nodeRightImage = document.createElement( 'img' );
	nodeRightImage.src = LS_FixLink(LSGlobals.imagePath+'arrowRight.gif');
	nodeRightImage.width = '22';
	nodeRightImage.height = '22';
	nodeRightImage.style.visibility = 'hidden';

	var cnt2 = this.controller;
	nodeRightImage.onclick = function() { cnt2.scrollRight(); };

	nodeRightTD.appendChild( nodeRightImage );
	this.rightbutton = nodeRightImage;
	
	nodeTR.appendChild( nodeRightTD );
	
	nodeTableBody.appendChild( nodeTR );

	parent.appendChild( this.elMainContainer );

	this.handleResize();
}

LSScrollerPanes.prototype.renderInto = function( parent, obj ) { }

LSScrollerPanes.prototype.addObject = function( obj ) { this.objects.push( obj ); }

LSScrollerPanes.prototype.onUpdatingImages = function() { }

LSScrollerPanes.prototype.clear = function()
{
	this.onUpdatingImages();
	
	this.index = 0;
	this.objects = [];
	for( var i in this.divs )
		this.divs[i].style.visibility = 'hidden';
	this.leftbutton.style.visibility = 'hidden';
	this.rightbutton.style.visibility = 'hidden';
	
	this.setPositions();
}

LSScrollerPanes.prototype.onDoneLoading = function()
{
	this.loading.hide();
}

LSScrollerPanes.prototype.setPositions = function()
{
	var startx = this.itemwidth * -1;
	for( var d in this.divs )
	{
		this.divs[d].style.left = startx+'px';
		startx += this.itemwidth;
	}
	this.extra = this.divs[0];
}

LSScrollerPanes.prototype.scroll = function( direction )
{
	this.movecount = Math.floor( this.itemcount / 2 );
	if( this.movecount <= 0 )
		this.movecount = 1;
	
	this.onUpdatingImages();
	for( var i = 0; i < this.movecount; i++ )
	{
		this.commands.push( { task: 'move_extra', direction: direction } );
		for( var s = 0; s < this.steps; s++ )
		{
			this.commands.push( { task: 'shift',
				amount: direction * ( this.itemwidth / this.steps ) * -1 } );
		}
		this.commands.push( { task: 'change_index', direction: direction } );
	}
}

LSScrollerPanes.prototype.idle = function()
{
	if ( this.commands.length <= 0 )
		return;

	this.onUpdatingImages();

	var f = this.commands.shift();
	if ( f.task == 'move_extra' ) this.moveExtra( f.direction );
	if ( f.task == 'shift' )
	{
		for( var oi in this.divs )
			this.move( this.divs[ oi ], f.amount );
	}
	if ( f.task == 'change_index' ) this.changeIndex( f.direction );
}

LSScrollerPanes.prototype.move = function( obj, dx )
{
	var x = parseInt( obj.style.left.replace( 'px', '' ) ) + dx;
	var w = parseInt( obj.style.width.replace( 'px', '' ) );
	obj.style.left = x+'px';
	obj.style.visibility = 'visible';
}

LSScrollerPanes.prototype.moveExtra = function( direction )
{
	if ( this.extra == null )
		return;
		
	this.extra.style.left = ( direction == 1 ) ? ( this.itemwidth * this.itemcount )+'px' : '-'+this.itemwidth+'px';
	this.extra.style.top = '0px';
	this.extra.style.visibility = 'hidden';

	var ci = this.index + ( ( direction == -1 ) ? -1 : this.itemcount );
	if ( ci >= this.objects.length ) ci -= this.objects.length;
	if ( ci < 0 ) ci = this.objects.length + ci;

	this.extra.data = this.objects[ ci ];
	this.renderInto( this.extra, this.objects[ ci ] );
	
	var positions = [];
	for( var d in this.divs )
		positions.push( this.divs[d].style.left );
}

LSScrollerPanes.prototype.changeIndex = function( direction )
{
	this.index += direction;

	if ( this.index < 0 ) this.index = this.objects.length - 1;
	if ( this.index >= this.objects.length ) this.index = 0;

	for( var i = 0; i < this.divs.length; i++ )
	{
		if ( this.divs[i].style.left == '-'+this.itemwidth+'px' ||
 		     this.divs[i].style.left == this.width+'px' )
			this.extra = this.divs[i];
	}
}

LSScrollerPanes.prototype.update = function()
{
	var ci = this.index;

	this.leftbutton.style.visibility = ( this.objects.length > this.itemcount ) ? 'visible' :  'hidden';
	this.rightbutton.style.visibility = ( this.objects.length > this.itemcount ) ? 'visible' : 'hidden';

	var c = 0;
	for( var i = 0; i < this.divs.length; i++ )
	{
		if ( this.divs[ i ] != this.extra )
		{
			if ( c >= this.objects.length ) break;

			this.divs[ i ].data = this.objects[ ci ];
			this.renderInto( this.divs[ i ], this.objects[ ci ] );
			this.move( this.divs[ i ], 0 );

			ci++;
			if ( ci >= this.objects.length ) ci -= this.objects.length;
			c++;
		}
	}
}

function LSScrollerItemFormatter()
{
}

LSScrollerItemFormatter.prototype.render = function( parent, item, parentObj )
{
	parent.innerHTML = '';
	
	var elDiv = document.createElement( 'div' );
	elDiv.style.width = '100%';
	elDiv.style.textAlign = 'center';

	var elTable = document.createElement( 'table' );
	elTable.cellSpacing = 0;
	elTable.cellPadding = 0;
	elDiv.appendChild( elTable );
	
	var elTBody = document.createElement( 'tbody' );
	elTable.appendChild( elTBody );

	var elTR = document.createElement( 'tr' );
	elTBody.appendChild( elTR );

	var elTD = document.createElement( 'td' );
	elTR.appendChild( elTD );

	var elP = document.createElement( 'p' );
	elP.className = 'scroll-item-name';
	elTD.appendChild( elP );

	if ( item.getImage() != null )
	{
		var self = this;
		var currentObj = item;
		
		var elAnchor = document.createElement( 'a' );
		if ( parentObj != null && parentObj.anchorTarget != null )
			elAnchor.target = parentObj.anchorTarget;
		elAnchor.href = LS_FixLink(item.getLink());
		elAnchor.style.styleFloat = 'left';
		elAnchor.style.padding = '2px';

		var elImg = document.createElement( 'img' );
		var imgSrc = item.getImage().replace( /[\n\r]/, "" );
		elImg.border = 0;
		elImg.src = LSResizeImage( imgSrc, Math.round( item.getImageWidth() * 0.5 ), Math.round( item.getImageHeight() * 0.5 ) );
		elImg.width = Math.round( item.getImageWidth() * 0.5 );
		elImg.height = Math.round( item.getImageHeight() * 0.5 );
		elAnchor.onmouseover = function() { parentObj.rollover( this, currentObj.getId() ); };
		elAnchor.onmouseout = function() { parentObj.rollout(); };
		
		elAnchor.appendChild( elImg );
		elP.appendChild( elAnchor );
	}

	var elAnchorPerson = document.createElement( 'a' );
	if ( parentObj != null && parentObj.anchorTarget != null )
		elAnchorPerson.target = parentObj.anchorTarget;
	elAnchorPerson.className = 'scroll-item-link';
	elAnchorPerson.href = LS_FixLink(item.getLink());
	elAnchorPerson.style.fontWeight = 'bold';
	var title = item.getTitle();
	if ( title != null && title.length > 10 )
		title = title.substring( 0, 10 ) + '...';
	elAnchorPerson.appendChild( document.createTextNode( title ) );
	
	elP.appendChild( elAnchorPerson );

	var desc = item.getDescription();
	if ( desc != null && desc.length > 100 )
		desc = desc.substring( 0, 100 ).replace( /\s[^\s]*?$/, '...' );

	var elPDescription = document.createElement( 'p' );
	elPDescription.className = 'scroll-item-description';
	elPDescription.appendChild( document.createTextNode( desc ) );
	elTD.appendChild( elPDescription );

	parent.appendChild( elDiv );
}

function LSScrollerPopupFormatter()
{
}

LSScrollerPopupFormatter.prototype.render = function( parent, item, parentObj )
{
	var elTable = document.createElement( 'table' );
	var elTBody = document.createElement( 'tbody' );
	elTable.appendChild( elTBody );
	
	var elTR1 = document.createElement( 'tr' );

	var elTDTitle1 = document.createElement( 'td' );
	elTDTitle1.appendChild( document.createTextNode( 'ID' ) );
	elTDTitle1.className = 'ls-popup-info-header';
	elTR1.appendChild( elTDTitle1 );

	var elTDTitle1 = document.createElement( 'td' );
	elTDTitle1.appendChild( document.createTextNode( item.getTitle() ) );
	elTDTitle1.className = 'ls-popup-info-item';
	elTR1.appendChild( elTDTitle1 );

	elTBody.appendChild( elTR1 );

	var pids = item.getProfileKeys();
	for( var pid in pids )
	{
		var values = item.getProfileValues( pids[ pid ] );
		var valueStr = this.renderValue( values );
		if ( valueStr != null && valueStr.length > 100 )
			valueStr = valueStr.substring( 0, 100 ).replace( /\s[^\s]*?$/, '...' );

		var elTR2 = document.createElement( 'tr' );

		var elTDTitle2 = document.createElement( 'td' );
		elTDTitle2.appendChild( document.createTextNode( pids[ pid ] ) );
		elTDTitle2.className = 'popup-info-header';
		elTR2.appendChild( elTDTitle2 );

		var elTDTitle2 = document.createElement( 'td' );
		elTDTitle2.appendChild( document.createTextNode( valueStr ) );
		elTDTitle2.className = 'popup-info-item';
		elTR2.appendChild( elTDTitle2 );

		elTBody.appendChild( elTR2 );
	}

	parent.appendChild( elTable );
}

LSScrollerPopupFormatter.prototype.renderValue = function( values )
{
	return values.join( ', ' );
}


LSScroller.prototype = new LSUIElement();

function LSScroller( dataSource, parent, divid, itemFormatter, popupFormatter, anchorTarget )
{
	var self = this;
	this.dataSource = dataSource;
	this.anchorTarget = ( anchorTarget != null ) ? anchorTarget : null;
	this.dataSource.callback = function( data ) { self.setRecords( data.items ); }

	this.itemFormatter = ( itemFormatter != null ) ? itemFormatter : new LSScrollerItemFormatter();
	this.popupFormatter = ( popupFormatter != null ) ? popupFormatter : new LSScrollerPopupFormatter();
	
	this.parent = parent;
	
	this.width = 450;
	this.height = 155;
	this.popup_offset_x = 10;
	this.popup_offset_y = 30;
	this.divid = divid;

	this.po_index = {};
	
	if ( this.parent != null )
	{
		var thisScroller = this;
		LS_onContent( function() { thisScroller.place( thisScroller.parent ); } );
	}
}

LSScroller.prototype.buildJavascript = function()
{
	var html = "";
	html += "new LSScroller( \n";
	html += "  "+this.dataSource.buildJavascript()+",\n";
	html += "  null, ";
	html += ( this.divid != null ) ? "'"+this.divid+"'" : "null";
	html += ")";
	return html;
}

LSScroller.prototype.getDataSource = function()
{
	return this.dataSource;
}

LSScroller.prototype.scrollLeft = function( )
{
	this.scroller.scroll( -1 );
}

LSScroller.prototype.scrollRight = function( )
{
	this.scroller.scroll( 1 );
}

LSScroller.prototype.scroll = function( dir )
{
	this.scroller.scroll( dir );
}

LSScroller.prototype.onUpdatingImages = function()
{
	if ( this.controller.scrollerPopup == null ) return;
	this.controller.scrollerPopup.hide();
}

LSScroller.prototype.rollover = function( obj, cid )
{
	this.scrollerPopup.content.innerHTML = '';
	this.popupFormatter.render( this.scrollerPopup.content, this.getObject( cid ), this );
	this.scrollerPopup.show( obj );
}

LSScroller.prototype.rollout = function()
{
	if ( this.scrollerPopup == null ) return;
	this.scrollerPopup.hide();
}

LSScroller.prototype.setRecords = function( records )
{
	this.po_index = {};
	this.scroller.clear();

	for( var r in records )
	{
		var nr = new LSProfileObject();
		
		nr.setId( records[r].ID );
		nr.setTitle( records[r].title );
		nr.setDescription( records[r].description );
		nr.setLink( records[r].link );
		nr.setImage( records[r].MediaUrl );
		nr.setImageWidth( records[r].MediaWidth );
		nr.setImageHeight( records[r].MediaHeight );
		for( var i in records[r].ProfileItem )
		{
			for( var pk in records[r].ProfileItem[i] )
			{
				nr.addProfile( pk, pk, records[r].ProfileItem[i][pk] );
			}
		}
		
		this.po_index[ nr.getId() ] = nr;
		this.scroller.addObject( nr );
	}

	this.scroller.onDoneLoading();
	this.scroller.update();

	LSNotifySuccess();
}

LSScroller.prototype.getObject = function( cid )
{
	return this.po_index[ cid ];
}

LSScroller.prototype.udpateSizing = function()
{
	this.scroller.handleResize();
}

LSScroller.prototype.place = function( parent )
{
	var self = this;

	this.scroller = new LSScrollerPanes( this, this.height, this.divid );
	this.scroller.controller = this;
	this.scroller.renderInto = function( parent, obj ) { self.itemFormatter.render( parent, obj, self ); };
	this.scroller.onUpdatingImages = this.onUpdatingImages;
	this.scroller.place( parent );

	this.scrollerPopup = new LSScrollerPopup( this.popup_offset_x, this.popup_offset_y );
	this.scrollerPopup.place( document.body );

	this.dataSource.start();
}

function LSBusinessCardRenderer()
{
}

LSBusinessCardRenderer.prototype.render = function( parent, record, profileMap, parentObj )
{
	if ( record.MediaUrl != null )
	{
		var elImageDiv = document.createElement( 'div' );
		elImageDiv.className = 'business-card-image';
		
		var elImageAnchor = document.createElement( 'a' );
		if ( parentObj != null && parentObj.anchorTarget != null )
			elImageAnchor.target = parentObj.anchorTarget;
		elImageAnchor.href = LS_FixLink(record.link);

		var width = record.MediaWidth * 0.4;
		var height = record.MediaHeight * 0.4;
		
		var elImage = document.createElement( 'img' );
		elImage.src = LSResizeImage( record.MediaUrl, width, height );
		elImage.width = width;
		elImage.height = height;
		elImage.style.width = width+'px';
		elImage.style.height = height+'px';
		elImage.border = '0';
		elImageDiv.appendChild( elImage );

		elImageAnchor.appendChild( elImageDiv );
		parent.appendChild( elImageAnchor );
	}
	
	var elPopup = document.createElement( 'div' );
	elPopup.className = 'business-card-popup';
	var builder = new LSHTMLBuilder();
	builder.setParent( parentObj );
	builder.place( elPopup );
	parent.appendChild( elPopup );

	var elName = document.createElement( 'div' );
	elName.className = 'business-card-id';
	var elNameAnchor = document.createElement( 'a' );
	if ( parentObj != null && parentObj.anchorTarget != null )
		elNameAnchor.target = parentObj.anchorTarget;
	elNameAnchor.href = LS_FixLink(record.link);
	elNameAnchor.appendChild( document.createTextNode( record.MemberName ) );
	elName.appendChild( elNameAnchor );
	parent.appendChild( elName );

	var desc = record.description;
	if ( desc != null && desc.length > 200 )
		desc = desc.substring( 0, 200 ).replace( /\s[^\s]*?$/, '...' );

	var elDescription = document.createElement( 'div' );
	elDescription.className = 'business-card-description';
	elDescription.appendChild( document.createTextNode( desc ) );
	parent.appendChild( elDescription );
	
	for( var pk in profileMap ) { profileMap[pk] = { title: profileMap[pk], values: [] }; }
	for( var p in record.ProfileItem )
	{
		for( var pk in record.ProfileItem[p] )
		{
			var pv = record.ProfileItem[p][pk];
			profileMap[pk].values.push( pv );
		}
	}
	
	var elProfileTable = document.createElement( 'table' );
	elProfileTable.className = 'business-card-profile-table';
	elProfileTable.cellSpacing = '0';
	elProfileTable.cellPadding = '0';
	parent.appendChild( elProfileTable );
	
	for( var pk in profileMap )
	{
		var elTR = elProfileTable.insertRow( -1 );
		var elTitleTD = elTR.insertCell( -1 );
		elTitleTD.className = 'business-card-profile-title';
		elTitleTD.appendChild( document.createTextNode( profileMap[pk].title ) );

		var elValuesTD = elTR.insertCell( -1 );
		elValuesTD.className = 'business-card-profile-values';
		elValuesTD.appendChild( document.createTextNode( profileMap[pk].values.join(', ') ) );
	}
	
	var elJoin = document.createElement( 'a' );
	if ( parentObj != null && parentObj.anchorTarget != null )
		elJoin.target = parentObj.anchorTarget;
	elJoin.className = 'business-card-join';
	elJoin.href = LS_FixLink(record.link);
	elJoin.appendChild( document.createTextNode( 'Come join me @ '+LSGlobals.clientID+'!' ) );
	parent.appendChild( elJoin );
	
	var elPoweredByLeverage = document.createElement( 'img' );
	elPoweredByLeverage.className = 'business-card-leverage';
	elPoweredByLeverage.alt = 'Powered by Leverage Software';
	elPoweredByLeverage.src = LS_FixLink(LSGlobals.imagePath+'/levlabs.gif');
	parent.appendChild( elPoweredByLeverage );
}

function LSBusinessCard( dataSource, parent, styleName, divid, render, anchorTarget )
{
	var self = this;
	
	this.anchorTarget = ( anchorTarget != null ) ? anchorTarget : null;
	this.link = null;
	this.parent = parent;
	this.divid = divid;
	this.styleName = ( styleName == null ) ? 'badge-small' : styleName;
	this.render = ( render == null ) ? new LSBusinessCardRenderer() : render;
	this.dataSource = dataSource;
	this.dataSource.callback = function( data ) { self.setRecord( data ); }
	if ( parent )
		this.place( parent );
}

LSBusinessCard.prototype = new LSUIElement();

LSBusinessCard.prototype.buildJavascript = function()
{
	var html = "";
	html += "new LSBusinessCard( ";
	html += this.dataSource.buildJavascript();
	html += ", "+(( this.parent != null ) ? "document.getElementById( '"+this.parent.id+"' ) " : "null" );
	html += ", "+(( this.styleName != null ) ? "'"+this.styleName+"'" : "null" );
	html += ", ";
	html += ", "+(( this.divid != null ) ? "'"+this.divid+"'" : "null" );
	html += " )";
	return html;
}

LSBusinessCard.prototype.getDataSource = function()
{
	return this.dataSource;
}

LSBusinessCard.prototype.getHTMLContainerID = function()
{
	return this.parent.id;
}

LSBusinessCard.prototype.setRecord = function( data )
{
	this.loading.hide();
	this.container.innerHTML = '';
	
	var profileMap = {};
	for( var p in data.ProfileName )
	{
		for( pk in data.ProfileName[p] )
			profileMap[ pk ] = data.ProfileName[p][pk];
	}

	this.link = data.items[0].link;
	
	this.render.render( this.container, data.items[0], profileMap, this );
}

LSBusinessCard.prototype.onClick = function( )
{
	if ( this.link != null )
		window.location = this.link;
}

LSBusinessCard.prototype.place = function( parent )
{
	if ( parent == null )
		parent = document.body;
	else
		parent.innerHTML = '';

	var self = this;
		
	var elCard = document.createElement( 'div' );
	if ( this.styleName != null )
		elCard.className = this.styleName;
	elCard.onclick = function() { self.onClick(); }
	parent.appendChild( elCard );

	this.container = document.createElement( 'div' );
	if ( this.styleName != null )
	this.container.className = 'business-card-container';
	if ( this.divid != null )
		this.container.id = this.divid;
		
	this.loading = new LSLoadingGraphic();
	this.loading.place( this.container );
	
	elCard.appendChild( this.container );

	this.dataSource.start();
}


function LSSlideShow( dataSource, parent, divid, width, height, anchorTarget )
{
	var self = this;
	
	this.anchorTarget = ( anchorTarget != null ) ? anchorTarget : null;
	this.width = width;
	this.height = height;
	this.divid = divid;
	this.dataSource = dataSource;
	this.dataSource.callback = function( data ) { self.setRecord( data.items ); }
	this.parent = parent;
	this.items = [];
	this.elImages = [];
	this.elImageAnchors = [];
	this.currentIndex = -1;
	this.opacity = 0;
	if ( parent )
		LS_onContent( function() { self.place( parent ) } );
}

LSSlideShow.prototype = new LSUIElement();

LSSlideShow.prototype.getDataSource = function()
{
	return this.dataSource;
}

LSSlideShow.prototype.buildJavascript = function()
{
	var html = "";
	html += "new LSSlideShow( ";
	html += this.dataSource.buildJavascript();
	html += ", "+(( this.parent != null ) ? "document.getElementById( '"+this.parent.id+"' ) " : "null" );
	html += ", "+(( this.divid != null ) ? "'"+this.divid+"'" : "null" );
	html += " )";
	return html;
}

LSSlideShow.prototype.getHTMLContainerID = function()
{
	return this.parent.id;
}

LSSlideShow.prototype.setRecord = function( data )
{
	this.loading.hide();

	this.items = data;
	for( var i in this.items )
	{
		this.elImageAnchors[i] = document.createElement( 'a' );
		this.elImageAnchors[i].href = LS_FixLink(this.items[i].link);
		if ( this.anchorTarget != null )
			this.elImageAnchors[i].target = this.anchorTarget;

		this.elImages[i] = document.createElement( 'img' );
		this.elImages[i].border = '0';
		this.elImages[i].galleryImg = false;
		this.elImages[i].src = LSResizeImage( this.items[i].MediaUrl, this.width, this.height );
		this.elImages[i].style.display = 'none';
		this.elImages[i].style.visibility = 'hidden';
		this.elImages[i].className = 'slideshow-image';

		this.elImageAnchors[i].appendChild( this.elImages[i] );
		this.container.appendChild( this.elImageAnchors[i] );
	}
	
	this.currentIndex = 0;
	this.nextSlide();
}

LSSlideShow.prototype.fadeIn = function( data )
{
	this.opacity += 10;
	LSSetOpacity( this.elImages[ this.currentIndex ], this.opacity );
	
	var self = this;
	if ( this.opacity < 100 )
		window.setTimeout( function() { self.fadeIn(); }, 100 );
	else
		window.setTimeout( function() { self.fadeOut(); }, 2000 );
}

LSSlideShow.prototype.fadeOut = function( data )
{
	this.opacity -= 10;
	LSSetOpacity( this.elImages[ this.currentIndex ], this.opacity );

	var self = this;
	if ( this.opacity > 0 )
		window.setTimeout( function() { self.fadeOut(); }, 100 );
	else
		window.setTimeout( function() { self.nextSlide(); }, 20 );
}

LSSlideShow.prototype.nextSlide = function( data )
{
	this.loading.hide();

	if( this.currentIndex >= 0 )
	{
		this.elImages[ this.currentIndex ].style.display = 'none';
		this.elImages[ this.currentIndex ].style.visibility = 'hidden';
	}
		
	this.currentIndex += 1;
	if ( this.currentIndex >= this.items.length )
		this.currentIndex = 0;

	this.opacity = 0;
	LSSetOpacity( this.elImages[ this.currentIndex ], this.opacity );
	this.elImages[ this.currentIndex ].style.display = 'inline';
	this.elImages[ this.currentIndex ].style.visibility = 'visible';

	var self = this;
	window.setTimeout( function() { self.fadeIn(); }, 1000 );
}

LSSlideShow.prototype.place = function( parent )
{
	if ( parent == null )
		parent = document.body;
	else
		parent.innerHTML = '';

	this.container = document.createElement( 'div' );
	if ( this.styleName != null )
	this.container.className = 'slideshow-container';
	if ( this.divid != null )
		this.container.id = this.divid;

	this.loading = new LSLoadingGraphic();
	this.loading.place( this.container );
	
	parent.appendChild( this.container );

	this.dataSource.start();
}


function LSTableBuilder()
{
}

LSTableBuilder.prototype.placeBody = function( parent )
{
	this.bFirst = true;
	
	this.containerTable = document.createElement( 'table' );
	this.containerTable.width = '100%';
	this.containerTable.cellSpacing = '0';
	this.containerTable.cellPadding = '0';
	parent.appendChild( this.containerTable );

	var elTR1 = this.containerTable.insertRow( -1 );

	this.firstCell = elTR1.insertCell( -1 );
	this.firstCell.rowSpan = 1;

	this.contentCell = elTR1.insertCell( -1 );
	this.contentCell.rowSpan = 99;
	this.contentCell.align = 'center';
	this.contentCell.valign = 'top';
}

LSTableBuilder.prototype.getTable = function( parent )
{
	return this.containerTable;
}

LSTableBuilder.prototype.getContent = function( parent )
{
	return this.contentCell;
}

LSTableBuilder.prototype.addListCell = function()
{
}


function LSSideTableBuilder()
{
}

LSSideTableBuilder.prototype = new LSTableBuilder();

LSSideTableBuilder.prototype.addListCell = function()
{
	if ( this.bFirst )
	{
		this.bFirst = false;
		return this.firstCell;
	}
	
	var elTR = this.containerTable.insertRow( -1 );
	return elTR.insertCell( 0 );
}


function LSMediaSelectorListRenderer()
{
}

LSMediaSelectorListRenderer.prototype.render = function( parent, item )
{
	var elTitle = document.createElement( 'div' );
	elTitle.className = 'media-selector-item-title';
	elTitle.appendChild( document.createTextNode( item.title ) );
	parent.appendChild( elTitle );
}

function LSMediaSelector( dataSource, parent, divid, render )
{
	var self = this;

	this.tableBuilder = new LSSideTableBuilder();
	this.divid = divid;
	this.dataSource = dataSource;
	this.dataSource.callback = function( data ) { self.update( data.items ); }
	this.parent = parent;
	this.render = ( render == null ) ? new LSMediaSelectorListRenderer() : render;

	if ( this.parent ) this.place( this.parent );
}

LSMediaSelector.prototype = new LSUIElement();

LSMediaSelector.prototype.buildJavascript = function()
{
	var html = "";
	html += "new LSMediaSelector( ";
	html += this.dataSource.buildJavascript();
	html += ", "+(( this.parent != null ) ? "document.getElementById( '"+this.parent.id+"' ) " : "null" );
	html += ", "+(( this.divid != null ) ? "'"+this.divid+"'" : "null" );
	html += " )";
	return html;
}

LSMediaSelector.prototype.getDataSource = function()
{
	return this.dataSource;
}

LSMediaSelector.prototype.getHTMLContainerID = function()
{
	return this.parent.id;
}

LSMediaSelector.prototype.buildMediaController = function()
{
	var elController = document.createElement( 'embed' );
	elController.width = '320';
	elController.height = '256';
	elController.align = 'middle';
	elController.bgcolor = 'black';
	elController.style.visibility = 'hidden';
	elController.className = 'media-selector-controller';
	return elController;
}

LSMediaSelector.prototype.onClick = function( cell )
{
	for( var i in this.items )
	{
		if ( cell == this.items[i].__cell ) this.setMedia( this.items[i].FileUrl[0] );
	}
}

LSMediaSelector.prototype.updateList = function( )
{
	var self = this;

	for( var i in this.items )
	{
		var elTD = this.tableBuilder.addListCell();
		elTD.className = 'media-selector-item-box-off';
		this.items[i].__cell = elTD;
		elTD.onclick = function() { self.onClick( this ); }

		this.render.render( elTD, this.items[i] );
	}

	var elTD = this.tableBuilder.addListCell();
	elTD.className = 'media-selector-item-box-filler';
	elTD.innerHTML = '&nbsp;';
}

LSMediaSelector.prototype.update = function( data )
{
	this.loading.hide();

	this.items = data;
	this.updateList( );

	if ( this.items.length > 0 ) this.setMedia( this.items[0].FileUrl[0] );

	this.tableBuilder.getTable().style.visibility = 'visible';
}

LSMediaSelector.prototype.setMedia = function( mediaUrl )
{
	this.elDescription.innerHTML = '';

	this.controller.src = '';
	this.controller.style.visibility = 'hidden';
	this.controller.style.display = 'none';
	this.controllerContainer.removeChild( this.controller );
	this.controller = null;

	for( var i in this.items )
	{
		if ( this.items[i].FileUrl[0] == mediaUrl ) {
			this.items[i].__cell.className = 'media-selector-item-box-on';
		} else {
			this.items[i].__cell.className = 'media-selector-item-box-off';
		}
	}

	var self = this;
	window.setTimeout( function() { self.setMedia2( mediaUrl ); }, 100 );
}

LSMediaSelector.prototype.setMedia2 = function( mediaUrl )
{
	this.controller = this.buildMediaController();
	this.controllerContainer.appendChild( this.controller );

	this.controller.src = LS_FixLink(mediaUrl);
	this.controller.style.visibility = 'visible';

	for( var i in this.items )
	{
		if ( this.items[i].FileUrl[0] == mediaUrl ) {
			this.elDescription.innerHTML = '';
			this.elDescription.appendChild( document.createTextNode( this.items[i].description ) );
			break;
		}
	}
}

LSMediaSelector.prototype.place = function( parent )
{
	if ( parent == null ) parent = document.body;

	this.loading = new LSLoadingGraphic();
	this.loading.place( parent );

	this.container = document.createElement( 'div' );
	this.container.className = 'media-selector';
	if ( this.divid ) this.container.id = divid;
	parent.appendChild( this.container );

	this.tableBuilder.placeBody( this.container );
	
	this.tableBuilder.getTable().style.visibility = 'hidden';

	this.tableBuilder.getContent().className = 'media-selector-playbox';

	this.controllerContainer = document.createElement( 'div' );
	this.tableBuilder.getContent().appendChild( this.controllerContainer );
	
	this.controller = this.buildMediaController();
	this.controllerContainer.appendChild( this.controller );

	this.elDescription = document.createElement( 'div' );
	this.elDescription.className = 'media-selector-description';
	this.tableBuilder.getContent().appendChild( this.elDescription );
	
	this.dataSource.start();
}


function LSMovieWidget( dataSource, parent, divid, render )
{
	var self = this;
	this.dataSource = dataSource;
	this.dataSource.callback = function( data ) { self.update( data ); }
	this.items = null;

	this.parent = parent;
	if ( this.parent ) this.place( this.parent );
}

LSMovieWidget.prototype = new LSUIElement();

LSMovieWidget.prototype.buildJavascript = function()
{
	var html = "";
	html += "new LSMovieWidget( ";
	html += this.dataSource.buildJavascript();
	html += ", "+(( this.parent != null ) ? "document.getElementById( '"+this.parent.id+"' ) " : "null" );
	html += ", "+(( this.divid != null ) ? "'"+this.divid+"'" : "null" );
	html += " )";
	return html;
}

LSMovieWidget.prototype.getDataSource = function()
{
	return this.dataSource;
}

LSMovieWidget.prototype.getHTMLContainerID = function()
{
	return this.parent.id;
}

LSMovieWidget.prototype.update = function( data )
{
	this.loading.hide();

	if ( this.items != null ) 
		return;

	this.items = data.items;

	if ( data.items.length > 0 )
	{
		var url = null;
		for( var d in data.items )
		{
			if ( data.items[d].FileUrl != null && data.items[d].FileUrl.length > 0 && data.items[d].FileUrl[0].length > 0 )
			{
				url = data.items[d].FileUrl[0];
				break;
			}
		}

		if ( url != null )
		{
			this.elPlaceHolder.style.display = 'none'; 

 			var elEmbed = document.createElement( 'embed' );
			elEmbed.src = LS_FixLink(url);
 			elEmbed.width = '320';
 			elEmbed.height = '256';
 			elEmbed.bgcolor = 'black';
 			if ( elEmbed.setAttribute )
	 			elEmbed.setAttribute( 'autoplay', false );
			elEmbed.style.width = '320px';
 			elEmbed.style.height = '256px';
			this.parent.appendChild( elEmbed );
		}
	}
}

LSMovieWidget.prototype.place = function( parent )
{
	if ( parent == null ) parent = document.body;

	this.parent = parent;

	this.loading = new LSLoadingGraphic();
	this.loading.place( parent );

	this.elPlaceHolder = document.createElement( 'div' );
	this.elPlaceHolder.style.width = '320px';
	this.elPlaceHolder.style.height = '320px';
	parent.appendChild( this.elPlaceHolder );
	
	this.dataSource.start();
}


function LSImageList( dataSource, parent, divid, width, height, anchorTarget )
{
	var self = this;

	this.anchorTarget = ( anchorTarget != null ) ? anchorTarget : null;
	this.width = ( width == null ) ? 50 : width;
	this.height = ( height == null ) ? 50 : height;
	this.divid = divid;
	this.dataSource = dataSource;
	this.dataSource.callback = function( data ) { self.setRecord( data.items ); }
	this.parent = parent;
	if ( parent )
		this.place( parent );
}

LSImageList.prototype = new LSUIElement();

LSImageList.prototype.getDataSource = function()
{
	return this.dataSource;
}

LSImageList.prototype.buildJavascript = function()
{
	var html = "";
	html += "new LSImageList( ";
	html += this.dataSource.buildJavascript();
	html += ", "+(( this.parent != null ) ? "document.getElementById( '"+this.parent.id+"' ) " : "null" );
	html += ", "+(( this.divid != null ) ? "'"+this.divid+"'" : "null" );
	html += " )";
	return html;
}

LSImageList.prototype.getHTMLContainerID = function()
{
	return this.parent.id;
}

LSImageList.prototype.setRecord = function( data )
{
	this.loading.hide();
	
	for( var i in data )
	{
		var elDiv = document.createElement( 'div' );
		elDiv.className = 'imagelist-item';

		var elAnchor = document.createElement( 'a' );
		if ( this.anchorTarget != null )
			elAnchor.target = this.anchorTarget;
		elAnchor.href = LS_FixLink(data[ i ].link);
		elDiv.appendChild( elAnchor );

		var elImage = document.createElement( 'img' );
		elImage.src = LSResizeImage( data[ i ].MediaUrl, this.width, this.height );
		elImage.border = '0';
		elImage.className = 'imagelist-image';
		elImage.galleryImg = false;
		elAnchor.appendChild( elImage );

		this.container.appendChild( elDiv );
	}
}

LSImageList.prototype.place = function( parent )
{
	if ( parent == null )
		parent = document.body;
	else
		parent.innerHTML = '';
	this.parent = parent;

	this.loading = new LSLoadingGraphic();
	this.loading.place( parent );

	this.container = document.createElement( 'div' );
	if ( this.styleName != null )
	this.container.className = 'imagelist-container';
	if ( this.divid != null )
		this.container.id = this.divid;
	
	parent.appendChild( this.container );

	this.dataSource.start();
}


function LSFadingImageList( dataSource, parent, divid, count, width, height, anchorTarget )
{
	var self = this;

	this.anchorTarget = ( anchorTarget != null ) ? anchorTarget : null;
	this.count = ( count == null ) ? 20 : count;
	this.width = ( width == null ) ? 100 : width;
	this.height = ( height == null ) ? 100 : height;
	this.divid = divid;
	this.dataSource = dataSource;
	this.dataSource.callback = function( data ) { self.setRecord( data.items ); }
	this.parent = parent;
	this.divs = [];
	this.currentIndex = 0;
	this.opacity = 0;
	if ( parent )
		this.place( parent );
}

LSFadingImageList.prototype = new LSUIElement();

LSFadingImageList.prototype.getDataSource = function()
{
	return this.dataSource;
}

LSFadingImageList.prototype.buildJavascript = function()
{
	var html = "";
	html += "new LSFadingImageList( ";
	html += this.dataSource.buildJavascript();
	html += ", "+(( this.parent != null ) ? "document.getElementById( '"+this.parent.id+"' ) " : "null" );
	html += ", "+(( this.divid != null ) ? "'"+this.divid+"'" : "null" );
	html += " )";
	return html;
}

LSFadingImageList.prototype.getHTMLContainerID = function()
{
	return this.parent.id;
}

LSFadingImageList.prototype.setRecord = function( data )
{
	this.loading.hide();

	this.items = data;
	
	for( var i=0; i<this.count;i++ )
	{
		var elDiv = document.createElement( 'div' );
		elDiv.className = 'fading-imagelist-item';

		var link = '';
		var mediaUrl = '';
		if ( i < this.items.length )
		{
			link = this.items[i].link;
			mediaUrl = LSResizeImage( this.items[i].MediaUrl, this.width, this.height );
		}	

		var elAnchor = document.createElement( 'a' );
		if ( this.anchorTarget != null )
			elAnchor.target = this.anchorTarget;
		elAnchor.href = LS_FixLink(link);
		elDiv.appendChild( elAnchor );

		var elImage = document.createElement( 'img' );
		elImage.src = LS_FixLink(mediaUrl);
		elImage.galleryImg = false;
		elImage.border = '0';
		elImage.className = 'fading-imagelist-image';
		elImage.style.visibility = ( mediaUrl.length > 0 ) ? 'visible' : 'hidden';
		elAnchor.appendChild( elImage );

		this.container.appendChild( elDiv );
		
		this.divs.push( { container: elDiv, link: elAnchor, image: elImage } );
	}
	
	this.startFading();
}

LSFadingImageList.prototype.setItem = function( itemIndex )
{
	LSSetOpacity( this.divs[ this.currentIndex ].container, this.opacity );
	this.divs[this.currentIndex].link.href = LS_FixLink(this.items[ itemIndex ].link);
	this.divs[this.currentIndex].image.src = LSResizeImage( this.items[ itemIndex ].MediaUrl, this.width, this.height );
	this.divs[this.currentIndex].image.style.visibility = 'visible';
}

LSFadingImageList.prototype.startFading = function()
{
	this.opacity = 0;
	this.currentIndex = ( Math.floor( Math.random() * this.count ) );
	this.setItem( Math.floor( Math.random() * this.items.length ) );
	
	var self = this;
	window.setTimeout( function() { self.fadeIn(); }, 100 );
}

LSFadingImageList.prototype.fadeIn = function()
{
	this.opacity += 10;
	LSSetOpacity( this.divs[ this.currentIndex ].container, this.opacity );

	var self = this;
	if ( this.opacity < 100 )
		window.setTimeout( function() { self.fadeIn(); }, 100 );
	else
		window.setTimeout( function() { self.startFading(); }, 100 );
}

LSFadingImageList.prototype.place = function( parent )
{
	if ( parent == null )
		parent = document.body;
	else
		parent.innerHTML = '';

	this.loading = new LSLoadingGraphic();
	this.loading.place( parent );

	this.container = document.createElement( 'div' );
	if ( this.styleName != null )
	this.container.className = 'fading-imagelist-container';
	if ( this.divid != null )
		this.container.id = this.divid;
	
	parent.appendChild( this.container );

	this.dataSource.start();
}



function LSImageGrid( dataSource, parent, divid, rows, columns, width, height, anchorTarget )
{
	var self = this;

	this.anchorTarget = ( anchorTarget != null ) ? anchorTarget : null;
	this.rows = ( rows == null ) ? 3 : count;
	this.columns = ( columns == null ) ? 3 : count;
	this.width = ( width == null ) ? 20 : width;
	this.height = ( height == null ) ? 20 : height;
	this.divid = divid;
	this.dataSource = dataSource;
	this.dataSource.callback = function( data ) { self.setRecord( data.items ); }
	this.parent = parent;
	this.divs = [];
	this.currentIndex = 0;
	this.opacity = 0;
	if ( parent )
		this.place( parent );
}

LSImageGrid.prototype = new LSUIElement();

LSImageGrid.prototype.getDataSource = function()
{
	return this.dataSource;
}

LSImageGrid.prototype.buildJavascript = function()
{
	var html = "";
	html += "new LSImageGrid( ";
	html += this.dataSource.buildJavascript();
	html += ", "+(( this.parent != null ) ? "document.getElementById( '"+this.parent.id+"' ) " : "null" );
	html += ", "+(( this.divid != null ) ? "'"+this.divid+"'" : "null" );
	html += " )";
	return html;
}

LSImageGrid.prototype.getHTMLContainerID = function()
{
	return this.parent.id;
}

LSImageGrid.prototype.setRecord = function( data )
{
	this.loading.hide();

	this.items = data;

	var itemIndex = 0;
	for( var i in this.divs )
	{
		this.currentIndex = i;
		this.setItem( itemIndex );
		itemIndex++;
		if ( itemIndex >= this.items.length )
			itemIndex = 0;

		LSSetOpacity( this.divs[ i ].container, 100 );
	}
	
	this.startFading();
}

LSImageGrid.prototype.setItem = function( itemIndex )
{
	LSSetOpacity( this.divs[ this.currentIndex ].container, this.opacity );
	this.divs[this.currentIndex].link.href = LS_FixLink(this.items[ itemIndex ].link);
	this.divs[this.currentIndex].image.src = LSResizeImage( this.items[ itemIndex ].MediaUrl, this.width, this.height );
	this.divs[this.currentIndex].image.style.visibility = 'visible';
}

LSImageGrid.prototype.startFading = function()
{
	this.opacity = 0;
	this.currentIndex = ( Math.floor( Math.random() * this.divs.length ) );
	this.setItem( Math.floor( Math.random() * this.items.length ) );

	var self = this;
	window.setTimeout( function() { self.fadeIn(); }, 100 );
}

LSImageGrid.prototype.fadeIn = function()
{
	this.opacity += 10;
	LSSetOpacity( this.divs[ this.currentIndex ].container, this.opacity );

	var self = this;
	if ( this.opacity < 100 )
		window.setTimeout( function() { self.fadeIn(); }, 100 );
	else
		window.setTimeout( function() { self.startFading(); }, 100 );
}

LSImageGrid.prototype.place = function( parent )
{
	if ( parent == null )
		parent = document.body;
	else
		parent.innerHTML = '';

	this.loading = new LSLoadingGraphic();
	this.loading.place( parent );

	this.container = document.createElement( 'table' );
	if ( this.styleName != null )
	this.container.className = 'imagegrid-container';
	this.container.cellSpacing = '0';
	this.container.cellPadding = '0';
	this.container.width = ( this.columns * this.width );
	if ( this.divid != null )
		this.container.id = this.divid;
		
	this.divs = [];
	for( var r = 0; r < this.rows ; r++ )
	{
		var elTR = this.container.insertRow( -1 );
		elTR.height = this.height;
		elTR.style.height = this.height + 'px';
		for ( var c = 0; c < this.columns; c++ )
		{
			var elTD = elTR.insertCell( -1 );
			elTD.width = this.width;
			elTR.style.width = this.width + 'px';
			elTD.className = 'imagegrid-item';

			var elAnchor = document.createElement( 'a' );
			if ( this.anchorTarget != null )
				elAnchor.target = this.anchorTarget;
			elTD.appendChild( elAnchor );

			var elImage = document.createElement( 'img' );
			elImage.galleryImg = false;
			elImage.src = '';
			elImage.border = '0';
			elImage.className = 'imagegrid-image';
			elImage.style.visibility = 'hidden';
			elImage.width = this.width;
			elImage.heigh = this.height;
			elImage.style.width = this.width + 'px';
			elImage.style.height = this.height + 'px';
			elAnchor.appendChild( elImage );

			this.divs.push( { container: elTD, link: elAnchor, image: elImage } );
		}
	}
	
	parent.appendChild( this.container );

	this.dataSource.start();
}


function LSCounter( dataSource, parent, divid )
{
	var self = this;

	this.divid = divid;
	this.dataSource = dataSource;
	this.dataSource.callback = function( data ) { self.setRecord( data.items ); }
	this.parent = parent;
	if ( parent )
		this.place( parent );
}

LSCounter.prototype = new LSUIElement();

LSCounter.prototype.getDataSource = function()
{
	return this.dataSource;
}

LSCounter.prototype.buildJavascript = function()
{
	var html = "";
	html += "new LSCounter( ";
	html += this.dataSource.buildJavascript();
	html += ", "+(( this.parent != null ) ? "document.getElementById( '"+this.parent.id+"' ) " : "null" );
	html += ", "+(( this.divid != null ) ? "'"+this.divid+"'" : "null" );
	html += " )";
	return html;
}

LSCounter.prototype.getHTMLContainerID = function() { return this.parent.id; }

LSCounter.prototype.setRecord = function( data )
{
	this.loading.hide();
	this.container.appendChild( document.createTextNode( data.length.toString() ) );
}

LSCounter.prototype.place = function( parent )
{
	if ( parent == null ) parent = document.body;
	else parent.innerHTML = '';

	this.loading = new LSLoadingGraphic();
	this.loading.place( parent );

	this.container = document.createElement( 'span' );
	this.container.className = 'ls-counter';
	if ( this.divid != null )
		this.container.id = this.divid;
	
	parent.appendChild( this.container );

	this.dataSource.start();
}


function LSPeoplePanes( controller, height, divid )
{
	this.divid = divid;
	this.controller = controller;
	this.height = height;
	this.commands = [];
	this.index = 0;
	this.movecount = 1;
	this.steps = 5;
	this.itemwidth = 24;
	this.width = 0;

	this.extra = null;
	this.divs = [];
	this.itemcount = 3;
	this.resizeTimer = null;

	this.personList = [];
	this.pendingPersonList = null;

	var self = this;
	window.setInterval( function() { self.idle(); }, 20 );
}

LSPeoplePanes.prototype.addPerson = function( person )
{
	this.personList.push( person );
}

LSPeoplePanes.prototype.renderInto = function( elParent, person )
{
	var lPerson = person;
	var parentObj = this.controller;
	
	var anchorUrl = LSGlobals.appUrl+'profile_view.aspx?CustomerID='+person;
	var elAnchor = document.createElement( 'a' );
	elAnchor.target = '_blank';
	elAnchor.href = LS_FixLink(anchorUrl);
	
	var imgUrl = LSGlobals.appUrl+'photo.aspx?w=25&h=25&CustomerID='+person;
	var elPersonImg = document.createElement( 'img' );
	elPersonImg.src = LS_FixLink(imgUrl);
	elPersonImg.width = 25;
	elPersonImg.border = '0';
	elPersonImg.height = 25;
	elPersonImg.style.margin = '1px';
	elPersonImg.onmouseover = function() { parentObj.rollover( this, lPerson ); };
	elPersonImg.onmouseout = function() { parentObj.rollout(); };

	elAnchor.appendChild( elPersonImg );
	elParent.appendChild( elAnchor );
}

LSPeoplePanes.prototype.deletePerson = function( person )
{
	var newPersonList = [];
	for( var e in this.personList )
		if ( this.personList[e] != person ) newPersonList.push( this.personList[e] );
	this.personList = newPersonList;
}

LSPeoplePanes.prototype.setPersonList = function( data )
{
	if ( this.commands.length > 0 )
	{
		this.pendingPersonList = data;
	}
	else
	{
		var changed = false;

		var existingIDs = {};
		for( var e in this.personList ) existingIDs[ this.personList[e] ] = true;

		var newDataIDs = {};
		for( var e in data )
		{
			if ( existingIDs[ data[e] ] == null ) { changed = true; this.addPerson( data[e] ); }
			newDataIDs[ data[e] ] = true;
		}

		var origList = []
		for( var e in this.personList )
			origList.push( this.personList[e].toString() );
		for( var e in origList )
			if ( newDataIDs[ origList[e] ] == null ) { changed = true; this.deletePerson( origList[e] ); }

		if ( this.index >= this.personList.length )
			this.index = ( this.personList.length - 1 );
		if ( this.personList.length == 0 )
		{
			this.index = 0;
			this.handleResize( this.width );
		}

		if ( changed )
			this.update();
	}
}

LSPeoplePanes.prototype.onClick = function( divObj )
{
	LSEvent.sendMessage( this, 'click', divObj.data );
}

LSPeoplePanes.prototype.handleResize = function( width )
{
	if ( window.innerWidth == null )
	{
		var width = this.elSizer.offsetWidth;
		if ( width == 0 )
			width = this.elSizer.clientWidth - 55;
		width -= 50;
	}

	this.onUpdatingImages();
	
	this.resizeTimer = null;
	this.commands = [];

	this.itemcount = Math.floor( width / this.itemwidth );
	if ( this.itemcount < 0 ) this.itemcount = 0;
	
	this.width = this.itemcount * this.itemwidth;
	
	if ( ( this.itemcount * this.itemwidth ) > 0 )
		this.elMiddleTD.width = ( this.itemcount * this.itemwidth );
	this.elMiddleDiv.style.width = ( this.itemcount * this.itemwidth )+'px';
	this.elMiddleDiv.innerHTML = '';
	this.divs = [];

	var self = this;
	for( var i = 0; i < this.itemcount + 1; i++ )
	{
		var nodeItemDiv = document.createElement( 'div' );

		nodeItemDiv.className = 'scroll-item';
		nodeItemDiv.style.fontSize = '11px';
		nodeItemDiv.style.color = '#666';
		nodeItemDiv.style.position = 'absolute';
		nodeItemDiv.style.width = this.itemwidth + 'px';
		nodeItemDiv.style.height = '24px';
		nodeItemDiv.style.overflow = 'hidden';
		nodeItemDiv.style.top = '0px';
		nodeItemDiv.style.left = (i*this.itemwidth)+'px';
		nodeItemDiv.style.textAlign = 'center';
		nodeItemDiv.onclick = function() { self.onClick( this ); }
		this.elMiddleDiv.appendChild( nodeItemDiv );
		
		this.divs.push( nodeItemDiv );
	}
	
	this.setPositions();
	this.update();
}

LSPeoplePanes.prototype.onResize = function( parent )
{
	if ( this.resizeTimer != null )
		window.clearTimeout( this.resizeTimer );
	var self = this;
	this.resizeTimer = window.setTimeout( function() { self.handleResize(); }, 500 );
}

LSPeoplePanes.prototype.onLoad = function( parent )
{
	this.handleResize();
}

LSPeoplePanes.prototype.place = function( parent )
{
	if ( parent == null ) parent = document.body;
	
	if ( window.innerWidth == null )
	{
		var self = this;
		LSEvent.addEventListener( window, 'resize', function( evData ) { self.onResize( evData ); } );
		LSEvent.addEventListener( window, 'load', function( evData ) { self.onLoad( evData ); } );

		this.elSizer = document.createElement( 'div' );
		this.elSizer.style.height = '0px';
		this.elSizer.style.width = '100%';
		this.elSizer.style.fontSize = '0px';
		this.elSizer.onresize = function() { self.onResize(); }
		parent.appendChild( this.elSizer );
	}
	
	this.elMainContainer = document.createElement( 'div' );
	if ( window.innerWidth == null )
		this.elMainContainer.style.width = '100%';
	this.elMainContainer.style.textAlign = 'center';
	this.elMainContainer.id = this.divid;
	
	var elMainTable = document.createElement( 'table' );
	elMainTable.cellSpacing = '0';
	elMainTable.cellPadding = '0';
	elMainTable.className = 'scroll';
	this.elMainContainer.appendChild( elMainTable );

	var nodeTableBody = document.createElement( 'tbody' );
	elMainTable.appendChild( nodeTableBody );

	var nodeTR = document.createElement( 'tr' );
	
	var nodeLeftTD = document.createElement( 'td' );
	nodeLeftTD.valign = 'middle';
	nodeLeftTD.align = 'center';
	nodeLeftTD.width = '22';
	nodeLeftTD.height = '24';
	nodeLeftTD.className = 'scroll-left';

	var nodeLeftImage = document.createElement( 'img' );
	nodeLeftImage.src = LS_FixLink(LSGlobals.imagePath+'arrowLeft.gif');
	nodeLeftImage.width = '22';
	nodeLeftImage.height = '22';
	nodeLeftImage.style.visibility = 'hidden';

	var cnt1 = this.controller;
	nodeLeftImage.onclick = function() { cnt1.scrollLeft(); };

	nodeLeftTD.appendChild( nodeLeftImage );
	this.leftbutton = nodeLeftImage;
	nodeTR.appendChild( nodeLeftTD );

	this.elMiddleTD = document.createElement( 'td' );
	this.elMiddleTD.className = 'scroll-middle';

	this.elMiddleDiv = document.createElement( 'div' );
	this.elMiddleDiv.style.position = 'relative';
	this.elMiddleDiv.style.height = '24px';
	this.elMiddleDiv.style.overflow = 'hidden';
	this.elMiddleTD.appendChild( this.elMiddleDiv );

	nodeTR.appendChild( this.elMiddleTD );

	var nodeRightTD = document.createElement( 'td' );
	nodeRightTD.valign = 'middle';
	nodeRightTD.align = 'center';
	nodeRightTD.width = '22';
	nodeRightTD.height = '24';
	nodeRightTD.className = 'scroll-right';
	
	var nodeRightImage = document.createElement( 'img' );
	nodeRightImage.src = LS_FixLink(LSGlobals.imagePath+'arrowRight.gif');
	nodeRightImage.width = '22';
	nodeRightImage.height = '22';
	nodeRightImage.style.visibility = 'hidden';

	var cnt2 = this.controller;
	nodeRightImage.onclick = function() { cnt2.scrollRight(); };

	nodeRightTD.appendChild( nodeRightImage );
	this.rightbutton = nodeRightImage;
	
	nodeTR.appendChild( nodeRightTD );
	
	nodeTableBody.appendChild( nodeTR );

	parent.appendChild( this.elMainContainer );
}

LSPeoplePanes.prototype.addObject = function( obj ) { this.objects.push( obj ); }
LSPeoplePanes.prototype.onUpdatingImages = function() { }

LSPeoplePanes.prototype.clear = function()
{
	this.onUpdatingImages();
	
	this.index = 0;
	for( var i in this.divs )
		this.divs[i].style.visibility = 'hidden';
	this.leftbutton.style.visibility = 'hidden';
	this.rightbutton.style.visibility = 'hidden';
	
	this.setPositions();
}

LSPeoplePanes.prototype.setPositions = function()
{
	var startx = this.itemwidth * -1;
	for( var d in this.divs )
	{
		this.divs[d].style.left = startx+'px';
		startx += this.itemwidth;
	}
	this.extra = this.divs[0];
}

LSPeoplePanes.prototype.scroll = function( direction )
{
	this.movecount = Math.floor( this.itemcount / 2 );
	if( this.movecount <= 0 )
		this.movecount = 1;
	
	this.onUpdatingImages();
	for( var i = 0; i < this.movecount; i++ )
	{
		this.commands.push( { task: 'move_extra', direction: direction } );
		for( var s = 0; s < this.steps; s++ )
		{
			this.commands.push( { task: 'shift',
				amount: direction * ( this.itemwidth / this.steps ) * -1 } );
		}
		this.commands.push( { task: 'change_index', direction: direction } );
	}
}

LSPeoplePanes.prototype.idle = function()
{
	if ( this.commands.length <= 0 )
		return;

	this.onUpdatingImages();

	var f = this.commands.shift();
	if ( f.task == 'move_extra' )
		this.moveExtra( f.direction );
	if ( f.task == 'shift' )
	{
		for( var oi in this.divs )
			this.move( this.divs[ oi ], f.amount );
	}
	if ( f.task == 'change_index' )
	{
		this.changeIndex( f.direction );
		if ( this.pendingPersonList ) 
		{
			this.setPersonList( this.pendingPersonList );
			this.pendingPersonList = null;
		}
	}
}

LSPeoplePanes.prototype.move = function( obj, dx )
{
	var x = parseInt( obj.style.left.replace( 'px', '' ) ) + dx;
	var w = parseInt( obj.style.width.replace( 'px', '' ) );
	obj.style.left = x+'px';
	obj.style.visibility = 'visible';
}

LSPeoplePanes.prototype.moveExtra = function( direction )
{
	if ( this.extra == null )
		return;
		
	this.extra.style.left = ( direction == 1 ) ? ( this.itemwidth * this.itemcount )+'px' : '-'+this.itemwidth+'px';
	this.extra.style.top = '0px';
	this.extra.style.visibility = 'hidden';

	var ci = this.index + ( ( direction == -1 ) ? -1 : this.itemcount );
	if ( ci >= this.personList.length ) ci -= this.personList.length;
	if ( ci < 0 ) ci = this.personList.length + ci;

	this.extra.data = this.personList[ ci ];

	if ( this.extra.childNodes.length > 0 )
	{
		while( this.extra.childNodes.length > 0 )
			this.extra.removeChild( this.extra.childNodes.item( 0 ) );
	}
	this.renderInto( this.extra, this.personList[ ci ] );
	
	var positions = [];
	for( var d in this.divs )
		positions.push( this.divs[d].style.left );
}

LSPeoplePanes.prototype.changeIndex = function( direction )
{
	this.index += direction;

	if ( this.index < 0 ) this.index = this.personList.length - 1;
	if ( this.index >= this.personList.length ) this.index = 0;

	for( var i = 0; i < this.divs.length; i++ )
	{
		var px = LSGetPixels( this.divs[i].style.left );
		if ( px < -5 || px >= this.width )
			this.extra = this.divs[i];
	}
}

LSPeoplePanes.prototype.update = function()
{
	var ci = this.index;

	this.leftbutton.style.visibility = ( this.personList.length > this.itemcount ) ? 'visible' :  'hidden';
	this.rightbutton.style.visibility = ( this.personList.length > this.itemcount ) ? 'visible' : 'hidden';

	var c = 0;
	for( var i = 0; i < this.divs.length; i++ )
	{
		if ( this.divs[ i ] != this.extra )
		{
			this.divs[ i ].data = this.personList[ ci ];
			if ( this.divs[ i ].childNodes.length > 0 )
			{
				while( this.divs[ i ].childNodes.length > 0 )
					this.divs[ i ].removeChild( this.divs[ i ].childNodes.item( 0 ) );
			}
			if ( c < this.personList.length )
				this.renderInto( this.divs[ i ], this.personList[ ci ] );
			this.move( this.divs[ i ], 0 );

			ci++;
			if ( ci >= this.personList.length ) ci -= this.personList.length;
			c++;
		}
	}
}


function LSPeopleScroller( parent, divid, personList )
{
	var self = this;

	this.parent = parent;
	this.width = 450;
	this.height = 155;
	this.popup_offset_x = -22;
	this.popup_offset_y = -15;
	this.divid = divid;
	this.personList = personList;
	
	this.personDescriptions = {};
	this.personMemberNames = {};
	
	this.popupPerson = null;
	
	if ( this.parent != null )
		this.place( this.parent );
}

LSPeopleScroller.prototype.setPersonList = function( data ) { this.scroller.setPersonList( data ); }

LSPeopleScroller.prototype.buildJavascript = function() { return ''; }
LSPeopleScroller.prototype.getDataSource = function() { return null; }

LSPeopleScroller.prototype.scrollLeft = function( ) { this.scroller.scroll( -1 ); }
LSPeopleScroller.prototype.scrollRight = function( ) { this.scroller.scroll( 1 ); }
LSPeopleScroller.prototype.scroll = function( dir ) { this.scroller.scroll( dir ); }
LSPeopleScroller.prototype.onUpdatingImages = function()
{
	if ( this.controller.scrollerPopup == null ) return;
	this.controller.scrollerPopup.hide();
}

LSPeopleScroller.prototype.onDescriptionData = function( customerID, data )
{
	if ( this.personDescriptions[ customerID ] != null )
	{
	    return;
	}
	
	if ( data != null && data.items != null )
	{
		var desc = ( data.items.length > 0 ) ? data.items[0].description : '';
		var membername = ( data.items.length > 0 ) ? data.items[0].title : '';
		
		this.personDescriptions[ customerID ] = desc;
		this.personMemberNames[ customerID ] = membername;
		
		if ( this.scrollerPopup != null && customerID == this.popupPerson )
	    {
	        this.displayPopup (membername, desc);
		}
	}
}

LSPeopleScroller.prototype.displayPopup = function (membername, desc)
{
    this.scrollerPopup.content.innerHTML = "<p style=\"padding:0px;margin:0px;\"><b>"+membername+"</b></p>";
	this.scrollerPopup.content.innerHTML += "<p style=\"padding:0px;margin:0px;\">"+desc+"</p>";
}

LSPeopleScroller.prototype.getDescription = function( cid )
{
	var customerID = cid;
	var self = this;
	new LSCustomersGet( customerID, function( data ) { self.onDescriptionData( customerID, data ) } );
}

LSPeopleScroller.prototype.rollover = function( obj, cid )
{
	this.popupPerson = cid;
	if ( this.personDescriptions[ cid ] == null )
		this.getDescription( cid );
	
	if ( this.personDescriptions[ cid ] != null && this.personMemberNames[ cid ] != null)
	{
	    this.displayPopup (this.personMemberNames[ cid ], this.personDescriptions[ cid ]);
	}
	
	this.scrollerPopup.show( obj );
}
LSPeopleScroller.prototype.rollout = function()
{
	this.popupPerson = null;

	if ( this.scrollerPopup == null ) return;
	this.scrollerPopup.hide();
}

LSPeopleScroller.prototype.udpateSizing = function( width ) { this.scroller.handleResize( width ); }

LSPeopleScroller.prototype.place = function( parent )
{
	var self = this;

	this.scroller = new LSPeoplePanes( this, this.height, this.divid );
	this.scroller.controller = this;
	this.scroller.onUpdatingImages = this.onUpdatingImages;
	this.scroller.place( parent );

	this.scroller.setPersonList( this.personList );

	this.scrollerPopup = new LSScrollerPopup( this.popup_offset_x, this.popup_offset_y, 250 );
	this.scrollerPopup.place( document.body );
}



LSSearchBox.prototype = new LSUIElement();

function LSSearchBox( parent )
{
	this.parent = parent;
	this.timer = null;
	if ( this.parent )
		this.place( this.parent );
}

LSSearchBox.prototype.getXYTotal = function( obj )
{
	var x = 0;
	var y = 0;

	while( obj != null )
	{
		x += obj.offsetLeft;
		y += obj.offsetTop;
		obj = obj.offsetParent;
	}

	return { x:x, y:y };
}

LSSearchBox.prototype.update = function()
{
	while( this.tableNode.childNodes.length > 0 )
		this.tableNode.removeChild( this.tableNode.childNodes.item( 0 ) );

	for( var e in this.data ) {
        var elTrItem = this.tableNode.insertRow( -1 );
        var elTdItem = elTrItem.insertCell( -1 );
        elTdItem.onmouseover = function() { this.style.background = '#eeeeee'; }
        elTdItem.onmouseout = function() { this.style.background = 'white'; }
        elTdItem.cssClass = 'ls-searchbox-row';

        var elDiv = document.createElement( 'div' );
        elDiv.style.padding = '3px';
        var elAnchor = document.createElement( 'a' );
        elAnchor.href = this.data[e].link;
        elAnchor.appendChild( document.createTextNode( this.data[e].title ) );
        elDiv.appendChild( elAnchor );
        elTdItem.appendChild( elDiv );
	}

    var offset = this.getXYTotal( this.elSearchText );
    this.dropList.style.left = '20px';
    this.dropList.style.top = '55px';
    this.dropList.style.visibility = 'visible';
}

LSSearchBox.prototype.onSearch = function()
{
	this.reader = new LSAllGetAll( { keyword: this.elSearchText.value, sort:'accessdate' } );
	var self = this;
	this.reader.callback = function( data )
	{
		self.data = data.items;
		self.update();
	}
	this.reader.start();
}

LSSearchBox.prototype.onKeyUp = function()
{
    if ( this.timer == null ) {
        window.clearTimeout( this.timer );
        this.timer = null;
    }
    
    var self = this;
    this.timer = window.setTimeout( function() { self.onSearch(); }, 1000 );
}

LSSearchBox.prototype.place = function( parent )
{
	if ( parent == null )
		parent = document.body;
	else
		parent.innerHTML = '';

    var self = this;

	this.container = document.createElement( 'div' );
	this.container.style.position = 'relative';
    
    var elKeywordP = document.createElement( 'p' );
    elKeywordP.className = 'ls-newsfeed-search-text';
    elKeywordP.style.fontSize = '10pt';
    elKeywordP.appendChild( document.createTextNode( 'Search!' ) );
    this.container.appendChild( elKeywordP );

    var elTextP = document.createElement( 'p' );
    this.elSearchText = document.createElement( 'input' );
    this.elSearchText.type = 'text';
    this.elSearchText.style.width = '200px';
    this.elSearchText.onkeyup = function() { self.onKeyUp(); }
    elTextP.appendChild( this.elSearchText );
    this.container.appendChild( elTextP );

    this.dropList = document.createElement( 'div' );
    this.dropList.style.position = 'absolute';
    this.dropList.style.height = '300px';
    this.dropList.style.width = '200px';
    this.dropList.style.border = '1px solid black';
    this.dropList.style.padding = '0px';
    this.dropList.style.overflow = 'auto';
    this.dropList.style.visibility = 'hidden';
    this.dropList.style.background = 'white';
    
    this.tableNode = document.createElement( 'table' );
    this.tableNode.width = '220px';
    this.tableNode.style.margin = '0px';
    this.tableNode.style.padding = '0px';
    this.tableNode.cellPadding = '0';
    this.tableNode.cellSpacing = '0';
    this.dropList.appendChild( this.tableNode );    
    
    this.container.appendChild( this.dropList );
	
	parent.appendChild( this.container );
} 


function LSNewsFeedRegularBuilder() {
}

LSNewsFeedRegularBuilder.prototype.build = function( feed, parent, items )
{
    for( var objind in items ) {
        var item = items[objind];
        var elIRow = parent.insertRow( -1 );
        var elIHeader = elIRow.insertCell( -1 );

        var mediaUrl = feed.getMediaUrl( item );
        if ( mediaUrl != null ) {
            var elMediaAnchor = document.createElement( 'a' );
            if( feed.anchorTarget != null )
                elMediaAnchor.target = feed.anchorTarget;
            elMediaAnchor.href = item.link;
            elMediaAnchor.style.styleFloat = 'left';
            elMediaAnchor.style.cssFloat = 'left';
            elMediaAnchor.style.padding = '0px 5px 0px 0px';

            mediaUrl = LSResizeImage( mediaUrl, 30, 30 );
	        mediaUrl = mediaUrl.replace( /&scaletype=(\w+)/, '' );
	        mediaUrl += '&scaletype=zoom';

            var elMediaImgItem = document.createElement( 'img' );
            elMediaImgItem.src = mediaUrl;
            elMediaImgItem.width = 30;
            elMediaImgItem.height = 30;
            elMediaImgItem.border = 0;
            elMediaImgItem.style.border = '1px solid #ccc';
            elMediaAnchor.appendChild( elMediaImgItem );
            elIHeader.appendChild( elMediaAnchor );
        }
        
        var elAnchor = document.createElement( 'a' );
        if( feed.anchorTarget != null )
        {
            elAnchor.target = feed.anchorTarget;
        }
        elAnchor.href = item.link;
        elAnchor.className = 'ls-newsfeeds-following-link';
        elAnchor.appendChild( document.createTextNode( item.title ) );
        elIHeader.appendChild( elAnchor );
    }
}

function LSNewsFeedCustomerBuilder_mouseOver( id ) {
    var rids = id.split( /_/ );
    document.getElementById( 'lsnewsfeedpersonicondesc_'+rids[1] ).style.display = 'inline';
}

function LSNewsFeedCustomerBuilder_mouseOut( id ) {
    var rids = id.split( /_/ );
    document.getElementById( 'lsnewsfeedpersonicondesc_'+rids[1] ).style.display = 'none';
}

function LSNewsFeedCustomerBuilder() {
}

LSNewsFeedCustomerBuilder.prototype.build = function( feed, parent, items )
{
    var elIRow = parent.insertRow( -1 );
    var elIHeader = elIRow.insertCell( -1 );

    for( var objind in items ) {
        var elDiv = document.createElement( 'div' );
        elIHeader.appendChild( elDiv );
        elDiv.style.cssFloat = 'left';
        elDiv.style.styleFloat = 'left';
        elDiv.style.height = '30px';
        elDiv.style.width = '30px';
        elDiv.style.margin = '3px';

        var item = items[objind];
        var ownerUrl = LSGlobals.appUrl+'profile_view.aspx?CustomerID='+item.title;

        var elImgAnchor = document.createElement( 'a' );
        elImgAnchor.href = ownerUrl;
        if( feed.anchorTarget != null )
            elImgAnchor.target = feed.anchorTarget;
        
    	var imgUrl = LSGlobals.appUrl+'photo.aspx?w=30&h=30&CustomerID='+item.title;
        var elImg = document.createElement( 'img' );
        elImg.id = 'lsnewsfeedpersonicon_'+LSGlobals.uniqueID;
        elImg.src = imgUrl;
        elImg.width = 30;
        elImg.height = 30;
        elImg.border = 0;
        elImg.style.border = '1px solid #ccc';
        elImg.onmouseover = function() { LSNewsFeedCustomerBuilder_mouseOver( this.id ); }
        elImg.onmouseout = function() { LSNewsFeedCustomerBuilder_mouseOut( this.id ); }
        elImgAnchor.appendChild( elImg  );
        elDiv.appendChild( elImgAnchor );
        
        var elDescriptionWrap = document.createElement( 'div' );
        elDescriptionWrap.style.position = 'relative';
        elDescriptionWrap.style.height = '1px';
        elDescriptionWrap.style.width = '1px';
        elDiv.appendChild( elDescriptionWrap );

        var elDescription = document.createElement( 'div' );
        elDescription.id = 'lsnewsfeedpersonicondesc_'+LSGlobals.uniqueID;
        elDescription.style.position = 'absolute';
        elDescription.style.display = 'none';
        elDescription.style.border = '1px solid #ccc';
        elDescription.style.background = 'white';
        elDescription.style.padding = '3px';
        elDescription.style.width = '200px';
        elDescriptionWrap.appendChild( elDescription );
        
        var elName = document.createElement( 'div' );
        elName.style.fontWeight = 'bold';
        elName.appendChild( document.createTextNode( item.title ) );
        elDescription.appendChild( elName );
       
        var elRealDescDiv = document.createElement( 'div' );
        elRealDescDiv.id = 'lsnewsfeedpersoniconrdesc_'+LSGlobals.uniqueID;
        elDescription.appendChild( elRealDescDiv );
        
        feed.setPersonDescription( item.title, elRealDescDiv.id );
        
        LSGlobals.uniqueID++;
    }
}


LSNewsFeed.prototype = new LSUIElement();

function LSNewsFeed( reader, parent, width, height, containerID, anchorTarget )
{
	this.containerID = containerID;
	this.parent = parent;
	this.anchorTarget = ( anchorTarget != null ) ? anchorTarget : null;

    this.itemLookup = {};
    this.descLookup = {};
    this.loadingLookup = {};
    this.personDescription = {};
    this.details = [];
    this.personListItems = [];
    
    this.starredPeople = {};
    this.starredObjects = {};
    
    this.personIcons = {};
    this.titleIcons = {};
    
    this.watchingObjects = [];
    this.hideNext = true;

	this.reader = reader;
	if ( this.reader != null )
	{
        if ( this.reader.params.exclude != null )
            this.reader.params.exclude = 'chats';
		var self = this;
		this.reader.callback = function( data )
		{
			self.data = data.items;
			self.update();
		}
	}
		
	this.data = [];
	this.width = width;
	this.height = height;
	this.today = new Date();
	
	if ( this.parent )
		this.place( this.parent );
}

LSNewsFeed.prototype.buildJavascript = function()
{
	var html = "";
	html += "new LSNewsFeed( ";
	html += this.reader.buildJavascript();
	html += ", null, ";
	html += ( this.width != null ) ? "+this.width+" : "null";
	html += ', ';
	html += ( this.height != null ) ? "+this.height+" : "null";
	html += ', ';
	html += ( this.containerID != null ) ? "'"+this.containerID+"'" : "null";
	html += ")";
	return html;
}

LSNewsFeed.prototype.getDataSource = function()
{
	return this.reader;
}

LSNewsFeed.prototype.onClick = function( tdNode )
{
	LSEvent.sendMessage( this, 'click', tdNode.data );
}

LSNewsFeed.prototype.add = function( entry )
{
	this.entries.push( entry );
}

LSNewsFeed.prototype.isValidItem = function( item )
{
    if ( item.ObjectType == 'Chat' ) return false;
    if ( item.ObjectType == 'WikiTopic' ) return false;
    var owner = this.getOwner( item );
    if ( owner == null ) return false;
    if ( owner.toString().length < 4 ) return false;
    return true;
}

LSNewsFeed.prototype.getOwner = function( item )
{
    if ( item.CustomerID != null )
        return item.CustomerID;
    return item.OwnerID;
}

LSNewsFeed.prototype.getMediaUrl = function( item )
{
    if ( item.ObjectType == 'Customer' || item.ObjectType == 'WikiEntry' ) return null;
    return item.MediaUrl;
}

LSNewsFeed.prototype.getObjectID = function( item ) {
    return item.link;
}

LSNewsFeed.prototype.onTitleStarClick = function( id ) {
    var objID = this.getObjectID( this.titleIcons[ id ] );

    this.watchObject( this.titleIcons[ id ] );

    for( var tid in this.titleIcons ) {
        var tdObj = document.getElementById( tid );
        tdObj.src = LSGlobals.imagePath+'/topic_'+(this.watchingObject(this.titleIcons[ tid ])?'on':'off')+'.png';
    }

    for( var ps in this.titleStars ) {
        this.titleStars[ps].star.style.fontWeight = this.watchingObject( this.titleStars[ps].item )?'bold':'';
    }
    
    this.updateWatchObjectList();
}

LSNewsFeed.prototype.onPersonListOver = function( elid )
{
    var id = (elid.split('_'))[1];
    var obj = document.getElementById( 'lsnewsfeedpersonitem_'+id );
    obj.style.display = 'block';
}

LSNewsFeed.prototype.onPersonListOut = function( elid )
{
    var id = (elid.split('_'))[1];
    var obj = document.getElementById( 'lsnewsfeedpersonitem_'+id );
    obj.style.display = 'none';
}

LSNewsFeed.prototype.setCustomerDescription = function( elDesc, desc )
{
    if ( desc != null && desc.length > 80 )
        desc = desc.substring( 0, 80 ).replace( /\s[^\s]*?$/, '...' );
    desc = desc.replace( /\s\s+/g, ' ' );
    desc = LSParseText( desc, false );
    elDesc.innerHTML = desc;
}

LSNewsFeed.prototype.updateWatchObjectList = function()
{
	while( this.elTWatching.childNodes.length > 0 )
		this.elTWatching.removeChild( this.elTWatching.childNodes.item( 0 ) );

    var typeRegistry = {};
    typeRegistry[ 'Customer' ] = { title: 'People', builder: new LSNewsFeedCustomerBuilder() };
    typeRegistry[ 'GroupDiscussionMessage' ] = { title: 'Discussions', builder: new LSNewsFeedRegularBuilder() };
    typeRegistry[ 'GroupFile' ] = { title: 'Files', builder: new LSNewsFeedRegularBuilder() };
    typeRegistry[ 'CustomerFile' ] = { title: 'Files', builder: new LSNewsFeedRegularBuilder() };
    typeRegistry[ 'WikiEntry' ] = { title: 'Wikis', builder: new LSNewsFeedRegularBuilder() };
    typeRegistry[ 'GroupMeeting' ] = { title: 'Meetings', builder: new LSNewsFeedRegularBuilder() };
    typeRegistry[ 'BlogPost' ] = { title: 'Blogs', builder: new LSNewsFeedRegularBuilder() };

    var self = this;
    var typeBuckets = {};

    for( var p in this.watchingObjects ) {
        var item = this.watchingObjects[ p ];
        if ( typeBuckets[ item.ObjectType ] == null )
            typeBuckets[ item.ObjectType ] = [];
        typeBuckets[ item.ObjectType ].push( item );
    }
    
    for( var bucket in typeRegistry ) {
        if ( typeBuckets[ bucket ] == null )
            continue;
           
        var elBRow = this.elTWatching.insertRow( -1 );
        var elBHeader = elBRow.insertCell( -1 );
        elBHeader.className = 'ls-newsfeeds-following-header';
        elBHeader.width = '100%';
        elBHeader.style.borderBottom = '1px solid #ccc';
        elBHeader.appendChild( document.createTextNode( typeRegistry[ bucket ].title ) );
 
        typeRegistry[bucket].builder.build( this, this.elTWatching, typeBuckets[ bucket ] );
    }

    this.elTTitle.style.display = ( this.watchingObjects.length > 0 ) ? 'block' : 'none';
    try {
        this.elTWatching.style.display = ( this.watchingObjects.length > 0 ) ? 'table' : 'none';
    } catch( e ) {
        this.elTWatching.style.display = ( this.watchingObjects.length > 0 ) ? 'block' : 'none';
    }
}

LSNewsFeed.prototype.watchingObject = function( item )
{
    var found = false;
    for( var o in this.watchingObjects ) {
        if ( this.watchingObjects[ o ] == item ) {
            found = true;
            break;
        }
    }
    return found;
}

LSNewsFeed.prototype.watchObject = function( item )
{
    var watchingObjects = [];
    var found = false;
    for( var o in this.watchingObjects ) {
        if ( this.watchingObjects[o] == item )
            found = true;
        else if ( this.watchingObjects[o].ObjectType.toString() == item.ObjectType.toString() &&
             this.watchingObjects[o].title.toString() == item.title.toString() )
            found = true;
        else
            watchingObjects.push( this.watchingObjects[o] );
    }
    if ( found == false )
        watchingObjects.push( item );
    this.watchingObjects = watchingObjects;
}

LSNewsFeed.prototype.setPersonDescription = function( person, divid )
{
    if ( this.personDescription[ person ] != null ) {
        var div = document.getElementById( divid );
        if ( div != null )
            this.setCustomerDescription( div, this.personDescription[ person ] );
    } else {
        this.personListItems.push( { person: person, divid: divid } );
        this.loadPersonDescription( person );
    }
}


LSNewsFeed.prototype.onPersonStarClick = function( id )
{
    var owner = this.getOwner( this.personIcons[ id ] );

    this.loadPersonDescription( owner );

    if ( this.starredPeople[ owner ] ) {
        var starPeople = {};
        for( var p in this.starredPeople )
            if ( p != owner ) starPeople[ p ] = true;
        this.starredPeople = starPeople;
    }
    else
        this.starredPeople[ owner ] = true;
  
    for( var pi in this.personIcons ) {
        var piOwner = this.getOwner( this.personIcons[pi] );
        var pIcon = document.getElementById( pi );
        pIcon.src = LSGlobals.imagePath+'/person_'+(this.starredPeople[piOwner]?'on':'off')+'.png';
    }
  
    for( var ps in this.personStars ) {
        var psOwner = this.getOwner( this.personStars[ps].item );
        this.personStars[ps].star.style.fontWeight = this.starredPeople[psOwner]?'bold':'';
    }

    this.watchObject( { ObjectType: 'Customer', title: owner } );
    this.updateWatchObjectList();
}

LSNewsFeed.prototype.addTitleOwner = function( elBase, item )
{
    var owner = this.getOwner( item );
   	var ownerUrl = LSGlobals.appUrl+'profile_view.aspx?CustomerID='+owner;
    
    var self = this;

    var elAnchor = document.createElement( 'a' );
    elAnchor.href = ownerUrl;
    if ( this.anchorTarget != null )
        elAnchor.target = this.anchorTarget;
    elAnchor.id = 'ls_newsfeed_star_'+LSGlobals.uniqueID;
    elAnchor.style.fontWeight = this.starredPeople[owner] ? 'bold' : '';
    elAnchor.appendChild( document.createTextNode( owner ) );
    elBase.appendChild( elAnchor );

    this.personStars[ elAnchor.id ] = {
        item:item,
        star:elAnchor
    };

    LSGlobals.uniqueID++;
}

LSNewsFeed.prototype.addTitleLink = function( elBase, item )
{
    var objID = this.getObjectID( item );
    var self = this;
    
    var elAnchor = document.createElement( 'a' );
    if ( this.anchorTarget != null )
        elAnchor.target = this.anchorTarget;
    elAnchor.id = 'ls_newsfeed_star_'+LSGlobals.uniqueID;
    elAnchor.href = item.link;
    elAnchor.innerHTML = item.title;
    if ( this.starredObjects[objID] )
        elAnchor.style.fontWeight = 'bold';
    elBase.appendChild( elAnchor );

    this.titleStars[ elAnchor.id ] = {
        item:item,
        star:elAnchor
    };

    LSGlobals.uniqueID++;
}

LSNewsFeed.prototype.addTitleText = function( elBase, title )
{
    var elTitleSpan = document.createElement( 'span' );
    elTitleSpan.className = 'ls-newsfeed-title';
    elTitleSpan.innerHTML = '&nbsp;'+title+'&nbsp;';
    elBase.appendChild( elTitleSpan );
}

LSNewsFeed.prototype.addTitle = function( elBase, item )
{
    if ( item.ObjectType == 'Customer' ) {
        this.addTitleLink( elBase, item );
        this.addTitleText( elBase, 'joined the community' );
    }
    this.addTitleOwner( elBase, item );
    if ( item.ObjectType == 'GroupDiscussionMessage' ) {
        this.addTitleText( elBase, 'posted to the discussion' );
    }
    if ( item.ObjectType == 'CustomerFile' ) {
        this.addTitleText( elBase, 'posted the file' );
    }
    if ( item.ObjectType == 'GroupFile' ) {
        this.addTitleText( elBase, 'posted the file' );
    }
    if ( item.ObjectType == 'BlogPost' ) {
        this.addTitleText( elBase, 'created a blog post' );
    }
    if ( item.ObjectType == 'WikiEntry' ) {
        this.addTitleText( elBase, 'edited the wiki page' );
    }
    if ( item.ObjectType == 'GroupMeeting' ) {
        this.addTitleText( elBase, 'scheduled a group meeting' );
    }
    this.addTitleLink( elBase, item );
}

LSNewsFeed.prototype.getPostTime = function( item )
{
    var oneDay = 1000*60*60*24;

    var itemd = item.date;
    if ( item.Created != null ) {
        itemd = new Date();
        itemd.setTime( Date.parse( item.Created[0] ) );
    }
    
    var mins = ( itemd.getMinutes() < 10 ) ? '0' + itemd.getMinutes().toString() : itemd.getMinutes().toString();
    var time = ( itemd.getHours() < 13 ) ? itemd.getHours() + ':' + mins + ' AM' : ( itemd.getHours() - 12 ) + ':' + mins + ' PM';

    var months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ];
    var year = ( itemd.getYear() < 1900 ) ? itemd.getYear() + 1900 : itemd.getYear();
    bucketName = months[ itemd.getMonth() ] + ' ' + itemd.getDate() + ', ' + year + ' ' + time;
    
    return bucketName;
}

LSNewsFeed.prototype.getBucket = function( item )
{
    var oneDay = 1000*60*60*24;

    var itemd = item.date;
    if ( item.Created != null ) {
        itemd = new Date();
        itemd.setTime( Date.parse( item.Created[0] ) );
    }

    var tdn = new Date( this.today.getYear(), this.today.getMonth(), this.today.getDate() );
    var idn = new Date( itemd.getYear(), itemd.getMonth(), itemd.getDate() );

    var diff = Math.ceil((tdn.getTime()-idn.getTime())/oneDay);
    var bucketValue = -1;
    var bucketName = '';
    if ( diff <= 1 ) { bucketName = 'Today'; bucketValue = 1; }
    else if ( diff <= 2 ) { bucketName = 'Yesterday'; bucketValue = diff; }
    else if ( diff <= 3 ) { bucketName = 'Two days ago'; bucketValue = diff; }
    else if ( diff <= 4 ) { bucketName = 'Three days ago'; bucketValue = diff; }
    else if ( diff <= 5 ) { bucketName = 'Four days ago'; bucketValue = diff; }
    else if ( diff <= 6 ) { bucketName = 'Five days ago'; bucketValue = diff; }
    else if ( diff <= 7 ) { bucketName = 'Six days ago'; bucketValue = diff; }
    else if ( diff <= 14 ) { bucketName = 'Last week'; bucketValue = 14; }
    else if ( diff <= 21 ) { bucketName = 'Two weeks ago'; bucketValue = 21; }
    else if ( diff <= 28 ) { bucketName = 'Three weeks ago'; bucketValue = 28; }
    else if ( diff <= 60 ) { bucketName = 'Last month'; bucketValue = 60; }
    else if ( diff <= 90 ) { bucketName = 'Two months ago'; bucketValue = 90; }
    else if ( diff <= 120 ) { bucketName = 'Up to six months ago'; bucketValue = 120; }
    else if ( diff <= 365 ) { bucketName = 'This year'; bucketValue = 365; }
    else if ( diff <= 780 ) { bucketName = 'Last year'; bucketValue = 780; }
    else if ( diff ) { bucketName = 'More than two years ago'; bucketValue = 781; }
    
    return { value:bucketValue, name:bucketName };
}

LSNewsFeed.prototype.onDescriptionData = function( customerID, data )
{
	if ( this.personDescription[ customerID ] != null )
		return;

	if ( data != null && data.items != null )
	{
		var desc = ( data.items.length > 0 ) ? data.items[0].description : '';
		this.personDescription[ customerID ] = desc;
		for( var k in this.itemLookup ) {
		    var owner = this.getOwner( this.itemLookup[ k ] );
		    if ( owner.toString() == customerID.toString() ) { 
                var elLoading = this.loadingLookup[ k ];
                elLoading.hide();
                this.loadingLookup[ k ] = null;
                
                this.descLookup[ k ].innerHTML = desc;
		    }
		}
		for( var i in this.personListItems ) {
		    if ( this.personListItems[i].person == customerID ) {
		        var div = document.getElementById( this.personListItems[i].divid );
		        if ( div != null )
                    this.setCustomerDescription( div, desc );
		    }
		}
	}
}

LSNewsFeed.prototype.loadPersonDescription = function( owner )
{
    if ( this.personDescription[ owner ] == null )
    {
        var self = this;
	    new LSCustomersGet( owner, function( data ) { self.onDescriptionData( owner, data ) } );
    }
}

LSNewsFeed.prototype.showPerson = function( id )
{
    var owner = this.getOwner( this.itemLookup[ id ] );
    
    var elDiv = this.descLookup[ id ];
    elDiv.style.visibility = 'visible';

    if ( this.personDescription[ owner ] == null )
    { 
        var elLoading = this.loadingLookup[ id ];
        if ( elLoading )
           elLoading.show();
        this.loadPersonDescription( owner );
    }   
}

LSNewsFeed.prototype.hidePerson = function( id )
{    
    var elLoading = this.loadingLookup[ id ];
    if ( elLoading ) elLoading.hide();

    var elDiv = this.descLookup[ id ];
    elDiv.style.visibility = 'hidden';
}

LSNewsFeed.prototype.isHidden = function( elDetail ) {
    if ( elDetail.style.display == null ||
         elDetail.style.display == '' ||
         elDetail.style.display == 'block' )
        return false;
    else
        return true;
}

LSNewsFeed.prototype.hideShowItem = function( elDetail, elButton, hide ) {
    if ( hide )
    {
        elDetail.style.display = 'none';
        elButton.src = LSGlobals.imagePath+'/tiny_open.png';
    }
    else
    {
        elDetail.style.display = 'block';
        elButton.src = LSGlobals.imagePath+'/tiny_close.png';
    }
}

LSNewsFeed.prototype.hideShowDetail = function( id ) {
    var divnum = (id.split( '_' ))[1];
    var detaildiv = document.getElementById( 'lsNewsFeedDetail_'+divnum );
    var elDetailButton = document.getElementById( id );
    this.hideShowItem( detaildiv, elDetailButton, !this.isHidden( detaildiv ) );
}

LSNewsFeed.prototype.onExpandToggle = function( )
{
    for( var i in this.details ) {
        this.hideShowItem( this.details[i].detail, this.details[i].button, this.hideNext );
    }
    this.hideNext = !this.hideNext;
}

LSNewsFeed.prototype.update = function()
{
    this.searchColumn.style.visibility = 'visible';
	this.loading.hide();

    this.details = [];
    this.personStars = {};
    this.titleStars = {};
    this.personIcons = {};
    this.titleIcons = {};
	
	while( this.tableBodyNode.childNodes.length > 0 )
		this.tableBodyNode.removeChild( this.tableBodyNode.childNodes.item( 0 ) );
    var elTrBuckets = this.tableNode.insertRow( -1 );
    var elTdBuckets = elTrBuckets.insertCell( -1 );
	elTdBuckets.style.padding = '3px 0px 3px 0px';

	var self = this;
	
	var buckets = {};
	var bucketValues = [];
	for( var e in this.data ) {
	    if ( this.isValidItem( this.data[e] ) )
	    {
    	    var bucket = this.getBucket( this.data[e] );
    	    if ( buckets[ bucket.value ] == null )
    	    {
    	        bucketValues.push( bucket.value );
                buckets[ bucket.value ] = { name: bucket.name, items: [] };
            }
            buckets[ bucket.value ].items.push( this.data[e] );
        }
	}
	
    bucketValues = bucketValues.sort( function(a,b) { return a-b; } );

    for( var b in bucketValues ) {
        var bv = bucketValues[b];
        var elH3BucketName = document.createElement( 'h3' );
        elH3BucketName.innerHTML = buckets[bv].name;
        elTdBuckets.appendChild( elH3BucketName );
        
        var elBucketTable = document.createElement( 'table' );
        elBucketTable.className = 'ls-newsfeeds-items';
        elBucketTable.width = '100%';
        elBucketTable.cellSpacing = 0;
        elBucketTable.cellPadding = 2;
        elBucketTable.style.padding = '0px';
        elBucketTable.style.width = '98%';
        elTdBuckets.appendChild( elBucketTable );

        var itemInd = 0;        
        for( var i in buckets[bv].items ) {
            var item = buckets[bv].items[i];
            
            var elTrItem = elBucketTable.insertRow( -1 );
            
            if ( ( itemInd % 2 ) == 1 )
                elTrItem.style.background = '#eeeeee';
            
            var owner = this.getOwner( item );
            var objID = this.getObjectID( item );
           	var ownerUrl = LSGlobals.appUrl+'profile_view.aspx?CustomerID='+owner;
        	var imgUrl = LSGlobals.appUrl+'photo.aspx?w=70&h=70&CustomerID='+owner;

            var elTdDesc = elTrItem.insertCell( -1 );
            if ( ( itemInd % 2 ) == 1 )
                elTdDesc.style.background = '#f5f5f5';
            elTdDesc.style.padding = '3px 0px 3px 0px';

            var uid = LSGlobals.uniqueID;
            var hideid = 'lsNewsFeedHide_'+uid;

            var visible = true;

            var elTitle = document.createElement( 'div' );
            elTitle.style.marginBottom = '10px';

            var elFlipImg = document.createElement( 'img' );
            elFlipImg.src = LSGlobals.imagePath+'/tiny_'+(visible?'close':'open')+'.png';
            elFlipImg.width = 9;
            elFlipImg.height = 9;
            elFlipImg.border = 0;
            elFlipImg.id = hideid;
            elFlipImg.onclick = function() { self.hideShowDetail( this.id ); }
            elFlipImg.style.margin = '0px 5px 0px 5px';

            elTitle.appendChild( elFlipImg );

            this.addTitle( elTitle, item );
            elTitle.appendChild( document.createTextNode( '  ' ) );

            elTdDesc.appendChild( elTitle );

            var detailid = 'lsNewsFeedDetail_'+uid;

            var elDetailDiv = document.createElement( 'div' );
            elDetailDiv.id = detailid;
            elDetailDiv.style.display = visible ? 'block' : 'none';
            elTdDesc.appendChild( elDetailDiv );
            
            this.details.push( { item: item,
                detail: elDetailDiv,
                button: elFlipImg } );

            LSGlobals.uniqueID++;

            var elTdImgDiv = document.createElement( 'div' );
            elTdImgDiv.style.cssFloat = 'left';
            elTdImgDiv.style.styleFloat = 'left';
            elTdImgDiv.style.width = '70px';
            elTdImgDiv.style.paddingRight = '5px';
            elTdImgDiv.style.marginLeft = '5px';
            elTdImgDiv.style.marginRight = '5px';
            elDetailDiv.appendChild( elTdImgDiv );

            var imgid = 'lsNewsFeed_'+LSGlobals.uniqueID;
            LSGlobals.uniqueID++;
            
            var elTdImgAnchor = document.createElement( 'a' );
            if ( this.anchorTarget != null )
                elTdImgAnchor.target = this.anchorTarget;
            elTdImgAnchor.href = ownerUrl;
            var elTdImgItem = document.createElement( 'img' );
            elTdImgItem.src = imgUrl;
            elTdImgItem.width = 70;
            elTdImgItem.height = 70;
            elTdImgItem.border = 0;
            elTdImgItem.id = imgid;
            elTdImgItem.style.border = '1px solid #ccc';
            elTdImgAnchor.appendChild( elTdImgItem );
            elTdImgDiv.appendChild( elTdImgAnchor );

            var elDescHost = document.createElement( 'div' );
            elDescHost.style.height = '2px';
            elDescHost.style.position = 'relative';
            elTdImgDiv.appendChild( elDescHost );

            var elDescDiv = document.createElement( 'div' );
            elDescDiv.style.position = 'absolute';
            elDescDiv.style.top = '0px';
            elDescDiv.style.visibility = 'hidden';
            elDescDiv.style.width = '150px';
            elDescDiv.style.border = '1px solid #ccc';
            elDescDiv.style.padding = '2px';
            elDescDiv.style.fontSize = '8pt';
            elDescDiv.style.background = 'white';
            elDescDiv.style.className = 'ls-newsfeed-person-description';
            elDescHost.appendChild( elDescDiv );

	        var elLoading = new LSLoadingGraphic();
	        elLoading.place( elDescDiv );
	        elLoading.hide();
            
            this.itemLookup[ imgid ] = item;
            this.descLookup[ imgid ] = elDescDiv;
            this.loadingLookup[ imgid ] = elLoading;

            elTdImgItem.onmouseover = function() { self.showPerson( this.id ); }
            elTdImgItem.onmouseout = function() { self.hidePerson( this.id ); }

            var mediaUrl = this.getMediaUrl( item );
            if ( mediaUrl != null ) {
                var elTdMediaAnchor = document.createElement( 'a' );
                if ( this.anchorTarget != null )
                    elTdMediaAnchor.target = this.anchorTarget;
                elTdMediaAnchor.href = item.link;
                elTdMediaAnchor.style.styleFloat = 'right';
                elTdMediaAnchor.style.cssFloat = 'right';

                mediaUrl = LSResizeImage( mediaUrl, 70, 70 );
		        mediaUrl = mediaUrl.replace( /&scaletype=(\w+)/, '' );
		        mediaUrl += '&scaletype=zoom';
                var elTdMediaImgItem = document.createElement( 'img' );
                elTdMediaImgItem.src = mediaUrl;
                elTdMediaImgItem.width = 70;
                elTdMediaImgItem.height = 70;
                elTdMediaImgItem.border = 0;
                elTdMediaImgItem.style.border = '1px solid #ccc';
                elTdMediaImgItem.style.marginRight = '5px';
                elTdMediaAnchor.appendChild( elTdMediaImgItem );
                elDetailDiv.appendChild( elTdMediaAnchor );
            }

            var desc = item.description;
	        if ( desc != null && desc.length > 240 )
		        desc = desc.substring( 0, 240 ).replace( /\s[^\s]*?$/, '...' );
            desc = desc.replace( /\s\s+/g, ' ' );
            desc = LSParseText( desc, false );
            var elSpan = document.createElement( 'span' );
            elSpan.className = 'ls-newsfeed-description';
            elSpan.innerHTML = desc;
            elDetailDiv.appendChild( elSpan );
            
            var elDateP = document.createElement( 'p' );
            elDateP.className = 'ls-newsfeed-date';

            elDateP.appendChild( document.createTextNode( this.getPostTime( item ) + ' ' ) );

            var elPersonImg = document.createElement( 'img' );
            elPersonImg.src = LSGlobals.imagePath+'/person_off.png';
            elPersonImg.width = 10;
            elPersonImg.alt = 'Follow this Person!';
            elPersonImg.height = 13;
            elPersonImg.border = 0;
            elPersonImg.id = 'lsnewsfeedpersonimg_'+LSGlobals.uniqueID;
            elPersonImg.style.marginLeft = '10px';
            elPersonImg.style.cursor = 'hand';
            elPersonImg.onmouseup = function() { self.onPersonStarClick( this.id.toString() ); }
            elDateP.appendChild( elPersonImg );
            this.personIcons[ elPersonImg.id.toString() ] = item;

            var elTopicImg = document.createElement( 'img' );
            elTopicImg.src = LSGlobals.imagePath+'/topic_off.png';
            elTopicImg.width = 11;
            elTopicImg.height = 13;
            elTopicImg.border = 0;
            elTopicImg.alt = 'Follow this Item!';
            elTopicImg.id = 'lsnewsfeedtopicimg_'+LSGlobals.uniqueID;
            elTopicImg.style.marginLeft = '5px';
            elTopicImg.style.cursor = 'hand';
            elTopicImg.onmouseup = function() { self.onTitleStarClick( this.id.toString() ); }
            elDateP.appendChild( elTopicImg );
            this.titleIcons[ elTopicImg.id.toString() ] = item;

            elDetailDiv.appendChild( elDateP );
            
            LSGlobals.uniqueID++;
            
            itemInd += 1;
        }
    }

	LSNotifySuccess();
}

LSNewsFeed.prototype.onSearchClick = function()
{
    this.searchColumn.style.visibility = 'visible';
	this.loading.show();
	
	while( this.tableBodyNode.childNodes.length > 0 )
		this.tableBodyNode.removeChild( this.tableBodyNode.childNodes.item( 0 ) );
	
	var count = 10;
	if ( this.reader.params.count != null )
	    count = this.reader.params.count;
	
	this.reader = new LSAllGetAll( { exclude:this.reader.params.exclude, keyword: this.elSearchText.value, sort:'accessdate', count:count } );
	this.rssAnchor.href = this.reader.getRDFUrl();
	var self = this;
	this.reader.callback = function( data )
	{
		self.data = data.items;
		self.update();
	}
	this.reader.start();
}

LSNewsFeed.prototype.place = function( parent )
{
	if ( parent == null )
		parent = document.body;
	else
		parent.innerHTML = '';

	this.container = document.createElement( 'div' );
	if ( this.containerID != null )
		this.container.id = this.containerID;

    var columnsTable = document.createElement( 'table' );
	columnsTable.cellSpacing = '0';
	columnsTable.cellPadding = '0';
	columnsTable.style.padding = '0px';
	columnsTable.style.margin = '0px';
	columnsTable.width = '100%';
	columnsTable.className = 'ls-newsfeed-container';

    var elTrColumn = columnsTable.insertRow( -1 );
    var elTdColumn1 = elTrColumn.insertCell( -1 );
    elTdColumn1.vAlign = 'top';
    elTdColumn1.width = '80%';
    elTdColumn1.style.padding = '0px';

    var self = this;

    var elExpandDiv = document.createElement( 'div' );
    elExpandDiv.className = 'ls-newsfeed-expand';
    elExpandDiv.appendChild( document.createTextNode( 'Expand/Collapse All ' ) );

    var elExpandImg = document.createElement( 'img' );
    elExpandImg.onclick = function() { self.onExpandToggle(); }
    elExpandImg.style.cursor = 'hand';
    elExpandImg.src = LSGlobals.imagePath+'/tiny_both.png';
    elExpandImg.width = 19;
    elExpandImg.height = 9;
    elExpandDiv.appendChild( elExpandImg );

    elTdColumn1.appendChild( elExpandDiv );
	
	this.loading = new LSLoadingGraphic();
	this.loading.place( elTdColumn1 );

	this.tableNode = document.createElement( 'table' );
	this.tableNode.cellSpacing = '0';
	this.tableNode.cellPadding = '0';
	this.tableNode.className = 'ls-newsfeed';
	this.tableNode.width = '100%';
	this.tableNode.style.marginLeft = '0px';
	this.tableNode.style.marginRight = '0px';
	this.tableNode.style.padding = '0px';
	elTdColumn1.appendChild( this.tableNode );

	this.container.appendChild( columnsTable );

    this.searchColumn = elTrColumn.insertCell( -1 );
    this.searchColumn.vAlign = 'top';
    this.searchColumn.style.visibility = 'hidden';
    this.searchColumn.width = '20%';
    this.searchColumn.style.padding = '0px';

    this.elPWatching = document.createElement( 'table' );
    this.elPWatching.className = 'ls-newsfeeds-people';
    this.elPWatching.style.display = 'none';
    this.elPWatching.style.margin = '0px 0px 10px 0px';
    this.elPWatching.width = '100%';
    this.searchColumn.appendChild( this.elPWatching );

    this.elTTitle = document.createElement( 'div' );
    this.elTTitle.className = 'ls-newsfeeds-imfollowing';
    this.elTTitle.style.display = 'none';
    this.elTTitle.width = '100%';
    this.elTTitle.appendChild( document.createTextNode( "I'm following" ) );
    this.searchColumn.appendChild( this.elTTitle );

    this.elTWatching = document.createElement( 'table' );
    this.elTWatching.className = 'ls-newsfeeds-topics';
    this.elTWatching.style.display = 'none';
    this.elTWatching.style.margin = '0px 0px 10px 0px';
    this.elTWatching.width = '100%';
    this.searchColumn.appendChild( this.elTWatching );
    
    var elKeywordP = document.createElement( 'p' );
    elKeywordP.className = 'ls-newsfeed-search-text';
    elKeywordP.style.fontSize = '10pt';
    elKeywordP.appendChild( document.createTextNode( 'Find activity by keyword' ) );
    this.searchColumn.appendChild( elKeywordP );

    var elSeparateP = document.createElement( 'p' );
    elSeparateP.className = 'ls-newsfeed-separated-text';
    elSeparateP.style.fontSize = '8pt';
    elSeparateP.style.marginTop = '10px';
    elSeparateP.style.marginBottom = '10px';
    elSeparateP.appendChild( document.createTextNode( 'Separate keywords by commas:' ) );
    this.searchColumn.appendChild( elSeparateP );

    var elTextP = document.createElement( 'p' );
    this.elSearchText = document.createElement( 'input' );
    this.elSearchText.type = 'text';
    elTextP.appendChild( this.elSearchText );
    this.searchColumn.appendChild( elTextP );

    var elButtonP = document.createElement( 'p' );
    var elSubmitButton = document.createElement( 'button' );
    elSubmitButton.onclick = function() { self.onSearchClick(); }
    elSubmitButton.appendChild( document.createTextNode( 'Refresh' ) );
    elButtonP.appendChild( elSubmitButton );
    this.searchColumn.appendChild( elButtonP );
	
    var elRssP = document.createElement( 'p' );
    elRssP.style.textAlign = 'right';
   
    this.rssAnchor = document.createElement( 'a' );
    if ( this.anchorTarget != null )
        this.rssAnchor.target = this.anchorTarget;
    
	var elRssImage = document.createElement( 'img' );
	elRssImage.src = LS_FixLink(LSGlobals.imagePath + '/rss.jpg');
	elRssImage.border = '0';
	this.rssAnchor.appendChild( elRssImage );
	elRssP.appendChild( this.rssAnchor );
    this.searchColumn.appendChild( elRssP );
	
	this.rssAnchor.href = this.reader.getRDFUrl();
	
	this.tableBodyNode = document.createElement( 'tbody' );
	this.tableNode.appendChild( this.tableBodyNode );
	
	parent.appendChild( this.container );

	this.reader.start();
} 


function LSGetPoweredBy()
{
	return ( LSGlobals.poweredBy != null ) ? LSGlobals.poweredBy : 'Powered by <a href="http://leveragesoftware.com">Leverage Software</a>';
}

function LSSetPoweredBy( str )
{
	LSGlobals.poweredBy = str;
}

function LS_onContent(callback){
    if ( LSGlobals.onLoadedFired ) callback();
    else LSEvent.addEventListener( window, 'load', callback );
};

if ( LSStartup )
{
LSGlobals.data.startPreload();

LSGlobals.data.endPreload();
}

