var prod_js2;
Ext.onReady(function(){
	Ext.QuickTips.init();
	var borde = bordex;
	var visor1 = function(config){
		this.config = config;
	}

	visor1.prototype = {
		lookup : {},
		show : function(){
			if(!this.win){
				this.initTemplates();
				this.store1 = new Ext.data.JsonStore({
					totalProperty: 'total',
					root: 'resultado',
					url: urlbase+'0/'+this.config.modelo+'/'+this.config.vista+'/',
					fields: ['id', 'alias','nombre', 'id_imagen', 'imagen', 'nodos_id']
				});
				
				this.store1.load({params:{start:0, limit:12}});
				
				var formatData = function(data){
					this.lookup[data.id] = data;
					return data;
				};
				
				this.dataview1 = new Ext.DataView({
					store: this.store1,
					tpl: this.tpl1,
					autoHeight:true,
					multiSelect: true,
					overClass:'x-view-over',
					itemSelector:'div.thumb-wrap',
					listeners: {
						'selectionchange': {fn:this.vervisor1, scope:this, buffer:100}
					},
					emptyText: '',
					prepareData: formatData.createDelegate(this)
				});

				var a = '';
				if(nav_id == nodo_id) a = ' | <span style="cursor:pointer;font-weight:bold;" onclick="editar(\'administracion\',\'0\');">Editar</span>';
				var cfg = {
					title: '<span style="cursor:pointer;font-weight:bold;" onclick="window.location = urlbase+urlbase3+\''+this.config.titulo+'/\';">'+this.config.titulo+'</span>'+a,
					renderTo: document.getElementById(this.config.capa),
					border: borde,
					defaults: {
						collapsible:false,
						border: false,
						titleCollapse: true
					},
					bbar: new Ext.PagingToolbar({
						pageSize: 12,
						store: this.store1,
						displayInfo: true,
						displayMsg: '{0} - {1} of {2}',
						emptyMsg: "No topics to display"
					}),
					items: [this.dataview1]
				};
				this.win = new Ext.Panel(cfg);
				var win = this.win;
				this.win.addClass(this.config.clase);
				this.win.show();
			}
		},
		initTemplates : function(){
			this.tpl1 = new Ext.XTemplate(
				'<tpl for=".">',
					'<div class="thumb-wrap" id="{id}">',
						'<div class="thumb"><img onmouseover="this.style.cursor = \'pointer\';" src="'+urlbase+'tmp/sol_{nodos_id}/thumbnails/{imagen}" title="{nombre}"></div>',
					'</div>',
				'</tpl>',
				'<div class="x-clear"></div>'
			);
			this.tpl1.compile();
		},
		vervisor1 : function(){
			var selNode = this.dataview1.getSelectedNodes(); 
			if(selNode.length > 0){
				if(selNode && selNode.length > 0){
					selNode = selNode[0];
					var data = this.lookup[selNode.id];
					window.location = urlbase+urlbase3+data.alias+'/';
				}
			}
		}
	};

	var visor2 = function(config){ this.config = config; }

	visor2.prototype = {
		lookup : {},
		show : function(){
			if(!this.win){
				this.initTemplates();
				this.store1 = new Ext.data.JsonStore({
					totalProperty: 'total',
					root: 'resultado',
					url: urlbase+'0/'+this.config.modelo+'/'+this.config.vista+'/',
					fields: ['id', 'nombre','detalle','archivo','archivos'],
					listeners: {
						datachanged: function() {
							if(this.getCount() > 0){ 
								var b = '';
								if(nav_id==nodo_id) b = ' | <span style="cursor:pointer;font-weight:bold;" onclick="editar(\''+config.modelo+'\',\'0\');">Editar</span>';
								win.setTitle('<span style="cursor:pointer;font-weight:bold;" onclick="window.location = urlbase+urlbase3+\''+config.modelo+'/\';">'+config.titulo+'</span>'+b);
							}
						}
					}
				});
				
				this.store1.load();
				
				var formatData = function(data){
					this.lookup[data.id] = data;
					return data;
				};
				
				this.dataview1 = new Ext.DataView({
					store: this.store1,
					tpl: this.tpl1,
					autoHeight:true,
					multiSelect: true,
					overClass:'x-view-over',
					itemSelector:'div.thumb-wrap',
					listeners: {
						'selectionchange': {fn:this.viewGaleria, scope:this, buffer:100}
					},
					emptyText: '',
					prepareData: formatData.createDelegate(this)
				});
				
				var store1 = this.store1;
				var config = this.config;
				var a = '';
				if(nav_id==nodo_id) a = ' | <span style="cursor:pointer;font-weight:bold;" onclick="editar2(\''+this.config.modelo+'\',\'0\',\'0\');">Agregar</span>';
				var cfg = {
					title: '<span style="cursor:pointer;font-weight:bold;" onclick="window.location = urlbase+urlbase3+\''+this.config.modelo+'/\';">'+this.config.titulo+'</span>' + a,
					renderTo: document.getElementById(this.config.capa),
					border: borde, 
					defaults: {
						collapsible:false,
						
						titleCollapse: true
					},
					items: [this.dataview1]
				};
				this.win = new Ext.Panel(cfg);
				var win = this.win;
				this.win.addClass(this.config.clase);
			}
			this.win.show();
		},
		initTemplates : function(){
			this.tpl1 = new Ext.XTemplate(
				'<tpl for=".">',
					'<div class="thumb-wrap" id="{id}">',
						'<div class="thumb"><img src="'+urlbase+'tmp/sol_'+nav_id+'/thumbnails/{archivo}" title="{nombre}"></div>',
						'<div class="info">',
							'<span class="x-editable"><b>{nombre}</b>: {detalle}</span>',
							'<span class="x-editable">{archivos} Fotos</span>',
						'</div>',
					'</div>',
				'</tpl>',
				'<div class="x-clear"></div>'
			);
			this.tpl1.compile();
		},
		viewGaleria : function(){
			var selNode = this.dataview1.getSelectedNodes(); 
			if(selNode.length > 0){
				if(selNode && selNode.length > 0){
					selNode = selNode[0];
					var data = this.lookup[selNode.id];
					window.location = urlbase+urlbase3+this.config.modelo+'/'+data.id+'/'+data.nombre;
				}
			}
		}
	};
	
	var visor9 = function(config){
		this.config = config;
	}

	visor9.prototype = {
		lookup : {},
		show : function(){
			if(!this.win){
				this.initTemplates();
				this.store1 = new Ext.data.JsonStore({
					totalProperty: 'total',
					root: 'resultado',
					url: urlbase+'0/'+this.config.modelo+'/'+this.config.vista+'/',
					fields: ['id', 'nombre','numero'],
					listeners: {
						datachanged: function() {
							if(this.getCount() > 0) win.setTitle('<span style="cursor:pointer;font-weight:bold;" onclick="window.location = urlbase+urlbase3+\''+config.modelo+'/\';">'+config.titulo+'</span>');
						}
					}
				});
				
				this.store1.load();
				
				this.dataview1 = new Ext.DataView({
					store: this.store1,
					tpl: this.tpl1,
					autoHeight:true,
					overClass:'x-view-over',
					itemSelector:'div.thumb-wrap',
					emptyText: ''
				});
				
				var store1 = this.store1;
				var config = this.config;
				var a = '';
				if(nav_id==nodo_id) a = ' | <span style="cursor:pointer;font-weight:bold;" onclick="editar(\''+this.config.modelo+'\',\'0\');">Agregar</span>';
				var cfg = {
					title: '<span style="cursor:pointer;font-weight:bold;" onclick="window.location = urlbase+urlbase3+\''+this.config.modelo+'/\';">'+this.config.titulo+'</span>' + a,
					renderTo: document.getElementById(this.config.capa),
					bodyStyle: 'padding: 5px',
					border: borde, 
					defaults: {
						collapsible:false,
						
						titleCollapse: true
					},
					items: [this.dataview1]
				};
				this.win = new Ext.Panel(cfg);
				var win = this.win;
				this.win.addClass(this.config.clase);
			}
			this.win.show();
		},
		initTemplates : function(){
			this.tpl1 = new Ext.XTemplate(
				'<tpl for=".">',
					'<div class="contenidox">',
						'<div class="titulo">',
							'<span><a href="'+urlbase+urlbase3+this.config.modelo+'/categorias/{id}/{nombre}" >{nombre} ({numero})</a></span>',
						'</div>',
					'</div>',
				'</tpl>',
				'<div class="x-clear"></div>'
			);
			this.tpl1.compile();
		}
	};
	
	var visor10 = function(config){
		this.config = config;
	}

	visor10.prototype = {
		lookup : {},
		show : function(){
			if(!this.win){
				this.initTemplates();
				this.store1 = new Ext.data.JsonStore({
					totalProperty: 'total',
					root: 'resultado',
					url: urlbase+'0/'+this.config.modelo+'/'+this.config.vista+'/',
					fields: ['id', 'nombre','archivo'],
					listeners: {
						datachanged: function() {
							if(this.getCount() > 0){ 
								var b = '';
								if(nav_id==nodo_id) b = ' | <span style="cursor:pointer;font-weight:bold;" onclick="editar(\''+config.modelo+'\',\'0\');">Editar</span>';
								win.setTitle('<span style="cursor:pointer;font-weight:bold;" onclick="window.location = urlbase+urlbase3+\''+config.modelo+'/\';">'+config.titulo+'</span>'+b);
							}
						}
					}
				});
				
				this.store1.load();
				
				var formatData = function(data){
					this.lookup[data.id] = data;
					return data;
				};
				
				this.dataview1 = new Ext.DataView({
					store: this.store1,
					tpl: this.tpl1,
					autoHeight:true,
					multiSelect: true,
					overClass:'x-view-over',
					itemSelector:'div.thumb-wrap',
					listeners: {
						'selectionchange': {fn:this.vervisor1, scope:this, buffer:100}
					},
					emptyText: '',
					prepareData: formatData.createDelegate(this)
				});

				var store1 = this.store1;
				var config = this.config;
				var a = '';
				if(nav_id==nodo_id) a = ' | <span style="cursor:pointer;font-weight:bold;" onclick="editar(\''+this.config.modelo+'\',\'0\');">Agregar</span>';
				
				var cfg = {
					title: '<span style="cursor:pointer;font-weight:bold;" onclick="window.location = urlbase+urlbase3+\''+this.config.modelo+'/\';">'+this.config.titulo+'</span>' + a,
					renderTo: document.getElementById(this.config.capa),
					border: borde, 
					defaults: {
						collapsible:false,
						
						titleCollapse: true
					},
					items: [this.dataview1]
				};
				this.win = new Ext.Panel(cfg);
				var win = this.win;
				this.win.addClass(this.config.clase);
			}
			
			this.win.show();
		},
		initTemplates : function(){
			this.tpl1 = new Ext.XTemplate(
				'<tpl for=".">',
					'<div class="thumb-wrap" id="{id}">',
						'<div class="thumb"><img width="170" src="http://img.youtube.com/vi/{archivo}/2.jpg" title="{nombre}"><img width="170" height="10" src="'+urlbase+'/images/media_player.jpg" title="{nombre}"></div>',
						'<div class="info">',
							'<span class="x-editable"><b>{nombre}</b></span>',
						'</div>',
					'</div>',
				'</tpl>',
				'<div class="x-clear"></div>'
			);
			
			this.tpl1.compile();
		},
		vervisor1: function(){
			if(this.tableWindow3){
				this.tableWindow3 = null;
			}
			var selNode = this.dataview1.getSelectedNodes();
			if(selNode && selNode.length > 0){
				selNode = selNode[0];
				var data = this.lookup[selNode.id];
				if(!this.tableWindow3){
					this.tableWindow3 = new Ext.Window({
						title: 'Video',
						closeAction: 'close',
						width:440,
						height:376
					});
				
				}else{
					this.tableWindow3.getEl().frame();
				}
				this.tableWindow3.html = '<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/'+data.archivo+'&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+data.archivo+'&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>';
				this.tableWindow3.show();
			}
		}
	};
	
	
	
	
		
	var video = new visor10({
		modelo:'videos',
		vista:'vista1json',
		capa:'videos',
		clase:'visor10',
		titulo: 'Videos'
	});
	video.show();
	
	var presta = new visor1({
		modelo:'prestadores',
		vista:'vista1json',
		capa:'prestadores',
		clase:'visor1',
		titulo: nav_name2
	});
	presta.show();
	var galer = new visor2({
		modelo:'galerias',
		vista:'vista1json',
		capa:'galerias',
		clase:'visor2',
		titulo: 'Galerias'
	});
	galer.show();
	var contenido3 = new visor9({
		modelo:'contenidos',
		vista:'vista3json',
		capa:'contenidos',
		clase:'visor6',
		titulo: 'Contenidos'
	});
	contenido3.show();
	var producto2 = new visor9({
		modelo:'productos',
		vista:'vista2json',
		capa:'productos2',
		clase:'visor6',
		titulo: 'Productos'
	});
	producto2.show();
	var producto2 = new visor9({
		modelo:'noticias',
		vista:'vista2json',
		capa:'noticias2',
		clase:'visor6',
		titulo: 'Noticias'
	});
	producto2.show();
	var evento2 = new visor9({
		modelo:'eventos',
		vista:'vista2json',
		capa:'eventos2',
		clase:'visor6',
		titulo: 'Eventos'
	});
	evento2.show();
	

});


