var masGalerias = new Class ({
	Implements: [Options, Events],
	options: {
		url: '',
		type: 'circulos',
		plaza:0
	},
	initialize: function(options){
		this.setOptions(options);
		var self = this;
		if ( this.options.type == 'circulos' )
		{
			this.options.url = '/RSS_galerias.php?id_tipo=2&top=4&id_ciudad='+this.options.plaza;
			var divfotos = new Element ('div', {
				'class': 'header_circulos'
				}).inject('contenedorMasGalerias');
		}
		else if ( this.options.type == 'fotogalerias' )
		{
			this.options.url = '/RSS_galerias.php?id_tipo=1&top=4';
			var divfotos = new Element ('div', {
				'class': 'header_fotos'
				}).inject('contenedorMasGalerias');
		}
		var retrieve = new retrieveWB ({ url:this.options.url, type:'rss' });
		retrieve.addEvent('completeXML', function(){
			var nodos = retrieve.XML.getElementsByTagName('item');
			self.XML = nodos;
			self.buildGallery();
		});
		
	},
	buildGallery: function()
	{
		var self = this;
		var parserXML = new parseXMLNode();
					
	
	
		for ( i=0; i<4; ++i )
		{
			var nodo = parserXML.node2json(this.XML[i]);
			var divElemento = new Element ('div', {
				'class':'nodoMasGalerias'
			});
			var divImagenElemento = new Element ('div', {
				'class':'divImagenMasGalerias',
				'events':{
					'click':self.followLink.pass(nodo.link.value)
				}
			}).inject(divElemento);
			
			var imagenElemento = new Element ('img', {
				'style':'imagenMasGalerias',
				'src':nodo.enclosure.url
			}).inject(divImagenElemento);
			imagenElemento.addEvent('load', function(){
				var anchuraOriginal = this.offsetWidth;
				this.setStyles({
					'width':134,
					'height':this.offsetHeight*(134/anchuraOriginal)
				});
			});
			var divTextoElemento = new Element ('div', {
				'class':'divTextoMasGalerias',
				'html':nodo.title.value,
				'events':{
					'click':self.followLink.pass(nodo.link.value)
				}
			}).inject(divElemento);
			$(divElemento).inject($('contenedorMasGalerias'));

		}
			
	},
	followLink: function(url)
	{
		if (url!='')
		{
			window.location = url;
		}
	}
});
