// Slideshow
var Fader = new Class({
    Implements: Options,
    options: {
	pause: 2000,
	duration: 1000,
	loop: true,
	onComplete: Class.empty,
	onStart: Class.empty
    },
    initialize: function(container,options) {
	this.setOptions(options);
	this.container = $(container);
	this.imgs = this.container.getElements('img');
	this.imgs.setStyles({
	    'position':'absolute',
	    'top':0,
	    'left':0,
	    'opacity':0
	});
	this.imgs[0].setStyle('opacity',1);
	this.el = new Element('div',{
	    'styles': {
		'position':'relative'
	    }
	});
	this.el.injectInside(this.container);
	this.el.adopt(this.imgs);
	this.curr = 0;
	this.next = 1;
	this.num_imgs = this.imgs.length - 1;
	this.start();
    },
    start: function() {
	//this.show();
	this.periodical = this.show.bind(this).periodical(this.options.pause);
    },
    stop: function() {
	$clear(this.periodical);
    },
    show: function() {
	if (!this.options.loop && this.next == this.num_imgs) this.stop();

	this.next = (this.curr == this.num_imgs) ? 0 : this.curr + 1;

	this.imgs[this.curr].fade('out');
	this.imgs[this.next].fade('in');
	
	this.curr = this.next;
    }

});

// Compartir en facebook
function fbs_click() {
    u = location.href;
    t = document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
    return false;
}

// Mostrar información oculta Archivo Detalle
function mostrar (id)
{
    $$('.hidden').each(function (el) { el.setStyle('display', 'none'); });
    $$('.sub').each(function (el) { el.removeClass('act'); });

    if (id == 'video') $('imagen').setStyle('display', 'none');
    else $('imagen').setStyle('display', 'block');

    $(id).setStyle('display', 'block');
    $('a_'+id).addClass('act');
}

    
// Enlaces externos válidos XHTML 1.0
function enlaces_externos ()
{
    $$('a[rel=external]').each(function (el) {
	el.set('target', '_blank');
    });
}

window.addEvent('domready', function () {

   if ($('slideshow')) {
       var fader1 = new Fader('slideshow', {'duration': 2000});
   }

   enlaces_externos();

   $$('.hidden').each(function (el) { el.setStyle('display', 'none'); })

   if ($('anyos')) {
       $('anyos').setStyle('display', 'none');
       $('archivo').addEvent('mouseenter', function (el) { $('anyos').setStyle('display', 'block')});
       $('anyos').addEvent('mouseenter', function (el) { $('anyos').setStyle('display', 'block')});
       $('archivo').addEvent('mouseleave', function (el) { $('anyos').setStyle('display', 'none')});
       $('anyos').addEvent('mouseleave', function (el) { $('anyos').setStyle('display', 'none')});
   }

});
