/**
 * for /user/projects page
 * 
 * @author eduard marsal <eduard.marsal@eyeworkers.de>
 */
 
var projects = {
	list : {
		/**
		 * Gets the list of the projects of the user with the passed user_id
		 * depending on the passed view_mode.
		 * @param {} user_id
		 * @param {} view_mode
		 */
		get : function(user_id, view_mode) {
			user_id = typeof user_id !== 'undefined' ? user_id : false;
			
			if (!user_id) {// check the selected value of the select-field
				user_id = jQuery('#temp-user-for-projectlist').val();
				user_id = !isNaN(user_id) ? user_id : false;				
			}
			
			jQuery('#all-projects').html('<img src="' + doc_root + 'misc/icons/loader.gif" style="padding:45%;" />');
			jQuery.post(doc_root + 'includes/ajax/user.all-projects.get.php', {
				intOwnerUserId : user_id,
				viewMode : view_mode 
			}, function(data, status) {
				jQuery('#all-projects').html(data);
				
				util.check_footer_location();
			}, 'json');
		},
		
		
		/**
		 * Update the links
		 */
		update : function(select_obj) {
			// update the list with the user selected, with default view_mode (started)  
			
			var user_id = jQuery(select_obj).val();
			user_id = !isNaN(user_id) ? user_id : false; 
			projects.list.get(user_id, 'started');
		}
		
	},
	modifying_box: {
		
		/**
		 * 
		 *  
		 */
		/**
		 * Loads data in a box then modifys it if needed.
		 * @param {String} element_id - Id of the DOM element which will contain the response of the asynchronous call 
		 * @param {String} content_type - depending on how the content will be visualized (table, list) 
		 */
		get : function(element_id, content_type) {

			// check if element exists
			if (jQuery('#' + element_id).length > 0) { 
				// load msg before update
				jQuery('#' + element_id).html('<img src="' + doc_root + 'misc/icons/loader.gif" style="padding:45%;" />'); 
				jQuery.post(doc_root + 'includes/ajax/user.' + element_id + '.get.php', {
					
				}, function (data, status) {
					// update element
					jQuery('#' + element_id).html(data);
					if (jQuery('#' + element_id + '-content').length > 0) {
						//projects.modify_with_jquery(element_id + '-content', content_type, element_id);
					}
					else {
						// wait and call again
						//alert('data still not present');
					}
				},'json');
			}						
		}
	},
	
	
	/**
	 * 
	 * @param {String} element_id - DOM-id of a element which will get modified visuals 
	 * @param {String} content_type - Type of the element {element_id}
	 */
	modify_with_jquery : function(element_id, content_type, parent_element_id) {
		if ('table' == content_type) {
			$("#" + element_id).ingrid({ 
				url: doc_root + 'includes/ajax/user.' + parent_element_id + '.get.php?json=false',
//				height: 350,
//				initialLoad: true,
				resizableCols: false,
				paging: false,
				sorting: false,
				colWidths: [170, 10],
				rowClasses: ['grid-row-style1','grid-row-style2']

			});
		}
	}
};
