var addURL = window.location.href;
var rezise_font = function( sign )
{
	$$( '#contenido p, #contenido a' ).each(
		function( item )
		{
			fSize = $( item ).getStyle( 'font-size' ).toInt();
			if( sign == "+" )
			{
				fSize += ( fSize < 22 ?  1 : 0 );
			}
			else
			{
				fSize -= ( fSize > 9 ? 1 : 0 );
			}
			$( item ).setStyle( 'font-size', fSize );
		}
	);
}

var print_page = function()
{
	window.print();
}

window.addEvent( 
	'domready',
	function(){
		new Request.JSON(
			{	'url' : '/includes/get_tiny_url.php?get_tiny=' + window.location.pathname,
				'onSuccess' :  function( json )
				{
					addURL = json.tiny_url;
					window.fireEvent( 'addthis_ready' );
				}
			}
		).send();
		
		$( 'newsletter_link' ).addEvent( 
			'click',
			function()
			{
				if(flagUrchin) pageTracker._trackEvent('noticias','Click','barra_newsletter');
				new Request.JSON(
					{	'url' : 'qv3_newsletter.php',
						'onSuccess' : function( obj )
						{
							$( 'newsletter_email' ).set( 'value', '' );
							if( obj.error )
							{
								alert( obj.error );
							}
							else
							{
								alert( obj.mensaje );
							}
						}
					}
				).post( { 'action' : 'register', 'email' : $( 'newsletter_email' ).get( 'value' ) });
			} 
		);
		if( $( 'nota_prev' ) && $( 'nota_sig' ) )
		{
		new Request({
			'url' : '/rss/portada.rss',
			'onSuccess' : function( txt, rss )
			{
				var item = rss.getElementsByTagName( 'item' );
				var nodo = new parseXMLNode();
				var currId = 0;
				var id_sig = 1;
				var id_ant = 0;
				if( item.length > 0 )
				{
					for( i = 0; i < item.length; i++ )
					{
						var news = nodo.node2json( item[i] );
						link = news.link.value;
						//link = link.replace("www","qv3" );  ////  TEMPORAL PARA PRUEBAS
						if( link == window.location )
						{
							currId = i;
							break;
						}
					}
					if( currId == 0 ) 
					{
						id_sig = 1; id_ant = ( item.length - 1 );
					}else if( currId == ( item.length - 1) ) 
					{
						id_sig = 0; id_ant = ( currId -1 );
					}else
					{
						id_sig = ( currId + 1  );
						id_ant = ( currId - 1 );
					}
					siguiente = nodo.node2json( item[ id_sig ] ).link.value;
					anterior  = nodo.node2json( item[ id_ant ] ).link.value;

					$( 'nota_sig' ).set( 'href', siguiente );  //quitar el replace cuando ya este
					$( 'nota_prev' ).set( 'href', anterior );  //quitar el replace cuando ya este
				}
			}
		}).get();
	}

	}
);
var showItems = function()
{
	try{ $( 'addThisTwitter' ).fade( 'in' ); } catch(e){}
	try{ $( 'addThisFacebook' ).fade( 'in' ); } catch(e){}
}
window.addEvent( 'addthis_ready',
	function()
	{
		try{ $( 'addThisTwitter' ).dispose(); } catch(e){}
		try{ $( 'addThisFacebook' ).dispose(); } catch(e){}
		new Element(
			'a',
			{ 	'id' : 'addThisTwitter',
				'class' : 'addthis_button_twitter',
				'addthis:url': addURL,
				'style' : 'opacity:0',
				'addthis:title': $$( '.titulo1' )[0].get( 'html' ) + ' ' +  $$( '.titulo2' )[0].get( 'html' )
			}
		).inject( $('news-next') );
		new Element(
			'a',
			{	'id' : 'addThisFacebook',
				'class' : 'addthis_button_facebook',
				'style' : 'opacity:0',
				'addthis:url' : addURL,
				'addthis:title': $$( '.titulo1' )[0].get( 'html' ) + ' ' +  $$( '.titulo2' )[0].get( 'html' )
			}
		).inject( $('news-next') );
		new Asset.javascript( 
			"http://s7.addthis.com/js/250/addthis_widget.js#username=quien", 
			{ 
				'id' : 'addThisJS',
				'onload' : function()
				{
					addthis.addEventListener( 'addthis.ready', showItems );
				}
			} 
		);


	}
);
