var CourMain = function(){
	var th = this;
	this.render = function(target){
		this.panel.render(target);
	};
	this.store = new Ext.data.JsonStore({
		url: 'actions/panelmain.get.json.php',
		fields: ['id', 'title', 'lock', 'owner']
	});

	this.getIdText = function(id){
		return $('#cour_i_'+id+' a').html();
	};

	this.setIdText = function(id, txt){
		return $('#cour_i_'+id+' a').html(txt);
	};

	this.reload = function(){
		th.store.reload();
	};

	this.editItemById = function(id){
		app.edit_line_main.edit(th, id);
	};

	this.deleteItemByIt = function(id){
		var title = this.getIdText(id);
		Ext.Msg.confirm('Confirm', 'Вы уверены, что хотите удалить курс "' + title + '"', function(btn) {
			if (btn == 'yes') {
				Ext.Ajax.request({
					params: {
						id: id
					},
					method: 'POST',
					waitMsg: 'Сохранение...',
					url: 'actions/panelmain.delete.xml.php',

					failure: function(form, action) {
						msg_error('Line was not saved (server error). Please, reload the page and try again');
					},
					success: function(form, action) {
						//msg_ok("Удаление прошло успешно.");
						app.cour_main.reload();
					},
					scope: th
				});
			};
			if (btn == 'cancel') {

			};
		});
	};

	this.store.load();

	this.tpl = Templates.cour_main_tpl;

	this.tb_button_add = new Ext.Button({
		text: "Добавить новый курс",
		handler: function(){
			//this.makeUpdate();
			app.edit_line_main.add(th);
		},
		scope: this
	});

	this.tb = new Ext.Toolbar({
		items: [this.tb_button_add]
	});

	this.panel = new Ext.Panel({
		id: 'images-view',
		frame: false,
		width: '100%',
		autoHeight: false,
		border: false,
		layout: 'fit',
		tbar: this.tb,

		items: new Ext.DataView({
			store: th.store,
			tpl: th.tpl,
			autoHeight:true,
			multiSelect: false,
			overClass:'x-view-over-main',
			itemSelector:'div.thumb-wrap-main',
			emptyText: 'Нету курсов =('
		})
	});
	
	/*this.makeUpdate = function(){
		$('div[id^=cour_id_]').each( function(){
			if(!in_array($(this).attr("rel"), app.my_list)){
				$('#add', this).hide();
			}
		});
	}*/
};
