joms = {
	activities: {
		getContent: function( activityId ){
				jax.call('community' , 'activities,ajaxGetContent' , activityId );
		},
		setContent: function( activityId , content ){
			jQuery("#profile-newsfeed-item-content-" + activityId ).html( content );
			jQuery("#profile-newsfeed-item-content-" + activityId ).removeClass("small profile-newsfeed-item-action").addClass("newsfeed-content-hidden").slideDown();
		},
		showVideo: function( activityId ){
			jQuery('#profile-newsfeed-item-content-' + activityId + ' .video-object').slideDown();
			jQuery('#profile-newsfeed-item-content-' + activityId + ' .video-object embed').css('width' , jQuery('#profile-newsfeed-item-content-' + activityId ).width() );
		}
	},
	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, 100);
		},
		showPrivacyWindow: function(appName){
			var ajaxCall = "jax.call('community', 'apps,ajaxShowPrivacy', '"+appName+"');";
			cWindowShow(ajaxCall, '', 450, 100);
		},
		showSettingsWindow: function(id, appName){
			var ajaxCall = "jax.call('community', 'apps,ajaxShowSettings', '"+id+"', '"+appName+"');";
			cWindowShow(ajaxCall, '', 450, 100);
		},
		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);
		}
	},
	bookmarks:{
		show: function( currentURI ){
			var ajaxCall = "jax.call('community', 'bookmarks,ajaxShowBookmarks','" + currentURI + "');";
			cWindowShow(ajaxCall, '', 450, 100);
		},
		email: function( currentURI ){
			var emailValue	 = jQuery('#bookmarks-email').val();
			var emailMessage = jQuery('#bookmarks-message').val();
			emailMessage		= escape( emailMessage );
			
			emailMessage=emailMessage.replace(/\\/g,'\\\\');
			emailMessage=emailMessage.replace(/\'/g,'\\\'');
			emailMessage=emailMessage.replace(/\"/g,'\\"');
			emailMessage=emailMessage.replace(/\0/g,'\\0');
			
			var ajaxCall = "jax.call('community', 'bookmarks,ajaxEmailPage','" + currentURI + "','" + emailValue + "','" + emailMessage + "');";
			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, 100);
		},
		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, 100);
			}
		}
	},
	featured: {
		add: function(uniqueId , controller ){
			var ajaxCall = "jax.call('community', '" + controller + ",ajaxAddFeatured', '"+uniqueId+"');";
			cWindowShow(ajaxCall, '', 450, 100);
		},
		remove: function(uniqueId , controller ){
			var ajaxCall = "jax.call('community','" + controller + ",ajaxRemoveFeatured','" + uniqueId + "');";
			cWindowShow(ajaxCall,'', 450, 100);
		}
	},
	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, '', 450, 100);
		},
		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);
					}
				});
				jQuery('.featured-member').bind('click', function() {
				    if ( !jQuery(this).hasClass('active-state') ) {
				        loading( jQuery(this).attr('class') );
				    	jax.call('community', 'frontpage,ajaxGetFeaturedMember', 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', joms.user.getActive());
					}
				});	
				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', joms.user.getActive());
					}
				});	
				
				// sorting and binding for videos
				jQuery('.newest-videos').bind('click', function() {
				    if ( !jQuery(this).hasClass('active-state') ) {
				        loading( jQuery(this).attr('class') );
						jax.call('community', 'frontpage,ajaxGetNewestVideos', frontpageVideos);
					}
				});
				jQuery('.popular-videos').bind('click', function() {
				    if ( !jQuery(this).hasClass('active-state') ) {
				        loading( jQuery(this).attr('class') );
				    	jax.call('community', 'frontpage,ajaxGetPopularVideos', frontpageVideos);
					}
				});
				jQuery('.featured-videos').bind('click', function() {
				    if ( !jQuery(this).hasClass('active-state') ) {
				        loading( jQuery(this).attr('class') );
				    	jax.call('community', 'frontpage,ajaxGetFeaturedVideos', frontpageVideos);
					}
				});
				
				// 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();
			// rebind the tooltip
			jQuery('.hasTipJax').addClass('hasTip');
			joms.tooltip.setup();	
		}
	},
	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, 100);
		},
		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, 100);
		},
		unpublish: function( groupId ){
			jax.call( 'community' , 'groups,ajaxUnpublishGroup', groupId);
		},
		leave: function( groupid ){
			var ajaxCall = 'jax.call("community", "groups,ajaxShowLeaveGroup", "' + groupid + '");';
			cWindowShow(ajaxCall, '', 450, 100);
		},
		joinWindow: function( groupid ){
			var ajaxCall = 'jax.call("community", "groups,ajaxShowJoinGroup", "' + groupid + '", location.href );';
			cWindowShow(ajaxCall, '', 450, 100);
		},
		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, 100, 'warning');
		}
	},
	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, '', 450, 100);
		},
		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, 100);
		},
		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();

			jQuery('#'+ id +' .wall-coc-form-action.add').attr('disabled', false);
			jQuery('#'+ id +' form').width(w).show();
			jQuery('#'+ id +' .show-cmt').hide();
			
			var textarea = jQuery('#'+ id +' textarea');
			joms.utils.textAreaWidth(textarea);
			joms.utils.autogrow(textarea);

			textarea.blur(function(){
				if (jQuery(this).val()=='') 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) {			
			with (jQuery(target))
			{
				css('width', '100%');
				// Google Chrome doesn't return correct outerWidth() else things would be nicer.
				// css('width', width()*2 - outerWidth(true));
				css('width', width() - parseInt(css('borderLeftWidth'))
				                     - parseInt(css('borderRightWidth'))
				                     - parseInt(css('padding-left'))
				                     - parseInt(css('padding-right')));
			}
		},
		
		autogrow: function (id, options) {
			if (options==undefined)
				options = {};
				
			// In JomSocial, by default every autogrow element will have a 300 maxHeight.
			options.maxHeight = options.maxHeight || 300;

			jQuery(id).autogrow(options);
		}
	},
	connect: {
	    checkRealname: function( value ){
	        var tmpLoadingFunction  = jax.loadingFunction;
			jax.loadingFunction = function(){};
			jax.doneLoadingFunction = function(){ jax.loadingFunction = tmpLoadingFunction; };
			jax.call('community','connect,ajaxCheckName', value);
		},
	    checkEmail: function( value ){
	        var tmpLoadingFunction  = jax.loadingFunction;
			jax.loadingFunction = function(){};
			jax.doneLoadingFunction = function(){ jax.loadingFunction = tmpLoadingFunction; };
			jax.call('community','connect,ajaxCheckEmail', value);
		},
		checkUsername: function( value ){
	        var tmpLoadingFunction  = jax.loadingFunction;
			jax.loadingFunction = function(){};
			jax.doneLoadingFunction = function(){ jax.loadingFunction = tmpLoadingFunction; };
		    jax.call('community','connect,ajaxCheckUsername', value);
		},
		// Displays popup that requires user to update their details upon 
		update: function(){
			var ajaxCall = "jax.call('community', 'connect,ajaxUpdate' );";
			cWindowShow(ajaxCall, '', 450, 200);
		},
		updateEmail: function(){
		    jQuery('#facebook-email-update').submit();
		},
		importData: function(){
		    var importStatus    = jQuery('#importstatus').is(':checked') ? 1 : 0;
		    var importAvatar    = jQuery('#importavatar').is(':checked') ? 1 : 0 ;
		    jax.call('community','connect,ajaxImportData',  importStatus , importAvatar );
		},
		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);
		},
		validateUser: function(){
			// Validate existing user
			var ajaxCall = "jax.call('community','connect,ajaxValidateLogin','" + jQuery('#existingusername').val() + "','" + jQuery('#existingpassword').val() + "');";
			cWindowShow(ajaxCall, '', 450, 200);
		},
		newUser: function(){
			var ajaxCall = "jax.call('community','connect,ajaxShowNewUserForm');";
			cWindowShow(ajaxCall, '', 450, 200);
		},
		existingUser: function(){
			var ajaxCall = "jax.call('community','connect,ajaxShowExistingUserForm');";
			cWindowShow(ajaxCall, '', 450, 200);
		},
		selectType: function(){
			if(jQuery('[name=membertype]:checked').val() == '1' )
			{
				joms.connect.newUser();
			}
			else
			{
				joms.connect.existingUser();
			}
		},
		validateNewAccount: function(){
			// Check for errors on the forms.
			jax.call('community','connect,ajaxCheckEmail', jQuery('#newemail').val() );
			jax.call('community','connect,ajaxCheckUsername', jQuery('#newusername').val() );
			jax.call('community','connect,ajaxCheckName', jQuery('#newname').val() );
			
			var isValid	= true;
			if(jQuery('#newname').val() == "" || jQuery('#error-newname').css('display') != 'none')			
			{
				isValid = false;
			}
			
			if(jQuery('#newusername').val() == "" || jQuery('#error-newusername').css('display') != 'none')			
			{
				isValid = false;
			}
			
			if(jQuery('#newemail').val() == '' || jQuery('#error-newemail').css('display') != 'none' )
			{
				isValid = false;
			}

			if(isValid)
			{
				var ajaxCall = "jax.call('community', 'connect,ajaxCreateNewAccount' , '" + jQuery('#newname').val() + "', '" + jQuery('#newusername').val() + "','" + jQuery('#newemail').val() + "');";
				cWindowShow(ajaxCall, '', 450, 200);
			}
		}
	},
	
	// Video component
	videos: {
		showEditWindow: function(id , redirectUrl ){

			if( typeof redirectUrl == 'undefined' )
				redirectUrl	= '';	
						
			var ajaxCall = "jax.call('community', 'videos,ajaxEditVideo', '"+id+"' , '" + redirectUrl + "');";
			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(creatortype, groupid) {
			if(typeof creatortype == "undefined" || creatortype == "")
			{
				var creatortype="";
				var groupid = "";
			}
			var ajaxCall = "jax.call('community', 'videos,ajaxAddVideo', '" + creatortype + "', '" + groupid + "');";
			cWindowShow(ajaxCall, '', 450, 100);
		},
		linkVideo: function(creatortype, groupid) {
			var ajaxCall = "jax.call('community', 'videos,ajaxLinkVideo', '" + creatortype + "', '" + groupid + "');";
			cWindowShow(ajaxCall, '', 450, 100);
		},
		uploadVideo: function(creatortype, groupid) {
			var ajaxCall = "jax.call('community', 'videos,ajaxUploadVideo', '" + creatortype + "', '" + groupid + "');";
			cWindowShow(ajaxCall, '', 450, 100);
		},
		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();
			}
		},
		fetchThumbnail: function(videoId){
			var ajaxCall = "jax.call('community' , 'videos,ajaxFetchThumbnail', '" + videoId + "','myvideos');";
			cWindowShow(ajaxCall, '', 450, 150);
		}
	},
	users: {
		blockUser: function( userId , isBlocked ){
			var ajaxCall = "jax.call('community', 'profile,ajaxBlockUser', '" + userId + "' , '" + isBlocked + "');";
			cWindowShow(ajaxCall, '', 450, 100);
		},
		removePicture: function( userId ){
			var ajaxCall = "jax.call('community', 'profile,ajaxRemovePicture', '" + userId + "');";
			cWindowShow(ajaxCall, '', 450, 100);
		}
	},
	
	user: {
		getActive: function( ){
			// return the current active user
			return js_profileId;
		}
	},
	
	tooltip: {
		setup: function( ){
			// Hide all active visible qTip
			jQuery('.qtip-active').hide();
			setTimeout('jQuery(\'.qtip-active\').hide()', 150);
			try{ clearTimeout(jQuery.fn.qtip.timers.show); } catch(e){}
			
			// Scan the document and setup the tooltip that has .hasTip
			jQuery(".hasTip").each(function(){
		    	var tipStyle = 'tipNormal';
		    	var tipWidth = 220;
		    	var tipPos	 = {corner: {target: 'topMiddle',tooltip: 'bottomMiddle'}}
		    	var tipShow  = true;
		    	var tipHide	 = { when: { event: 'mouseout' }, effect: { length: 10 } }
		    	
		    	if(jQuery(this).hasClass('tipRight'))
				{
		    		tipStyle = 'tipRight';
		    		tipWidth = 320;
		    		tipPos	 = {corner: {target: 'rightMiddle',tooltip: 'leftMiddle'}}
		    	}
		    	
		    	if(jQuery(this).hasClass('tipWide'))
				{
		    		tipWidth = 420;
		    	}
		    	
		    	if(jQuery(this).hasClass('tipFullWidth'))
				{
		    		tipWidth = jQuery(this).innerWidth()-20;
		    	}
		    	
		    	// Split the title and the content
		    	var title = '';
		    	var content = jQuery(this).attr('title');
				var contentArray = content.split('::');
				
				// Remove the 'title' attributes from the existing .hasTip classes
				jQuery( this ).attr('title' , '' );
				
				if(contentArray.length == 2)
				{
					content = contentArray[1];
					title = { text: contentArray[0] } ; 
				} else
					title = title = { text: '' } ; ;
		    	
		    	
		    	jQuery(this).qtip({
		    		content: {
					   text: content,
					   title: title
					},
					style: {name:tipStyle , width: tipWidth },
					position: tipPos,
					hide: tipHide,
					show: { solo: true, effect: { length: 50 } }
			 	}).removeClass('hasTip');		
			});
		
			return true;
		},
		
		setStyle: function() {
			jQuery.fn.qtip.styles.tipNormal = { // Last part is the name of the style
				width: 320,
				border: {
					width: 7,
					radius: 5
				},
				tip: true,
				name: 'dark' // Inherit the rest of the attributes from the preset dark style
			}
			
			jQuery.fn.qtip.styles.tipRight = { // Last part is the name of the style
				tip: 'leftMiddle',
				name: 'tipNormal' // Inherit the rest of the attributes from the preset dark style
			}
			
			return true;
		}
	}
}

// close layer when click-out
jQuery(document).click( function() {
    joms.toolbar.close();
});

// Document ready
jQuery(document).ready(function () {
    
	joms.tooltip.setStyle();
	joms.tooltip.setup(); 
});

(function(jQuery) {
    jQuery.fn.autogrow = function(options) {
        
        this.filter('textarea').each(function() {

			var textarea = jQuery(this);

			// Hide scrollbar first.
			textarea.css('overflow','hidden');

			options.minHeight = options.minHeight || textarea.height();
			options.maxHeight = options.maxHeight || 0;

            textarea.siblings('.textarea-shadow').remove();
            var shadow = jQuery('<div class="textarea-shadow">').css({
                             'position'    : 'absolute',
                             'visibility'  : 'hidden',
                             'font-size'   : (textarea[0].currentStyle==undefined) ? textarea.css('font-size') : textarea[0].currentStyle.fontSize,
                             'font-family' : textarea.css('font-family'),
                             'line-height' : textarea.css('line-height'),
                             'width'       : textarea.width()
                         }).insertBefore(textarea);

			var timer;
            var update = function() {
                var times = function(string, number) {
                    var _res = '';
                    for(var i=0; i<number; i++) {
                        _res = _res + string;
                    }
                    return _res;
                };

                var val = textarea[0].value.replace(/</g, '&lt;')
                                     .replace(/>/g, '&gt;')
                                     .replace(/&/g, '&amp;')
                                     .replace(/\njQuery/, '<br/>&nbsp;')
                                     .replace(/\n/g, '<br/>')
                                     .replace(/ {2,}/g, function(space) { return times('&nbsp;', space.length -1) + ' ' });
                shadow.html(val);

                // Resize textarea if maxHeight is not reached
                var newHeight = Math.max(shadow.height() + 20, options.minHeight);
				if(newHeight < options.maxHeight || options.maxHeight==0)
				{
					textarea.css({'height'   : newHeight,
					              'overflow' : 'hidden'
					             });
				// Enable scrollbar if maxHeight is reached.
				} else {
                	textarea.css('overflow','auto');
				}

                clearTimeout(timer);
            }
            
            var checkExpand = function() {
            	timer = setTimeout(update, 100);
            }

            textarea.change(checkExpand).keydown(checkExpand).keyup(checkExpand);
            
            update.apply(this);
        });
        
        return this;
        
    }
    
})(jQuery);
