$(document).ready(function(){
	$('#slider1').tinycarousel();	
	$('a.lightbox[rel]').overlay({top: 30});
	$('#accordion').accordion({autoHeight: false, header: "a.heading"});
	// install flowplayers	
	$("a.the-player").flowplayer("http://releases.flowplayer.org/swf/flowplayer-3.2.5.swf");
	// ul.overview a[rel].lb_html
	// ul.overview a[rel].lb_flash
	// ul.overview a[rel].lb_video
	$('a[rel].lb_video').overlay({
		top: 30,
		fixed: false,
		onLoad: function(content) {
			// find the player contained inside this overlay and load it
			var player = this.getOverlay().find("a.the-player");
			if (player.length > 0) {
				player.flowplayer(0).load();
			}
		},
		onClose: function(content) {
			try {
				$f().unload();
			}
			catch (e) {
			}
		}	
	});
	$('a[rel].lb_html').overlay({
		top: 30,
		fixed: false,
		onLoad: function(content) {
			// find the player contained inside this overlay and load it
			var player = this.getOverlay().find("a.the-player");
			if (player.length > 0) {
				player.flowplayer(0).load();
			}
		},
		onClose: function(content) {
			try {
				$f().unload();
			}
			catch (e) {
			}
		}	
	});
	$('a[rel].lb_flash').overlay({
		top: 30,
		fixed: false,
		onLoad: function(content) {
			// find the internal <a>
			var flash = this.getOverlay().find('a[rel]');
			var fbase = '/';
			var ffile = '';
			if (flash.length > 0) {
				fbase = flash.attr('flash_base');
				ffile = flash.attr('rel');
				flash.flashembed({src: ffile, wmode: 'opaque', base: fbase});
			}
		}
	});

	/* -- Convertir Imagenes en lightbox -- */
	var $imgs = $('img.thumbnail_lb');
	var idcounter = 0;
	$imgs.each(function () {
		var $img = $(this);
		var objid = 'lbimg' + idcounter;
		var lb = $('<div id="' + objid + '" style="min-height: 0; height: auto; width: auto;" class="imglightbox simple_overlay"></div>');
		lb.append('<img src="' + $img.attr('src') + '"/>');
		$img.after(lb);
		$img.wrap('<a rel="#' + objid + '" style="cursor:pointer;">');
		idcounter++;
		$img.parent().overlay({
			top: 30,
			fixed: false
		});
	});

});
