var rssReader = new Class(
{
	Extends : listadoRSS,
	options: {
		paginaActual:1,
		paginado:10,
		divListado: 'listado',
		divPaginado: 'paginado',
		seccion: '',
		rssFile: '',
		thumbWidth:104,
		forceThumbResize:true,
		useBothTitles:false,
		classNota:'rss_listado',
		defaultNumPages:10,
		nextButton:'paginadoSiguiente',
		prevButton:'paginadoAnterior',
		propiedadExtra:"yo"
	},
	initialize: function (options)
	{
		this.parent(options);
		this.setOptions(options);
	},
	generaPagina : function( numPagina )
	{
		$( 'noticias_contenedor' ).empty();
		var scroller = new Fx.Scroll( document.body,{ duration : 2500, transition: Fx.Transitions.Quad.easeInOut} );
		scroller.toTop();

		var self = this;
		//console.log (this);
		if ( typeof(numPagina) == 'undefined')
		{
			numPagina = this.options.paginaActual;
		}
		var paginado = this.getPag ( numPagina );
		new Request(
		{
			url: self.options.rssFile+paginado,
			onSuccess : function( txt, rss )
			{
				var item = rss.getElementsByTagName('item');
				var nodeParser = new parseXMLNode ();
				if( item.length > 0 )
				{
					/** se limpia el contenido **/
					$(self.options.divListado).innerHTML = '';
					tmpArr = paginado.split(',');
					init = tmpArr[0];
					end = parseInt( init, 10 ) + parseInt( tmpArr[1], 10 );
					for( var i = init; i < end; i++ ) //item.length; ++i )
					{
						var itemNode = nodeParser.node2json(item[i]);
						/** DIR contenedor **/
						var divRS = new Element( 'div' ).inject( self.options.divListado );
						/** THUMB **/
						var divIMG = new Element( 'div' );
						try{
						var imglink = new Element ('a', {'href' : itemNode.link.value}).inject( divIMG ); 
						var imagen = new Element( 'img', { 'src' :  itemNode.enclosure.url.replace("_thumb",""),'border':'0'  } ).inject( imglink );
						} catch(e){ var imagen = {};  }
						var author = new Element( 'div', { 'class' : 'credito', 'html' : itemNode.credit.value } ).inject( divIMG );
						//var H = ( self.options.thumbWidth * parseInt( imagen.height, 10 ) ) / parseInt( imagen.width, 10 );
						try{
						var W = parseInt( itemNode.enclosure.width, 10 );
						}catch(e){ var W= 200; }
						if( self.options.forceThumbResize )
						{
						//	$( thumb ).setStyles( { 'width' : self.options.thumbWidth, 'height' : H } );
						}
						/** TITULO **/
						divTitle1 = new Element( 'div', { 'class' : 'titulo1' } );
						divTitle2 = new Element( 'div', { 'class' : 'titulo2' } );
						if( self.options.useBothTitles )
						{
							anchT1 = new Element( 'a',{ 'text' : itemNode.title.h1, 'href' : itemNode.link.value, 'class' : 'title1'}).inject( divTitle1 );
							anchT2 = new Element( 'a',{ 'text' : itemNode.title.h2, 'href' : itemNode.link.value, 'class' : 'title2'}).inject( divTitle2 );
						} else {
							anchTitle = new Element( 'a', { 'text' : itemNode.title.value, 'href' : itemNode.link.value } ).inject( divTitle1 );
						}
						/** ENTRADILLA **/
						divEntr = new Element( 'div', { 'class' : 'entradilla' , 'html' : itemNode.description.value } );
						/**
						*	ADD THIS
						*/
						addthis = new Element( 'div', { 'class' : 'addthisButtons' } );
						addthis_cont = new Element( 'div', { 'class':'addthis_toolbox addthis_default_style' } ).inject( addthis );
						a1 = new Element( 'a', 
							{ 	'href'	:	'http://addthis.com/bookmark.php?v=250&amp;username=quien',
								'addthis:title' : 	itemNode.title.h1 + ' ' + itemNode.title.h2,
								'addthis:url' 	:	itemNode.tinyURL.value , 
								'class'	:	'addthis_button_compact',
								'text'	:	'Share' 
							} 
						).inject( addthis );
						separa = new Element( 'span', { 'class':'addthis_separator','html':'|' } ).inject(addthis );
						a2 = new Element( 'a', { 'class':'addthis_button_facebook','addthis:url':itemNode.tinyURL.value,'addthis:title':itemNode.title.h1 + ' ' + itemNode.title.h2 } ).inject( addthis );
						a3 = new Element( 'a', { 'class':'addthis_button_myspace','addthis:url':itemNode.tinyURL.value,'addthis:title':itemNode.title.h1 + ' ' + itemNode.title.h2  } ).inject( addthis );
						a4 = new Element( 'a', { 'class':'addthis_button_google','addthis:url':itemNode.tinyURL.value,'addthis:title':itemNode.title.h1 + ' ' + itemNode.title.h2  } ).inject( addthis );
						a5 = new Element( 'a', { 'class':'addthis_button_twitter','addthis:url':itemNode.tinyURL.value,'addthis:title':itemNode.title.h1 + ' ' + itemNode.title.h2  } ).inject( addthis );
						

						//if( H > self.options.thumbWidth )
						if( W < 300 )
						{
							$( divRS ).addClass( 'rs_vertical' );
							$( divIMG ).addClass( 'img_vertical' );
							$( divIMG ).inject( divRS );
							textos = new Element( 'div', { 'class': 'textos' } ).inject( divRS );
							$( divTitle1 ).inject( textos );
							$( divTitle2 ).inject( textos );
							$( divEntr ).inject( textos );
							$( addthis ).inject( textos );
						}
						else
						{
							$( divRS ).addClass( 'rs_horizontal' );
							$( divIMG ).addClass( 'img_horizontal' );
							$( divTitle1 ).inject( divRS );
							$( divTitle2 ).inject( divRS );
							$( divIMG ).inject( divRS );
							$( divEntr ).inject( divRS );
							$( addthis ).inject( divRS );
						}
					}
				}

				var html_head = $$( 'head' )[0];
				var js = document.createElement( 'script' );
				js.setAttribute( 'language', 'javascript' );
				js.setAttribute( 'type', 'text/javascript' );
				js.setAttribute( 'src', 'http://s7.addthis.com/js/250/addthis_widget.js#username=quien' );
				html_head.appendChild( js );
			}
		}
).send();

}
}
);


window.onload = function()
	{
		new rssReader(
			{	seccion:'noticias',
				divPaginado:'paginadoNumeros',
				paginado:5,
				divListado:'noticias_contenedor',
				rssFile:'/rss/portada.rss?q=' + Math.random() + '&top=',
				thumbWidth:104,
				forceThumbResize:true,
				useBothTitles:true,
				classNota:'rss_listado',
				defaultNumPages:12,
				nextButton:'paginadoSiguiente',
				prevButton:'paginadoAnterior'

			}
		);
	};

