joms = {
	apps: {
		windowTitle: '',
		toggle: function (id){
			jQuery(id).children('.app-box-actions').slideToggle('fast');
			jQuery(id).children('.app-box-footer').slideToggle('fast');
			jQuery(id).children('.app-box-content').slideToggle('fast',
				function() {
					jQuery(id).toggleClass('collapse', (jQuery(this).css('display')=='none'));
				}
			);
		},
		showAboutWindow: function(appName){
			var ajaxCall = "jax.call('community', 'apps,ajaxShowAbout', '"+appName+"');";
			cWindowShow(ajaxCall, '' , 450, 200);
		},
		showPrivacyWindow: function(appName){
			var ajaxCall = "jax.call('community', 'apps,ajaxShowPrivacy', '"+appName+"');";
			cWindowShow(ajaxCall, '' , 450, 300);
		},
		showSettingsWindow: function(id, appName){
			var ajaxCall = "jax.call('community', 'apps,ajaxShowSettings', '"+id+"', '"+appName+"');";
			cWindowShow(ajaxCall, '', 450, 300);
		},
		savePrivacy: function(){
			var value   = jQuery('input[name=privacy]:checked').val();
			var appName = jQuery('input[name=appname]').val();
			jax.call('community', 'apps,ajaxSavePrivacy', appName, value);
		},
		saveSettings: function(){
			jax.call('community', 'apps,ajaxSaveSettings', jax.getFormValues('appSetting'));
		},
		remove: function(appName){
			var ajaxCall = "jax.call('community', 'apps,ajaxRemove', '"+appName+"');";
			cWindowShow(ajaxCall, this.windowTitle , 450, 100);	
		},
		add: function(appName){
			var ajaxCall = "jax.call('community', 'apps,ajaxAdd', '"+appName+"');";
			cWindowShow(ajaxCall, '', 450, 100);
		}
	},
	report: {
		emptyMessage: '',
		
		checkReport: function(){
			if( jQuery( '#report-message' ).val() == '' )
			{
				jQuery( '#report-message-error' ).html( this.emptyMessage ).css( 'color' , 'red' );
				return false;
			}
			return true;
		},
		showWindow: function ( reportFunc, arguments ){
			var ajaxCall	= 'jax.call("community" , "system,ajaxReport" , "' + reportFunc + '","' + location.href + '" ,' + arguments + ');';
			cWindowShow(ajaxCall, '', 450, 300);
		},
		submit: function ( reportFunc , pageLink , arguments ){
			if( joms.report.checkReport() )
			{
				var message	= escape( jQuery('#report-message').val() );
				var ajaxcall='jax.call("community", "system,ajaxSendReport","' + reportFunc + '","' + pageLink + '","' + message + '" , ' + arguments + ')';
				cWindowShow(ajaxcall, '', 450, 300);
			}
		}
	},
	flash: {
		enabled: function(){
			// ie 
			try
			{ 
				try
				{
					// avoid fp6 minor version lookup issues 
					// see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/ 
					var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6'); 
					try
					{ 
						axo.AllowScriptAccess = 'always'; 
					} 
					catch(e)
					{
						return '6,0,0';
					} 
				}
				catch(e)
				{
				}
				return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1]; 
			// other browsers 
			}
			catch(e)
			{ 
				try
				{ 
					if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)
					{ 
						return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]; 
					} 
				}
				catch(e)
				{
				} 
			}		
			return false; 
		}
	},
	notifications: {
		showWindow: function (){
			var ajaxCall = 'jax.call("community", "notification,ajaxGetNotification", "")';
			cWindowShow(ajaxCall, 'Notification', 450, 350);
		},
		updateNotifyCount: function (){
			var notifyCount	= jQuery('#toolbar-item-notify-count').text();
			
			if(jQuery.trim(notifyCount) != '' && notifyCount > 0)
			{
				//first we update the count. if the updated count == 0, then we hide the tab.
				notifyCount = notifyCount - 1;
				jQuery('#toolbar-item-notify-count').html(notifyCount);
				if (notifyCount == 0)
				{
					jQuery('#toolbar-item-notify').hide();
				}				
			}			
		}
	},
	filters:{
		bind: function(){
			var loading	= this.loading;
			
			jQuery(document).ready( function() 
			{
				//sorting option binding for members display
				jQuery('.newest-member').bind('click', function() {
				    if ( !jQuery(this).hasClass('active-state') ) {
				        loading( jQuery(this).attr('class') );
						jax.call('community', 'frontpage,ajaxGetNewestMember', frontpageUsers);
					}
				});
				jQuery('.active-member').bind('click', function() {
				    if ( !jQuery(this).hasClass('active-state') ) {
			            loading( jQuery(this).attr('class') );
						jax.call('community', 'frontpage,ajaxGetActiveMember', frontpageUsers);
					}
				});
				jQuery('.popular-member').bind('click', function() {
				    if ( !jQuery(this).hasClass('active-state') ) {
				        loading( jQuery(this).attr('class') );
				    	jax.call('community', 'frontpage,ajaxGetPopularMember', frontpageUsers);
					}
				});
					
				//sorting option binding for activity stream
				jQuery('.all-activity').bind('click', function() {
				    if ( !jQuery(this).hasClass('active-state') ) {
			            loading( jQuery(this).attr('class') );
						jax.call('community', 'frontpage,ajaxGetActivities', 'all');
					}
				});
				jQuery('.me-and-friends-activity').bind('click', function() {
				    if ( !jQuery(this).hasClass('active-state') ) {
				        loading( jQuery(this).attr('class') );
				    	jax.call('community', 'frontpage,ajaxGetActivities', 'me-and-friends');
					}
				});
				jQuery('.active-profile-and-friends-activity').bind('click', function() {
				    if ( !jQuery(this).hasClass('active-state') ) {
				        loading( jQuery(this).attr('class') );
				    	jax.call('community', 'frontpage,ajaxGetActivities', 'active-profile-and-friends');
					}
				});	
				jQuery('.active-profile-activity').bind('click', function() {
				    if ( !jQuery(this).hasClass('active-state') ) {
				        loading( jQuery(this).attr('class') );
				    	jax.call('community', 'frontpage,ajaxGetActivities', 'active-profile');
					}
				});	
				
				// remove last link border
				jQuery('.popular-member').css('border-right', '0').css('padding-right', '0');
				jQuery('.me-and-friends-activity').css('border-right', '0').css('padding-right', '0');
				jQuery('.active-profile-activity').css('border-right', '0').css('padding-right', '0');
			});
		},
		loading: function(element){
			elParent = jQuery('.'+element).parent().parent().attr('id');
			if ( elParent === '' ) {
		        elParent = jQuery('.'+element).parent().attr('id');
			}
		    jQuery('#' + elParent + ' .loading').show();
		    jQuery('#' + elParent + ' a').removeClass('active-state');
		    jQuery('.'+element).addClass('active-state');
		},
		hideLoading: function(){
			jQuery( '.loading' ).hide();
		}
	},
	groups: {
		addInvite: function( element ){
			var parentId = jQuery('#' +element).parent().attr('id');
	
			if(parentId == "friends-list")
			{
				jQuery("#friends-invited").append(jQuery('#' +element)).html();
			}
			else
			{
				jQuery("#friends-list").append(jQuery('#' +element)).html();
			}
		},
		removeTopic: function( title , groupid , topicid ){
			var ajaxCall	= 'jax.call("community","groups,ajaxShowRemoveDiscussion", "' + groupid + '","' + topicid + '");';
			cWindowShow( ajaxCall , title , 450 , 150 );
		},
		editBulletin: function(){
			
			if( jQuery('#bulletin-data').css('display') == 'none' )
			{
				jQuery('#bulletin-data').show();
				jQuery('#bulletin-edit-data').hide();
			}
			else
			{
				jQuery('#bulletin-data').hide();
				jQuery('#bulletin-edit-data').show();
			}

		},
		removeBulletin: function( title , groupid , bulletinid ){
			var ajaxCall	= 'jax.call("community","groups,ajaxShowRemoveBulletin", "' + groupid + '","' + bulletinid + '");';
			cWindowShow( ajaxCall , title , 450 , 150 );
		},
		unpublish: function( groupId ){
			jax.call( 'community' , 'groups,ajaxUnpublishGroup' , groupId );
		},
		leave: function( groupid ){
			var ajaxCall	= 'jax.call("community" , "groups,ajaxShowLeaveGroup" , "' + groupid + '");';
			cWindowShow( ajaxCall , '' , 450 , 170 );
		},
		joinWindow: function( groupid ){
			var ajaxCall	= 'jax.call("community" , "groups,ajaxShowJoinGroup" , "' + groupid + '", location.href );';
			cWindowShow( ajaxCall , '' , 450 , 170 );
		},
		edit: function(){
			// Check if input is already displayed
			jQuery('#community-group-info .cdata').each(function(){
				// Test if the next div is cinput
	
				if(jQuery(this).next().html() && jQuery(this).css('display') != 'none' )
					jQuery(this).css('display' , 'none');
				else
					jQuery(this).css('display' , 'block');
			});
	
			jQuery('#community-group-info .cinput').each(function(){
				if(jQuery(this).css('display') == 'none')
					jQuery(this).css('display' , 'block');
				else
					jQuery(this).css('display' , 'none');
			});
	
			if(jQuery('div#community-group-info-actions').css('display') != 'none')
				jQuery('div#community-group-info-actions').css('display' , 'none');
			else
				jQuery('div#community-group-info-actions').css('display' , 'block');
		},
		save: function( groupid ){
			var name		= jQuery('#community-group-name').val();
			var description	= jQuery('#community-group-description').val();
			var website		= jQuery('#community-group-website').val();
			var category	= jQuery('#community-group-category').val();
			var approvals	= jQuery("input[@name='group-approvals']:checked").val();
			
			jax.call('community' , 'groups,ajaxSaveGroup' , groupid , name , description , website , category , approvals);
		},
		update: function( groupName , groupDescription , groupWebsite , groupCategory){
			// Re-update group data
			jQuery('#community-group-data-name').html( groupName );
			jQuery('#community-group-data-description').html( groupDescription );
			jQuery('#community-group-data-website').html( groupWebsite );
			jQuery('#community-group-data-category').html( groupCategory );
			this.edit();
		},
		removeMember: function( memberId , groupId ){
			jax.call('community' , 'groups,ajaxRemoveMember' , memberId , groupId );
		},
		deleteGroup: function( groupId ){
			var ajaxCall = "jax.call('community', 'groups,ajaxWarnGroupDeletion', '" + groupId + "');";	
			cWindowShow(ajaxCall, 'Delete Group', 450, 200);
			//jax.call( 'community' , 'groups,ajaxUnpublishGroup' , groupId );
		}
	},
	friends: {
		saveTag: function(){
			var formVars = jax.getFormValues('tagsForm');
			jax.call("community", "friends,ajaxFriendTagSave", formVars);
			return false;
		},
		saveGroup: function(userid) {
			if(document.getElementById('newtag').value == ''){
			    window.alert('TPL_DB_INVALIDTAG');
			}else{
				jax.call("community", "friends,ajaxAddGroup",userid,jQuery('#newtag').val());
			}
		},
		cancelRequest: function( friendsId ){
			var ajaxCall	= 'jax.call("community" , "friends,ajaxCancelRequest" , "' + friendsId + '");';
			cWindowShow(ajaxCall, 'Cancel Friend Request', 450, 100);	
		},
		connect: function( friendid ){
			var ajaxCall = 'jax.call("community", "friends,ajaxConnect", '+friendid+')';
			cWindowShow(ajaxCall, 'Add new friend', 450, 200);
		},
		addNow: function(){
		 	var formVars = jax.getFormValues('addfriend');
		 	jax.call("community", "friends,ajaxSaveFriend",formVars);
		 	return false;
		}
	},
	messaging: {
		loadComposeWindow: function(userid){
			var ajaxCall = 'jax.call("community", "inbox,ajaxCompose", '+userid+')';
			cWindowShow(ajaxCall, '', 450, 300);
		},
		send: function(){
			var formVars = jax.getFormValues('writeMessageForm');
			jax.call("community", "inbox,ajaxSend", formVars);
			return false;
		}
	},
	walls: {
		add: function ( uniqueId, addFunc ){

			jax.loadingFunction = function()
			{
				jQuery('#wall-message').attr('disabled', true);
				jQuery('#wall-submit').attr('disabled', true);
			}
		
			jax.doneLoadingFunction = function()
			{
				jQuery('#wall-message').attr('disabled', false);
				jQuery('#wall-submit').attr('disabled', false);
			};
			
			if(typeof getCacheId == 'function')
			{
				cache_id = getCacheId();
			}
			else
			{
				cache_id = "";
			}		
			
			jax.call('community', addFunc, jQuery('#wall-message').val(), uniqueId, cache_id);
		},	
		insert: function( html ){
			jQuery('#wall-message').val('');
			jQuery('#wallContent').prepend(html);	
		},
		remove: function( type , wallId , contentId ){
			if(confirm('Are you sure you want to delete this wall?'))
			{
				jax.call('community' , type + ',ajaxRemoveWall' , wallId , contentId );
				jQuery('#wall_' + wallId ).fadeOut('normal', function(){jQuery(this).remove()});
				
				// Process ajax calls
			}
		}
	},
	toolbar: {
		timeout: 500,
		closetimer: 0,
		ddmenuitem: 0,
		open: function( id ){
			
			if ( jQuery('#'+id).length > 0 ) { 
				// cancel close timer
				joms.toolbar.cancelclosetime();
			
				// close old layer
				if(joms.toolbar.ddmenuitem)
				{
					joms.toolbar.ddmenuitem.style.visibility = 'hidden';
				}
			
				// get new layer and show it
				joms.toolbar.ddmenuitem = document.getElementById(id);
				joms.toolbar.ddmenuitem.style.visibility = 'visible';
			}				
		},
		close: function(){
			if(joms.toolbar.ddmenuitem)
			{
				joms.toolbar.ddmenuitem.style.visibility = 'hidden';
			}
		},
		closetime: function(){
			joms.toolbar.closetimer	= window.setTimeout( joms.toolbar.close , joms.toolbar.timeout );
		},
		cancelclosetime: function(){
			if( joms.toolbar.closetimer )
			{
				window.clearTimeout( joms.toolbar.closetimer );
				joms.toolbar.closetimer = null;
			}
		}
	},
	registrations:{
		windowTitle: '',
		showTermsWindow: function(){
			var ajaxCall = 'jax.call("community", "register,ajaxShowTnc", "")';
			cWindowShow(ajaxCall, this.windowTitle , 600, 350);
		},
		authenticate: function(){
			jax.call("community", "register,ajaxGenerateAuthKey");
		},
		authenticateAssign: function(){
			jax.call("community", "register,ajaxAssignAuthKey");
		},		
		assignAuthKey: function(fname, lblname, authkey){
			eval("document.forms['" + fname + "'].elements['" + lblname + "'].value = '" + authkey + "';");
		},
		showWarning: function(message) {			
			cWindowShow('jQuery(\'#cWindowContent\').html(\''+message+'\')' , 'Notice' , 450 , 200 , 'warning');		
		}		
	},
	comments:{
		add: function(id){			
			var cmt = jQuery('#'+ id +' textarea').val();
			if(cmt != '') {
				jQuery('#'+ id +' .wall-coc-form-action.add').attr('disabled', true);
				if(typeof getCacheId == 'function')
				{
					cache_id = getCacheId();
				}
				else
				{
					cache_id = "";
				}
				jax.call("community", "plugins,walls,ajaxAddComment", id, cmt, cache_id);
			}
		},
		insert: function(id, text){
			jQuery('#'+ id +' form').before(text);
			joms.comments.cancel(id);
		},
		remove: function(obj){
			var cmtDiv = jQuery(obj).parents('.wallcmt');
			var index  = jQuery(obj).parents('.wallcmt').parent().children().index(cmtDiv);
			try{ console.log(index); } catch(err){}
			var parentId = jQuery(obj).parents('.wallcmt').parent().attr('id');
			try{ console.log(parentId); } catch(err){}
			//jQuery(obj).parent('.wallcmt').remove();		
			
			jax.call("community", "plugins,walls,ajaxRemoveComment", parentId, index);
		},
		cancel: function(id){
			jQuery('#'+ id +' textarea').val('');
			jQuery('#'+ id +' form').hide();
			jQuery('#'+ id +' .show-cmt').show();
			jQuery('#'+ id + ' .wall-coc-errors').hide();
		},
		show: function(id){
			var w = jQuery('#'+ id +' form').parent().width();
			try{ console.log(w); } catch(err){}
			jQuery('#'+ id +' textarea').width(w);
			jQuery('#'+ id +' .wall-coc-form-action.add').attr('disabled', false);
			jQuery('#'+ id +' form').width(w).show();
			jQuery('#'+ id +' .show-cmt').hide();
			
			// Need to reduce the textarea with, taking into accoutn of border and margin
			// the form need to be show first before we can calculate the correct size
			var ow = jQuery('#'+ id +' textarea').outerWidth(true);
			try{ console.log(ow); } catch(err){}

			// Bind the textarea to autogrow func
			joms.utils.autogrow('#'+ id +' textarea');
			
			// Hide the comment form if textarea IS empty and lose focus
			jQuery('#'+ id +' textarea').width(w - (ow - w)).blur(function(){
				var cmt = jQuery('#'+ id +' textarea').val();
				if(cmt == ''){
					joms.comments.cancel(id);
				}
			});
			
		}
	},
	utils: {
		// Resize the width of the giventext to follow the innerWidth of 
		// another DOM object
		// The textarea must be visible
		textAreaWidth: function(target){
			/*
			Rev 1
			var w = jQuery(followId).width();
			try{ console.log(w); } catch(err){}
			jQuery(textareaId).width(w);
			
			// Need to reduce the textarea with, taking into account of border and margin
			// the form need to be show first before we can calculate the correct size
			var ow = jQuery(textareaId).outerWidth(true);
			try{ console.log(ow); } catch(err){}
			jQuery(textareaId).width(w - (ow - w));
			*/

			/*
			Rev 2
			if (source==undefined)
				source = jQuery(target).parent();
				
			w  = jQuery(source).width() - (jQuery(target).outerWidth(true) - jQuery(target).width());
			
			jQuery(target).width(w);
			*/
			
			with (jQuery(target))
			{
				css('width', '100%');
				width(width() * 2 - outerWidth(true));
			}
		},
		
		autogrow: function (id, params){
			// Bind the textarea to autogrow func
			var lineHeight = parseFloat(jQuery(id).css('line-height').replace(/[^0-9]/g, ''));
			
			if(params==undefined)
				params = {maxHeight: 300, minHeight: (lineHeight*2), lineHeight: lineHeight};
			
			jQuery(id).height(params.minHeight).autogrow(params);
		}
	},
	connect: {
		// Displays popup that requires user to update their details upon 
		update: function(){
			var ajaxCall = "jax.call('community', 'connect,ajaxUpdate' );";
			cWindowShow(ajaxCall, '', 450, 200);
		},
		mergeNotice: function(){
			var ajaxCall = "jax.call('community','connect,ajaxMergeNotice');";
			cWindowShow(ajaxCall, '', 450, 200);
		},
		merge: function(){
			var ajaxCall = "jax.call('community','connect,ajaxMerge');";
			cWindowShow(ajaxCall, '', 450, 200);
		}
	},
	
	// Video component
	videos: {
		showEditWindow: function(id){		
			var ajaxCall = "jax.call('community', 'videos,ajaxEditVideo', '"+id+"');";
			cWindowShow(ajaxCall, '' , 450, 400);		
		},		
		deleteVideo: function(videoId){
			var ajaxCall = "jax.call('community' , 'videos,ajaxRemoveVideo', '" + videoId + "','myvideos');";
			cWindowShow(ajaxCall, '', 450, 150);
		},
		playerConf: {
			// Default flowplayer configuration here
		},
		addVideo: function() {
			var ajaxCall = "jax.call('community', 'videos,ajaxAddVideo', '');";
			cWindowShow(ajaxCall, '', 500, 330);
		},
		linkVideo: function() {
			var ajaxCall = "jax.call('community', 'videos,ajaxLinkVideo', '');";
			cWindowShow(ajaxCall, '', 450, 220);
		},
		uploadVideo: function() {
			var ajaxCall = "jax.call('community', 'videos,ajaxUploadVideo', '');";
			cWindowShow(ajaxCall, '', 450, 400);
		},
		submitLinkVideo: function() {
			var isValid = true;
			
			videoLinkUrl = "#linkVideo input[name='videoLinkUrl']";
			if(jQuery.trim(jQuery(videoLinkUrl).val())=='')
			{
				jQuery(videoLinkUrl).addClass('invalid');
				isValid = false;
			}
			else
			{
				jQuery(videoLinkUrl).removeClass('invalid');
			}
			
			if (isValid)
			{
				jQuery('#cwin-wait').css("margin-left","20px");
				jQuery('#cwin-wait').show();
				
				document.linkVideo.submit();
			}
		},
		submitUploadVideo: function() {
			var isValid = true;
			
			videoFile = "#uploadVideo input[name='videoFile']";

			if(jQuery.trim(jQuery(videoFile).val())=='')
			{
				jQuery(videoFile).addClass('invalid');
				isValid = false;
			}
			else
			{
				jQuery(videoFile).removeClass('invalid');
			}
			
			videoTitle = "#uploadVideo input[name='title']";
			if(jQuery.trim(jQuery(videoTitle).val())=='')
			{
				jQuery(videoTitle).addClass('invalid');
				isValid = false;
			}
			else
			{
				jQuery(videoTitle).removeClass('invalid');
			}

			if (isValid)
			{
				jQuery('#cwin-wait').css("margin-left","20px");
				jQuery('#cwin-wait').show();
				
				document.uploadVideo.submit();
			}
		}
	},
	users: {
		blockUser: function( userId , isBlocked ){
			var ajaxCall = "jax.call('community', 'profile,ajaxBlockUser', '" + userId + "' , '" + isBlocked + "');";
			cWindowShow(ajaxCall, '', 450, 400);
		},
		removePicture: function( userId ){
			var ajaxCall = "jax.call('community', 'profile,ajaxRemovePicture', '" + userId + "');";
			cWindowShow(ajaxCall, '', 450, 400);
		}
	}
}

// close layer when click-out
jQuery(document).click( function() {
    joms.toolbar.close();
});

/* 
 * Auto Expanding Text Area (1.2.2)
 * by Chrys Bader (www.chrysbader.com)
 * chrysb@gmail.com
 *
 * Special thanks to:
 * Jake Chapa - jake@hybridstudio.com
 * John Resig - jeresig@gmail.com
 *
 * Copyright (c) 2008 Chrys Bader (www.chrysbader.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 *
 * NOTE: This script requires jQuery to work.  Download jQuery at www.jquery.com
 *
 */
 
(function(jQuery) {
		  
	var self = null;
 
	jQuery.fn.autogrow = function(o)
	{	
		return this.each(function() {
			new jQuery.autogrow(this, o);
		});
	};
	

    /**
     * The autogrow object.
     *
     * @constructor
     * @name jQuery.autogrow
     * @param Object e The textarea to create the autogrow for.
     * @param Hash o A set of key/value pairs to set as configuration properties.
     * @cat Plugins/autogrow
     */
	
	jQuery.autogrow = function (e, o)
	{
		this.options		  	= o || {};
		this.dummy			  	= null;
		this.interval	 	  	= null;
		this.line_height	  	= this.options.lineHeight || parseInt(jQuery(e).css('line-height'));
		this.min_height		  	= this.options.minHeight || parseInt(jQuery(e).css('min-height'));
		this.max_height		  	= this.options.maxHeight || parseInt(jQuery(e).css('max-height'));;
		this.textarea		  	= jQuery(e);
		
		if(this.line_height == NaN)
		  this.line_height = 0;
		
		// Only one textarea activated at a time, the one being used
		this.init();
	};
	
	jQuery.autogrow.fn = jQuery.autogrow.prototype = {
    autogrow: '1.2.2'
  };
	
 	jQuery.autogrow.fn.extend = jQuery.autogrow.extend = jQuery.extend;
	
	jQuery.autogrow.fn.extend({
						 
		init: function() {			
			var self = this;			
			this.textarea.css({overflow: 'hidden', display: 'block'});
			this.textarea.unbind('focus').unbind('blur');
			this.textarea.bind('focus', function() { self.startExpand() } ).bind('blur', function() { self.stopExpand() });
			this.checkExpand();	
		},
						 
		startExpand: function() {				
		  var self = this;
			this.interval = window.setInterval(function() {self.checkExpand()}, 400);
		},
		
		stopExpand: function() {
			clearInterval(this.interval);	
		},
		
		checkExpand: function() {
			
			if (this.dummy == null)
			{
				this.dummy = jQuery('<div></div>');
				this.dummy.css({
								'font-size'  : this.textarea.css('font-size'),
								'font-family': this.textarea.css('font-family'),
								'width'      : this.textarea.css('width'),
								'padding'    : this.textarea.css('padding'),
								'line-height': this.line_height + 'px',
								'overflow-x' : 'hidden',
								'position'   : 'absolute',
								'top'        : 0,
								'left'		 : -9999
								}).appendTo('body');
			}
			
			// Strip HTML tags
			var html = this.textarea.val().replace(/(<|>)/g, '');
			
			// IE is different, as per usual
			if (jQuery.browser.msie)
			{
				html = html.replace(/\n/g, '<BR>new');
			}
			else
			{
				html = html.replace(/\n/g, '<br>new');
			}
			
			if (this.dummy.html() != html)
			{
				this.dummy.html(html);	
				
				if (this.max_height > 0 && (this.dummy.height() + this.line_height > this.max_height))
				{
					this.textarea.css('overflow-y', 'auto');	
				}
				else
				{
					this.textarea.css('overflow-y', 'hidden');
					if (this.textarea.height() < this.dummy.height() + this.line_height || (this.dummy.height() < this.textarea.height()))
					{	
						this.textarea.animate({height: (this.dummy.height() + this.line_height) + 'px'}, 60);	
					}
				}
			}
		}
						 
	 });
})(jQuery);