  
GroupWhiteboard = {
  start : 0,
  limit : 10,
  max : 15,
  min : 10,
  feedDivId : '',
  feedFile : '',
  feedTogglerId : '',
  hiddenFeedId : '',
  torender : 'min',
  loaddivtype : 'portlet',
  status_refreshfeed : true,
  id : '',
  
  init : function (id, start, limit, min, max, feedDivId, feedFile, feedTogglerId, hiddenFeedId)
  {
  	this.id = id;
    this.start = start;
    this.limit = limit;
    this.max = max;
    this.feedDivId = feedDivId;
    this.feedFile = feedFile;
    this.feedTogglerId = feedTogglerId;
    this.hiddenFeedId = hiddenFeedId;   
    this.min = min;
  },
  
  saveAE : function (id)
  {
		delete CC.portlets['cc_p_' + id]['limit'];
		CC.updatePortlet(id);
	},

  deleteItem : function(rowid)
  { 
    dellink = Ext.get('delitemlink_'+rowid);
    if (dellink)
    {
      dellink.dom.style.display='none';
    }
    
    Grouply.ajaxload('delres_'+rowid, '/ajax/cgroup.whiteboard.deleteitem.ajax', 'itemid='+encodeURIComponent(rowid)+'&owner='+encodeURIComponent(CC.portlets[this.id].owner), this.deleteItemCallback, null, true);
  },
  
  postItemCallback : function (el, success, response, options)
  {
		GroupWhiteboard.whiteboardInputReset(); 
		iel = document.getElementById("whiteboard_input_el");
		iel.value = "";
		
		if (response.responseText == 'success')
    {
      GroupWhiteboard.reloadWhiteboard();
    }
	},
  
  deleteItemCallback : function(el, success, response, options)
  {
    if (response.responseText == 'success')
    {
      elRow = el.parent('tr');
      if (!elRow)
      {
        GroupWhiteboard.clearHiddenDiv();
        return;
      }
      nextRow = elRow.next('tr');
      prevRow = elRow.prev('tr');
      elRow.remove();
      
      if (nextRow && nextRow.dom.className != 'ca-s')
      {
        nextRow.remove();
      }
      
      if (prevRow && prevRow.dom.className == 'ca-s')
      {
        prevRow.remove();
      }
      
    } else
    {
      dellink = el.prev('a');
      if (dellink)
      {
        dellink.dom.style.display='';
      }
    }
  },
  
  clearHiddenDiv : function ()
  {
    // check hidden div (seemore, see less etc)
      hidden_feed = Ext.get(this.hiddenFeedId);
      if (hidden_feed)
      {
        childExists = hidden_feed.child('tr');
        if (!childExists)
        {
          hidden_feed.remove();
          nf_toggler = Ext.get(this.feedTogglerId);
          if (nf_toggler)
          {
            nf_toggler_row = nf_toggler.parent('tr');
            if (nf_toggler_row)
            {
              nf_toggler_row.remove();
            }
          }
        }
      }
  },
  
  
  whiteboardInputClick : function()
  {
    document.getElementById("g_whiteboard_prompt").style.display = "none";
    document.getElementById("g_whiteboard_input").style.display = "block";
    iel = document.getElementById("whiteboard_input_el");
    //iel.value = "";
    iel.focus();
  },
  
  whiteboardInputReset : function()
  {
    var el2 = document.getElementById("g_whiteboard_prompt");
    var el3 = document.getElementById("g_whiteboard_input");
    if (el2 && el3) {
      el2.style.display = "block";
      el3.style.display = "none";
      iel = document.getElementById("whiteboard_input_el");
      iel.value = "";
    }
  },
  
  whiteboardBlur : function()
  {
    iel = document.getElementById("whiteboard_input_el");
    if (iel.value == "") {
      GroupWhiteboard.whiteboardInputReset();
    }
  },
  
  postWhiteboard : function()
  {
    Grouply.ajaxloadform('whiteboardPostResult', 'whiteboardInputForm', GroupWhiteboard.postItemCallback);
  },
  
  reloadWhiteboard : function()
  {
  	CC.portlets[this.id].start = this.start;
  	CC.portlets[this.id].limit = this.limit;
		CC.ajax.reload(this.id, true);	
	},
	
	next : function ()
	{
		this.start = this.start + this.limit;
		this.reloadWhiteboard();
	},
	
	prev : function ()
	{
		this.start = Math.max(0, this.start - this.limit);
		this.reloadWhiteboard();
	},
	
	seemore : function ()
	{	
		if (this.limit == this.max)
		{
			Grouply.showEl('wbseemorediv');
			Grouply.hideEl('wb_toggler_seemore');
			Grouply.showEl('wb_toggler_less');
		} else
		{
			this.limit = this.max;
			this.reloadWhiteboard();
		}
		
	},
	
	seeless : function ()
	{
		Grouply.hideEl('wbseemorediv');
		Grouply.showEl('wb_toggler_seemore');
		Grouply.hideEl('wb_toggler_less');
	},
	
	jumpTo : function (storyid)
	{
		window.location.hash = 'group_wb_post_' + storyid;
	}
}

