/**
 * @projectDescription global pandora play list bag
 *
 * @author riho.kim@pandora.tv
 * @version 1.0.0
 * @usage var TClass = TTPrgBagCtrl.getInstance();
 *
 * @sdoc
 * @namespace pandora.ch.playlist.bag.controller
 * @change log
 *  2008.03.18 - scrap 기능으로 인하여 플레이리스트에 담을때 user nickname을 사용하지 않음 (e.g. 출처 : ch_userid님의 채널)
 */

/** implementation Class */
var cTPrgBagCtrl = Class.create();
	cTPrgBagCtrl.prototype = {
		initialize : function() {
			this._storage		= cStorageMgr.getInstance();
		},

		set : function(parent, maxCookie, cateLength, uid) {
			this._parent		= parent;
			this.cateLength		= cateLength || 30;
			this.maxCookie		= maxCookie || 20;

			this._bid			= uid || decodeURIComponent(oCookie.get('glb_mem[userid]')) || ''; //uid에 넘어오는 값이 없을 경우 자동적으로 쿠키의 정보를 찾아 사용한다.

			this._storage.appendHash('bagInfo', { 'userid':this._bid, 'categ_id':'', 'max':this.maxCookie, 'prg_info':'', 'categ_id':'', 'new_cate_name':'', 'new_categ_index':'', 'new_categ_open_pub':'1'} );
			this._createSubInstance();
		},

		_createSubInstance : function () {
//			this.sharedObject = TSharedObject.getInstance();
			SharedObject.setup();
//			this.cookieInstance		= TTCookieCtrl.getInstance();
//			this.cookieInstance.set(this, 'glb_bsk', '/', 'pandora.tv', 7, false);

			this._prgBagListInstance	= TTPrgBagList.getInstance();
			this._prgBagListInstance.set(this, this._bid);
		},

		_destorySubInstance : function() {
			this._storage				= null;
			this._cookieInstance		= null;
			this._prgBagListInstance	= null;
		},

		append : function() {
			this._prgBagListInstance.append(arguments);
		},

		pop : function() {
			this.append();
		},

		initComplete : function() {
			//Event.observe(window, 'load', this.set.bindAsEventListener(this, list, category));
		}
	}


	/** Single Pattern - get only once Instance */
	cTPrgBagCtrl.__instance__ = null; // static property
	cTPrgBagCtrl.getInstance = function () {
		if (this.__instance__ == null) {
			this.__instance__ = new cTPrgBagCtrl();
		}
		return this.__instance__;
	}


function plAddCate(json) {
	var pl = cTPrgBagCtrl.getInstance();
	pl._prgBagListInstance._cateAddInstance._setJSON(json);
}


function plAddPrg(json) {
	var pl = cTPrgBagCtrl.getInstance();
	pl._prgBagListInstance._saveInstance._setJSON(json);
}

/* add by rhio.kim 2008.03.18 scrap movie have not a orginal channel name */
function plGetChName(json) {
	var pl = cTPrgBagCtrl.getInstance();
	pl._prgBagListInstance._setJSON(json);
}
