
function allst(iditem, kol)
{

	//alert(iditem);
	Ext.Ajax.request({
		// waitMsg: 'Подождите пожалуйста...',
		url: 'shopfunc.php',
		method: 'GET',
		params: {
			task: "additem",
			item: iditem,
			kol: kol
		},
		success: function(o){

			var a = Ext.decode(o.responseText);
			var items = a.items;
			var prices = a.price;
			//	alert(a.iditem);
			//var zz = Ext.decode(a);
			Ext.get('allprice').update(prices);
			var btncont = new Ext.Button({

			});

			var ww =  new Ext.Window({
				html: '<center><b><font size="3" >Товар добавлен в корзину',
				buttonAlign: 'center',
				//autoWidth: true,
				width: '300',
				buttons: [{
					text: 'Продолжить покупки',
					handler: function()
					{
						ww.hide();
					}
				},
				{
					text: 'Перейти в корзину',
					href: '?action=cart',
					target: "_self",
					handler: function() {
						location.href = '?action=cart';
						ww.hide();
					}
				}
				]
			});
			ww.show();



		}
	});

};



var store = new Ext.data.JsonStore({
	url: 'shopfunc.php?action=list',
	root: 'images',
	fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date', dateFormat:'timestamp'}]
});


var tpl = new Ext.XTemplate(
'<tpl for=".">',
'<div class="thumb-wrap" id="{name}">',
'<div class="thumb"><img src="{url}" title="{name}" height="100"></div>',
'<span><a href="#" onclick=zz("{name}")>увеличить</a></span></div>',
'</tpl>',
'<div class="x-clear"></div>'
);

var ima = new Ext.DataView({
	store: store,
	tpl: tpl,
	autoHeight:true,
	singleSelect: true,
	// multiSelect: true,
	overClass:'x-view-over',
	itemSelector:'div.thumb-wrap',
	emptyText: 'Нет фотографий',

	prepareData: function(data){
		data.shortName = Ext.util.Format.ellipsis(data.name, 15);
		data.sizeString = Ext.util.Format.fileSize(data.size);
		data.dateString = data.lastmod.format("m/d/Y g:i a");
		return data;
	}
});

var panel = new Ext.Panel({
	id:'images-view',
	frame:true,
	width:450,
	autoHeight:true,
	collapsible:true,
	layout:'fit',
	title:'Фотографии',
	items: ima
});

	var store2 = new Ext.data.JsonStore({
	url: 'gal.php?action=list',
	root: 'results',
	totalProperty:'total',
	fields: ['name', 'url', 'catid']
});
var GallerypB = new Ext.PagingToolbar({
	pageSize: 10,
	
	cls: 'x-plain',
	store: store2
	
});

var tpl2 = new Ext.XTemplate(
'<tpl for=".">',
'<div class="thumb-wrap" id="{name}">',
'<div class="thumb"><img src="{url}" title="{name}" height="100"></div>',
'<span><a href="#" onclick="zz2('+"'"+'{name}'+"'"+', {catid})">увеличить</a></span></div>',
'</tpl>',
'<div class="x-clear"></div>'
);

var ima2 = new Ext.DataView({
	store: store2,
	tpl: tpl2,
	autoHeight:true,
	singleSelect: true,
	// multiSelect: true,
	listeners: {
		"dblclick": function(ima2)
		{
			var records = ima2.getSelectedRecords();
			for(i=0,len = records.length;i < len; i++){
				var image = records[i].data;
			zz2(image.name, image.catid);
			}
			
		}
	},
	overClass:'x-view-over',
	itemSelector:'div.thumb-wrap',
	emptyText: 'Нет фотографий',

	prepareData: function(data){
		data.shortName = Ext.util.Format.ellipsis(data.name, 15);
		
		return data;
	}
});

var panel2 = new Ext.Panel({
	id:'images-view',
	frame:true,
	width:450,
	autoHeight:true,
	collapsible:false,
	baseCls: 'x-plain',
	layout:'fit',
	
	title:'Фотографии',
	items: [ima2]
});
function stors(start, stop, id)
{
	store2.load({params:{start:stop, limit:start, id: id}});
}

function cartpr(id)
{

	var ima2 = new Ext.DataView({
		store: store,
		tpl: tpl,
		autoHeight:true,
		singleSelect: true,
		// multiSelect: true,
		overClass:'x-view-over',
		itemSelector:'div.thumb-wrap',
		emptyText: 'Нет фотографий',

		prepareData: function(data){
			data.shortName = Ext.util.Format.ellipsis(data.name, 15);
			data.sizeString = Ext.util.Format.fileSize(data.size);
			data.dateString = data.lastmod.format("m/d/Y g:i a");
			return data;
		}
	});

	var panel2 = new Ext.Panel({
		id:'images-view',
		frame:true,
		width:"70%",
		
		autoHeight:true,
		collapsible:true,
		layout:'fit',
		title:'Фотографии',
		items: ima2
	});

	store.load({params:{id: id }});
	var pr = new Ext.Panel({
		autoLoad: {url: 'pr.php?iditem='+id},
		autoWidth: true

	});
	var pre = new Ext.Window({
		width: '600',
		height: '800',
		//autoWidth: true,
		//autoHeight: true,
		items: [pr, panel2]
	});

	//pre.show();
	pre.show();




	//ima.refresh();



};
function zz(file)
{
	new Ext.Window({
		layout:'fit',
        width:500,
        
        autoHeight:true,
       // modal: true,
       // shadow:true,
       // closable: false,
        resizable: true,
        plain: true,
        html:'<center><img src="files/shop/'+file+'" width="90%">',
        border: false
	}).show();
}
function zz2(file, catid)
{
	
	new Ext.Window({
		layout:'fit',
        width:'40%',
         maximizable: true,
        id: 'zoomimagegallery',
        loadMask: true,
        autoHeight:true,
       // modal: true,
       // shadow:true,
       // closable: false,
        resizable: true,
        plain: true,
        html:'<center><img src="files/gallery/'+file+'" width="90%">',
        border: false,
        buttonAlign: 'center',
        buttons: [{
        	text: 'Назад',
        		handler: function()
        	{
        		
		Ext.Ajax.request({
			waitMsg: 'Подождите пожалуйста...',
			url: 'gal.php',
			params: {
				task: "prev",
				catid: catid,
				file: file
			},
			success: function(response){
				var result=response.responseText;
				var nn = Ext.decode(result);
				Ext.getCmp('zoomimagegallery').body.update('<img src="'+nn.image+'" width="90%">');
				file = nn.file;
			},
			failure: function(response){
				var result=response.responseText;
				Ext.MessageBox.alert('error','could not connect to the database. retry later');
			}
		});
        	}
        },{
        	text:'Вперёд', 
        	handler: function()
        	{
        		
		Ext.Ajax.request({
			waitMsg: 'Подождите пожалуйста...',
			url: 'gal.php',
			params: {
				task: "next",
				catid: catid,
				file: file
			},
			success: function(response){
				var result=response.responseText;
				var nn = Ext.decode(result);
				Ext.getCmp('zoomimagegallery').body.update('<img src="'+nn.image+'" width="90%">');
				file = nn.file;
			},
			failure: function(response){
				var result=response.responseText;
				Ext.MessageBox.alert('error','could not connect to the database. retry later');
			}
		});
        	}
        }]
	}).show();
}




