$(document).ready(function(){

	/* ====================== */
	/* = DETECCIÓN DE IDIOMA= */
	/* ====================== */
	
	if (window.location.href.match('/EN/')) {
		var idioma = 'EN';
	}
	else {
		var idioma = 'ES';
	}

	// =================
	// = LAST CHILD IE =
	// =================
	
	if ($.browser.msie){
		$('table thead tr th:last-child').css('border-right','none');
		$('#footer ul li:last-child').css({'border-right':'none','margin-right':'0','padding-right':'0'});
		$('#container div.t3a div p:last-child').css('margin-bottom','0');
		$('#container div.pag ul li:last-child').css('padding-right','0');
		$('div.table3 table thead tr th:last-child').css('border-right','none');
		if (parseInt($.browser.version,10) < 8) {
			$('#container #breadcrumb li').append('&gt;&nbsp;');
		// $('dl#contact dd').not(":last").append("&middot;")
		}
	 }
	
	/* 
	$.ajax({ url: "http://ifbaspst.infobolsanet.com/ifblayout2/Layout.aspx?layout=ResumenHome&client=TecnicasReunidas",
							 context: document.body,
							 success: function(html){
        						$('#ficha_datos').html(html);
							}
	});	 
	*/
	
	/* ====================== */
	/* = MENÚS DESPLEGABLES = */
	/* ====================== */
	$('#sideA > ul > li:not(.active) > ul').hide();
	$('#sideA > ul > li strong').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	}).click(function(){
		$(this).next('ul').slideToggle();
	});	
	
	
	/* ============================== */
	/* = INSERTAMOS EN EL SIDEB LAS
	 * = FUNCIONALIDADES DE
	 * = AUMENTAR TAMAÑI E IMPRIMIR
	/* ============================== */
	
	if (idioma == 'ES') {
		var funcionalidades = '<div id="utilities"><ul class="first"><li><span class="decrement" title="Disminuir el tamaño de las fuentes">-A</span></li><li class="last"><span class="increment" title="Aumentar el tamaño de las fuentes">A+</span></li></ul><ul class="last"><li><span class="print" title="Imprimir página"><span>Imprimir página</span></span></li></ul></div>';
	}
	else {
		var funcionalidades = '<div id="utilities"><ul class="first"><li><span class="decrement" title="Decrement the font size">-A</span></li><li class="last"><span class="increment" title="Increment the font size">A+</span></li></ul><ul class="last"><li><span class="print" title="Print"><span>Print</span></span></li></ul></div>';
	}
	
	$('#sideB').prepend(funcionalidades);

	/* ========================= */
	/* = AUMENTAR TAMAÑO TEXTO = */
	/* ========================= */

	var fontClicks = 0;
	$('span.decrement').css({'visibility':'hidden'});;

	function resizeText(fontClicks){
			if(fontClicks > 0){
			   $('span.decrement').css({'visibility':'visible'});;
			}
			if(fontClicks < 1){
			   $('span.increment').css({'visibility':'visible'});;
			}
			switch (fontClicks) {
			    case 0:
				   $('span.decrement').css({'visibility':'hidden'});;
				   $('body').css({'font-size':'x-small'});							
			       break;
			    case 1:
				   $('body').css({'font-size':'small'});							
				   $('span.increment').css({'visibility':'hidden'});;
			       break;
			} 
	}

	$('span.increment').click(function(e){
		e.preventDefault();
		if(fontClicks < 1){
			fontClicks++;
			resizeText(fontClicks);
		}
	});
	
	$('span.decrement').click(function(e){
		e.preventDefault();
		if(fontClicks > 0){
			fontClicks--;
			resizeText(fontClicks);
		}
	});
	
	/* =================== */
	/* = IMPRIMIR PÁGINA = */
	/* =================== */
	
	$('span.print').live('click', function(){
		window.print();
	});
	
	// =================
	// = HOME CARRUSEL =
	// =================
	
	$('#carousel li').not(':first').hide();
	$('#carousel li:first,#home_info > li:first').addClass('on');
	$('#home_info > li').mouseover(function(){
		var cual = $(this).index();
		if (!$(this).hasClass('on')) {
			$('#home_info > li.on').removeClass('on');
			$(this).addClass('on');
			$('#carousel li.on').removeClass('on').fadeOut();
			$('#carousel li').eq(cual).addClass('on').fadeIn();
		}
	});
	
	/* =================== */
	/* = VÍDEOS = */
	/* =================== */
	if($(".oembed").length)
	{
	$(".oembed").oembed(null, 
                {
                embedMethod: "append", 
                maxWidth: 407,
                vimeo: { autoplay: false, maxWidth: 407, color: '4E5E8C', title:false, byline:false, portrait:false}                 
                })
			.hide();
	}

	
	
	// ============
	// = DROPDOWN =
	// ============
	
	$("tbody tr.dropdown").toggle();
	$("tbody tr.trigger").hover(
		function () {
			$(this).css('cursor','pointer');
			$(this).children().css('background-color','#EEEEEE');
		}, 
		function () {
			$(this).css('cursor','auto');
			$(this).children().css('background-color','#F5F5F5');
		}
	);
	$('tbody tr.trigger td').click(function(){
		$(this).parent().next('tbody tr.dropdown').toggle();
	});
	
	// ================================
	// = ABRIMOS EN UNA VENTANA NUEVA =
	// ================================

	$('a.external').click(function(){
		this.target = "_blank";	
	});
	
	$('a.colorbox').colorbox();

});

