function shb(_id, _period) {
	
	var replaceObj;
	var id = _id;
	var period = _period;
	var ticker = 0;
	var self = this;
	var addButtonValue;
	var addButton;
	var timeout;
	init();
	
	function init() {
		
		if (getById('shbSubmit_' + id)) {
			addButtonValue = getById('shbSubmit_' + id).value;
			addButton = getById('shbSubmit_' + id);
		}
	}

	this.action = function(_action, _loadingOverlay){
	
		var boxTab = getById('shbListShouts_' + id);
		
		if (_action == "add") {
			
			var text = getById('shbText_' + id).value;
			
			if(text == getById('shbDefaultText_' + id).value)
				return;
			
			getById('shbText_' + id).value = getById('shbDefaultText_' + id).value;
			
			if (getById('shbUsername')) 
				var username = getById('shbUsername').value;
			
			if (getById('shbCaptcha')) 
				var captcha = getById('shbCaptcha').value;
			
			if(ticker > 0)
				return;
				
			clearTimeout(timeout);
			
			if (period > 0) {
				ticker = period;
				addButton.disabled = "disabled";
				
				this.tick();
			}
		}	

		if(_loadingOverlay)
		{
			$(boxTab).html($("#shbShoutboxLoader").html());
		}

		replaceObj = boxTab;

		$.post(pathPrefix + "/Ajax/shbAction" + sid1,{
				action: _action,
				text: text,
				securityCode: captcha,
				id: id,
				username: username
			},
			this.replaceInnerHTML
		);
	}
	
	this.replaceInnerHTML = function(_response) {
		var text = _response;
		if(text.substr(0, 3) == "bwd") {
			alert(text.substr(4));
			return false;			
		}
		
		if(replaceObj)
			replaceObj.innerHTML = _response;
	}

	this.clearInterval = function() {
		
		if(interval)
			window.clearInterval(interval);
	}
	
	this.tick = function() {
		
		if(ticker > 0) {
			ticker--;
			
			if(ticker == 0) {
				
				addButton.disabled = false;
				addButton.value = addButtonValue;
			}
			else {
				addButton.value = addButtonValue + " (" + (ticker+1) + ")";
			}
			
			timeout = setTimeout(function() {self.tick() }, 1000);
		}
						
	}
	
}
