ClipControl = function (member_id)
{
	this.clipcore = new ClipCore('/v2/clip_gateway/clip_gateway.php');
	this.clipcore.setResponseFormat('json');
	this.clipcore.setConnectionFailedHandler(this.onConnectionFailed);
	if (member_id)
		this.clipcore.setMemberId(member_id, 'hkh_id');
	
	this.container = null;
	this.clipped_count = {
		prop: { count: 0, html: null }, 
		dir: { count: 0, html: null }, 
		article: { count: 0, html: null }, 
		goods: { count: 0, html: null } 
	};
	this.max_allowed_item = {
		property: 80,
		directory: 80,
		featured_article: 80,
		goods_and_services: 80
	};
	
	this.getClipCountName = function (item_cat)
	{
		var item_count_name = '';
		
		if (item_cat == 'property')
			item_count_name = 'prop';
		else if (item_cat == 'directory')
			item_count_name = 'dir';
		else if (item_cat == 'featured_article')
			item_count_name = 'article';
		else if (item_cat == 'goods_and_services')
			item_count_name = 'goods';
			
		return item_count_name;
	}
	this.checkClipItems = function (listener, item_cat, item_ids, item_type)
	{
		var info = {
			'namespace': 'hkh.item.'+item_cat,
			'item_id': item_ids.join(','),
			'item_type': item_type
		};
		
		var req_id = this.clipcore.checkItems(info, listener);
		return req_id;
	}
	this.fetchClipItems = function (listener, item_cat, item_type)
	{
		var info = {
			'namespace': 'hkh.item.'+item_cat,
			'item_type': item_type
		};
		
		this.clipcore.fetchItems(info, listener);
	}
	this.fetchClipItemByItemId = function (listener, item_cat, item_type, item_id)
	{
		var info = {
			'namespace': 'hkh.item.'+item_cat,
			'item_type': item_type,
			'item_id': item_id
		};
		
		this.clipcore.fetchItems(info, listener);
	}
	this.fetchClipItemById = function (listener, clip_item_id)
	{
		var info = {
			'clip_item_id': clip_item_id
		};
		
		this.clipcore.fetchItems(info, listener);
	}
	this.updateClipItemDescription = function (listener, clip_item_id, item_desc)
	{
		var info = {
			'clip_item_id': clip_item_id,
			'description': item_desc
		};
		
		this.clipcore.updateItem(info, listener);
	}
	this.addClipItem = function (listener, item_cat, item_id, item_type, item_desc)
	{
		var item_description = '';
		if (typeof(item_desc) != 'undefined')
		{
			item_description = item_desc;
		}
		
		var clip_count_name = this.getClipCountName(item_cat);
		if (typeof(this.max_allowed_item[item_cat]) != 'undefined' && 
			this.clipped_count[clip_count_name].count >= this.max_allowed_item[item_cat])
		{
			alert('Sorry, you cannot clip more than 80 items.');
			return;
		}
		
		var info = {
			'namespace': 'hkh.item.'+item_cat,
			'item_id': item_id,
			'item_type': item_type,
			'visibility': 1,
			'description': item_description
		};
		
		return this.clipcore.addItem(info, listener);
	}
	this.removeClipItem = function (listener, clip_item_id)
	{
		this.clipcore.removeItem(clip_item_id, listener);
	}
	this.removeClipItems = function (listener, clip_item_ids)
	{
		this.clipcore.removeItems(clip_item_ids, listener);
	}
	this.onConnectionFailed = function ()
	{
		// alert('Clipboard Connection Failed. Please try again later.');
	}
}

