var prod_js;
Ext.onReady(function(){
	Ext.QuickTips.init();
	var borde = bordex;
	
	var visor3 = function(config){
		this.config = config;
	}
	
	visor3.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: ['mid', 'mnombre','mintroduccion','mimagen','mcreacion','cid','cnombre','trans'],
					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(){
			var a = '';
			if(nav_id==nodo_id) a = ' | <a href="javascript:editar(\''+this.config.modelo+'\',\'{mid}\');">Editar</a>';
			this.tpl1 = new Ext.XTemplate(
				'<tpl for=".">',
					'<table><tr><td>',
					'<div class="contenido01">',
						'<div class="titulo">',
							'<span><a href="'+urlbase+urlbase3+this.config.modelo+'/{mid}/{mnombre}">{mnombre}</a></span><br>',
							'{mcreacion} | <a href="'+urlbase+urlbase3+'contenidos/categorias/{cid}/{cnombre}" >{cnombre}</a>{trans} '+ a,
						'</div>',
						'<div class="bloque">',
							'<p align="justify" >',
							'<img src="'+urlbase+'tmp/sol_'+nav_id+'/{mimagen}" style="margin-right: 5px;" align="left">',
							'{mintroduccion}',
							'</p>',
						'</div>',
						'<div class="pie">',
							'<a href="'+urlbase+urlbase3+this.config.modelo+'/{mid}/{mnombre}">Ver el resto del contenido</a>',
						'</div>',
					'</div>',
					'</td></tr></table>',
				'</tpl>',
				'<div class="x-clear"></div>'
			);
			this.tpl1.compile();
		}
	};

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

	visor4.prototype = {
		lookup : {},
		indice: 0,
		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','imagen'],
					listeners: {
						'load': {fn:function(){ this.dataview1.select(0); }, scope:this, single:true},
						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',
					emptyText: '',
					listeners: {
						'selectionchange': {fn:this.showDetails, scope:this, buffer:100}
					},
					prepareData: formatData.createDelegate(this)
				});
				
				this.panel1 = new Ext.Panel({
					id: this.config.modelo+'-detail-'+this.config.numero,	
					width:371,
					height:250,
					bodyStyle: 'padding: 5px',
					defaults: { 
						collapsible:false,
						border: false,
						titleCollapse: false
					},
					html: ''
				});
				
				this.panel2 = new Ext.Panel({
					id: this.config.modelo+'-list-'+this.config.numero,
					width:193,
					height:250,
					defaults: { 
						collapsible:false,
						border: false,
						titleCollapse: false
					},
					items: [this.dataview1]
				});
				
				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 = {
					id: this.config.modelo+this.config.numero,
					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),
					layout: 'column',
					border: borde, 
					defaults: {
						collapsible:false,
						
						titleCollapse: true
					},
					items: [this.panel1,this.panel2]
				};
				this.win = new Ext.Panel(cfg);
				var win = this.win;
				this.panel1.addClass(this.config.clase1);
				this.panel2.addClass(this.config.clase2);
			}
			this.win.show();
		},
		initTemplates : function(){
			this.tpl1 = new Ext.XTemplate(
				'<tpl for=".">',
					'<div class="thumb-wrap" id="{id}">',
						'<div class="thumb"><img height="48" width="48" src="'+urlbase+'tmp/sol_'+nav_id+'/thumbnails/{imagen}" title="{nombre}"></div>',
						'<div class="info">',
							'<span class="x-editable"><b>{nombre}</b></span>',
						'</div>',
					'</div>',
				'</tpl>',
				'<div class="x-clear"></div>'
			);
			this.tpl2 = new Ext.XTemplate(
				'<tpl for=".">',
					'<div class="elementoz">',
						'<div class="imagen"><p align="center"><img style="max-width: 359px; max-height: 238px;" src="'+urlbase+'tmp/sol_'+nav_id+'/{imagen}" title="{nombre}"></p></div>',
						'<div class="descripcion">',
						'<table width="100%" border="0" cellspacing="0" cellpadding="5">',
						'<tr><td><b>{nombre}</b></td></tr>',
						'<tr><td><a href="'+urlbase+urlbase3+this.config.modelo+'/{id}/{nombre}">{detalle}</a></td></tr>',
						'</table>',
						'</div>',
					'</div>',
				'</tpl>',
				'<div class="x-clear"></div>'
			);
			this.tpl1.compile();
			this.tpl2.compile();
		},
		showDetails : function(){
			var selNode = this.dataview1.getSelectedNodes();
			var detailEl = Ext.getCmp(this.config.modelo+'-detail-'+this.config.numero).body;
			if(selNode && selNode.length > 0){
				selNode = selNode[0];
				var data = this.lookup[selNode.id];
				detailEl.hide();
				this.tpl2.overwrite(detailEl, data);
				detailEl.slideIn('l', {stopFx:true,duration:.5});
			}
		},
		seleccion : function(){
			var selNode = this.dataview1.getSelectedIndexes();
			this.indice = selNode[0];
			this.indice++;
			if(this.indice == this.store1.getCount()) this.indice = 0;
			this.dataview1.select(this.indice);
		}
	};
	
	var visor5 = function(config){
		this.config = config;
	}

	visor5.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','imagen'],
					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 src="'+urlbase+'tmp/sol_'+nav_id+'/thumbnails/{imagen}" 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(){
			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 visor6 = function(config){
		this.config = config;
	}

	visor6.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: ['mid', 'mnombre','mintroduccion','mcreacion','cid','cnombre'],
					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);
			}
			var config = this.config;
			var win = this.win;
			this.win.show();
		},
		initTemplates : function(){
			var a = '';
			if(nav_id==nodo_id) a = ' | <a href="javascript:editar(\''+this.config.modelo+'\',\'{mid}\');">Editar</a>';
			this.tpl1 = new Ext.XTemplate(
				'<tpl for=".">',
					'<div class="contenidox">',
						'<div class="titulo">',
							'<span><a href="'+urlbase+urlbase3+this.config.modelo+'/{mid}/{mnombre}">{mnombre}</a></span><br>',
							'{mcreacion} | <a href="'+urlbase+urlbase3+this.config.modelo+'/categorias/{cid}/{cnombre}" >{cnombre}</a> '+a,
							'<p align="justify">{mintroduccion}</p>',
						'</div>',
					'</div>',
				'</tpl>',
				'<div class="x-clear"></div>'
			);
			this.tpl1.compile();
		}
	};
	
	var visor7 = function(config){
		this.config = config;
	}

	visor7.prototype = {
		lookup : {},
		show : function(){
			if(!this.win){
				this.initTemplates();
				var config = this.config;
				this.store1 = new Ext.data.JsonStore({
					totalProperty: 'total',
					root: 'resultado',
					url: urlbase+'0/'+this.config.modelo+'/'+this.config.vista+'/',
					fields: ['mid', 'mnombre','murl','mdetalle','mimagen'],
					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();
				
				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 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">',
							'<table width="100%"><tr><td><a href="http://{murl}" target="_blank">{mnombre}</a></td></tr>',
							'<tr><td><p align="justify"><a href="http://{murl}" target="_blank"><img width="70" src="'+urlbase+'tmp/sol_'+nav_id+'/thumbnails/{mimagen}" style="margin-right: 5px;" align="left"></a>{mdetalle}... <a href="http://{murl}" target="_blank">Visitar</a></p></td></tr></table>',
						'</div>',
					'</div>',
				'</tpl>',
				'<div class="x-clear"></div>'
			);
			this.tpl1.compile();
		}
	};
	
	var visor8 = function(config){
		this.config = config;
	}

	visor8.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: ['mid', 'mnombre','mfecha','nalias','modelo']
				});
				
				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 cfg = {
					title: '<span style="cursor:pointer;font-weight:bold;" onclick="window.location = urlbase+urlbase3+\''+this.config.modelo+'/\';">'+this.config.titulo+'</span>',
					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);
				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+'{nalias}/{modelo}/{mid}/{mnombre}">{mnombre}</a></span> {mfecha}',
						'</div>',
					'</div>',
				'</tpl>',
				'<div class="x-clear"></div>'
			);
			this.tpl1.compile();
		}
	};
	
	var visor20 = function(config){
		this.config = config;
	}

	visor20.prototype = {
		lookup : {},
		show : function(){
			if(!this.win&&document.getElementById(this.config.capa)){
				var cfg = {
					title: '<span style="cursor:pointer;font-weight:bold;" onclick="window.location = urlbase+urlbase3+\''+this.config.modelo+'/\';">'+this.config.titulo+'</span>',
					renderTo: document.getElementById(this.config.capa),
					bodyStyle: 'padding: 5px',
					border: borde, 
					defaults: {
						collapsible:false,
						titleCollapse: true
					},
					html: '<div id="encuestaz"></div>'
				};
				this.win = new Ext.FormPanel(cfg);
				this.win.addClass(this.config.clase);
				Ext.Ajax.request({
					url : urlbase+'0/encuestas/vista1/',
					method: 'GET',
					success: function ( result, request ) { 
						document.getElementById('encuestaz').innerHTML = result.responseText;
					}
				});
				this.win.show();
			}
		}
	};
	
	var visor21 = function(config){
		this.config = config;
	}

	visor21.prototype = {
		lookup : {},
		show : function(){
			if(!this.win&&document.getElementById(this.config.capa)){
				this.initTemplates();
				this.store1 = new Ext.data.JsonStore({
					totalProperty: 'total',
					root: 'resultado',
					url: urlbase+'0/'+this.config.modelo+'/'+this.config.vista+'/',
					fields: ['mid', 'mnombre','mintroduccion','mcreacion','cid','cnombre'],
					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(){
			var a = '';
			if(nav_id==nodo_id) a = ' | <a href="javascript:editar(\''+this.config.modelo+'\',\'{mid}\');">Editar</a>';
			this.tpl1 = new Ext.XTemplate(
				'<tpl for=".">',
					'<div class="contenidox">',
						'<div class="titulo">',
							'<span><a href="'+urlbase+urlbase3+this.config.modelo+'/{mid}/{mnombre}">{mnombre}:</a></span> {mintroduccion} '+a,
						'</div>',
					'</div>',
				'</tpl>',
				'<div class="x-clear"></div>'
			);
			this.tpl1.compile();
		}
	};
	
	var contenido1 = new visor3({
		modelo:'contenidos',
		vista:'vista1json',
		capa:'destacado',
		clase:'visor31',
		titulo: 'Destacado'
	});
	contenido1.show();
	var contenido2 = new visor3({
		modelo:'contenidos',
		vista:'vista2json',
		capa:'destacados',
		clase:'visor32',
		titulo: 'Recientes'
	});
	contenido2.show();
	
	var producto = new visor4({
		numero: '1',
		modelo:'productos',
		vista:'vista1json',
		capa:'productos',
		clase1:'visor4d',
		clase2:'visor4l',
		titulo: 'Productos destacados'
	});
	prod_js = producto;
	producto.show();
	
	var evento = new visor5({
		modelo:'eventos',
		vista:'vista1json',
		capa:'eventos',
		clase:'visor11',
		titulo: 'Eventos'
	});
	evento.show();
	var noticias1 = new visor6({
		modelo:'noticias',
		vista:'vista1json',
		capa:'noticias',
		clase:'visor6',
		titulo: 'Noticias'
	});
	noticias1.show();
	var enlaces1 = new visor7({
		modelo:'enlaces',
		vista:'vista1json',
		capa:'enlaces',
		clase:'visor6',
		titulo: 'Enlaces'
	});
	enlaces1.show();
	var redes1 = new visor8({
		modelo:'redes',
		vista:'vista1json',
		capa:'redes',
		clase:'visor6',
		titulo: 'La red'
	});
	redes1.show();
	
	var encues1 = new visor20({
		modelo:'encuestas',
		vista:'vista1',
		capa:'encuestas',
		clase:'visor6',
		titulo: 'Encuestas'
	});
	encues1.show();
	
	var archi1 = new visor21({
		modelo:'descargas',
		vista:'vista1json',
		capa:'archivos',
		clase:'visor6',
		titulo: 'Ultimas descargas'
	});
	archi1.show();
	
	
	setInterval('seleccion()',7000);
});

function seleccion(){
	prod_js.seleccion();
}
