(function($) {

	var lightBoxOptions = {
		imageLoading : (_base||"") + 'images/lightbox-ico-loading.gif',
		imageBtnClose  : (_base||"") + 'images/lightbox-btn-close.gif',
		imageBtnPrev : (_base||"") + 'images/lightbox-btn-prev.gif',
		imageBtnNext  : (_base||"") + 'images/lightbox-btn-next.gif',
		imageBlank  : (_base||"") + 'images/lightbox-blank.gif',
		txtImage : "Imagen",
		txtOf : "de"
	}

	$().ready( function() {
	
		//$(document).pngFix({blankgif:"/images/blank.gif"}); 
		if ($.browser.msie)
		{
			$('body').addClass('ie');
			if ($.browser.version == 6) $('body').addClass('ie6');
			if ($.browser.version == 7) $('body').addClass('ie7');
		}
		
		// menubar
		$("#nav ul > li").hover( function() { $(this).addClass("hover"); }, function() { $(this).removeClass("hover"); } );
			
		// tabs
		$(".js-tabs").each( function(i) {
		
			$l = $(this).find(">*");
			$h = $("<table class='tabla-tabs'><tr></tr></table>");
			var idbase = "jstabs-"+i+"-";
			$l.each( function(j) {
				var title = $(this).find("h3:first").html();
				var id = $(this).attr('id') || (idbase+j);
				$(this).attr('id', id);
				var $b = $('<th><a href="#'+id+'">'+title+'</a></th>');
				$h.find('tr:first').append($b);
				$b.click( function(e){
					e.preventDefault();
					$h.find("th").removeClass("selected");
					$(this).addClass("selected");
					$l.hide();
					$l.filter("#"+id).show();
				});
			} );
			$(this).prepend($h);
			$h.find("th:first").click();
		
		} );
		
		// Conversión email
		$("a").each( function() {
			this.innerHTML = this.innerHTML.replace("[at]", "@");
			if (this.href) this.href = this.href.replace("[at]", "@");
		});
		
		// Links auto-resaltados
		var loc = document.location.href.split(/[\?#]/).shift().replace(/\/$/, '');
		$("a").each(function() { 
			var href = this.href.replace(/\/$/, '');
			if ( loc.match( new RegExp(href+"$") ) || href.match( new RegExp(loc+"$") )) {
				$(this).parent().addClass("selected"); 
			}
		});
		
		$(".js-paginate").css({ 'overflow':'hidden' }).carousel({
			listItem : "a",
			autoplay : 5000,
			loop	 : true,
			contentItem : ">div",
			controlsItem : ".paginator",
			leftControl : "",
			rightControl : "",
			firstControl : "",
			lastControl : "",
			pageControl : "<a class='page'>%page%</a>",
			pageSeparator : "<span class='sep'>|</span>"
		});
		
		$('.gallery').each( function() {
			$(this).find("a").lightBox( lightBoxOptions )
		});		
		
		$("a.opengallery").click( function(e) {
			e.preventDefault();
			$(this).parent().find(".gallery a:first").click();
		} );
		
		$("a[rel=image]").lightBox(lightBoxOptions);
		
		/* Destacados */
		$(".mod-destacados").each( function() {
			if ($(".mod-content a", this).size() > 1) {
				$(".mod-content", this).nivoSlider({
					effect : 'random',
					slices : 8,
					pauseTime : 5000,
					directionNav : false,
					controlNav : true,
					keyboardNav : false,
					pauseOnHover:false
				});
			}
		});
		
		/* Calendario de cursos */
		$(".mod-calendario-cursos").configureCalendar();

	} );

})(jQuery);
