/*
 * FuncionesOposiones
 * http://www.areainteractiva.net/
 *
 * Copyright (c) 2009 Fernando Alou
 *
 * Date: 2009-06-29 (Mon, 29 Jun 2009)
 * Revision: 1
 */

// JavaScript Document
/*
$(document).ready( function() {
	inicializarEventos();
});


function inicializarEventos(){
	construyeCombo();
	Opacidades();
	VistosoHome();
//	reemplazoTexto();
	Layout();
	formConvocatorias();
	selctorFecha();
	expandeLista();
	cantosRombos();
//	reemplazoFecha();
	botones();
	ligtbox();
	lanzaLgBx();
	ayuda();
}
*/

function alMenosUnFiltro()
{
	var grupo = $('#jqCombo_0_text').html();
	var titulacion = $('#jqCombo_1_text').html();
	var organo = $('#jqCombo_2_text').html();

	if (grupo == 'Todos' && titulacion == 'Todas' && organo == 'Todos' )
	{
		alert("Debe seleccionar al menos un filtro.");
		return false;
	}
	return true;
}

function Layout(){
	var tamanyo = -10;
	$('.jq_menuBtn:last').each(function(){
					tamanyo = tamanyo+$(this).prev().width();
		 			tamanyo = tamanyo+$(this).width();
	});
		tamanyo = tamanyo+20-87;

	$('input.cabecera_buscador_input').css('width',tamanyo+'px');
	//alert(tamanyo+49);
	var left = 540-(tamanyo+97);
	$('input.cabecera_buscador_input').parent('form').css('left',left+'px');
}


function Opacidades(){
	$('.opacidad_50').each(function(){
								$(this).css('opacity','0.5');
								});
	$('.opacidad_60').each(function(){
								$(this).css('opacity','0.6');
								});
	$('.opacidad_65').each(function(){
								$(this).css('opacity','0.65');
								});
	$('.opacidad_70').each(function(){
								$(this).css('opacity','0.7');
								});
	$('.opacidad_75').each(function(){
								$(this).css('opacity','0.75');
								});
}
function VistosoHome(){
	if ($(".jq_Vistoso_item").length > 0){
		vistososHome = [];
		vistososHomeActual = 1;
		vistososHomeTotal = $('.jq_Vistoso_item').length;
		$('.jq_Vistoso_item').each(function(){
			vistososHome.push($(this));
		});
		setInterval(VistosoHomeRota, 5000)
	}
}

function VistosoHomeRota(){
	if(vistososHomeActual < vistososHomeTotal){
		//alert(vistososHomeActual);
		vistososHome[vistososHomeActual-1].animate({ height: "0"}, 500 );
		vistososHomeActual++
	} else {
		vistososHome[0].animate({ height: "275px"}, 500, function(){$('.jq_Vistoso_item').css('height','275px');});
		vistososHomeActual = 1;
	}

}
function reemplazoTexto(){

			if(FlashDetect.installed){
			// SI ESTA INSTALADO
			var jq_rTxtData = 1;
			$('.jq_rTxt').each(function(){
						var config = {
								estil : $(this).attr("class").replace("jq_rTxt ",""),
								textOriginal: $(this).html().replace("jq_rTxt ",""),
								text: $(this).find("span").html(),
								enlaceDir: $(this).children("a").attr("href"),
								alto: $(this).height(),
								ancho: $(this).width(),
								descripcion: $(this).children("a").attr("title")
							}
						codigoFlash = '<embed height="'+config.alto+'" width="'+config.ancho+'" src="img/txt2.swf" quality="best"';
			codigoFlash = codigoFlash+'flashvars="eltexto='+config.text+'&estil='+config.estil+'&enlace='+config.enlaceDir+'&alto='+config.alto;
			codigoFlash = codigoFlash+'&ancho='+config.ancho+'&descripcion='+config.descripcion+'&id_data='+jq_rTxtData+'" wmode="transparent" bgcolor="transparent" sifr="true" type="application/x-shockwave-flash" style="width: ';
			codigoFlash = codigoFlash+config.ancho+'px; height: '+config.alto+'px;"/><span class="accesibilidad">'+config.textOriginal+'</span>';
						$(this).html(codigoFlash);
						$(this).data('jq_rTxtData',jq_rTxtData);
						jq_rTxtData++;
				});

		}
}
function reemplazoFecha(){

			if(FlashDetect.installed){
			// SI ESTA INSTALADO
			$('.item_fecha').each(function(){
						var config = {
								text: $(this).text(),
								alto: 48,
								ancho: 40
							}
						codigoFlash = '<embed height="'+config.alto+'" width="'+config.ancho+'" src="img/fecha.swf" quality="best"';
			codigoFlash = codigoFlash+'flashvars="fecha='+config.text+'" wmode="transparent" bgcolor="transparent" sifr="true" type="application/x-shockwave-flash" style="width: ';
			codigoFlash = codigoFlash+config.ancho+'px; height: '+config.alto+'px;"/><span class="accesibilidad">'+config.textOriginal+'</span>';
						$(this).html(codigoFlash);
				});
		}
}
function EscribirFlash(config){
/*
			if(FlashDetect.installed){
			// SI ESTA INSTALADO
			codigoFlash  = '<embed height="'+config.alto+'" width="'+config.ancho+'" src="'+config.url+'" quality="best"'
			codigoFlash += '" wmode="transparent" bgcolor="transparent" sifr="true" type="application/x-shockwave-flash" style="width: '
			codigoFlash +=  config.ancho+'px; height: '+config.alto+'px;"/>';
			$('#'+config.id).html(codigoFlash);
			}
*/
}
function formConvocatorias(){
	if ($("#num_plaz").length > 0){

		var Item = $('#num_plaz');
		Item.before('<div id="num_plaz_text" class="ops_slider_leyenda"></div>');

		Item.find('input').each(function(){
            var nombre = $(this).attr('name');
        	var valor = $(this).attr('value');
   		$(this).replaceWith('<input type="hidden" name="'+nombre+'" value="'+valor+'">');
       });

		$(function() {
			$("#num_plaz").slider({
				range: true,
				step: ((500) / 10),
				min: 0,
				max: 500,
				values: [0, 500],
				slide: function(event, ui) {
					$("#num_plaz_text").html('Entre <b>'+ui.values[0]+'</b> y <b>'+ ui.values[1]+'</b> plazas');
				}
			});

			$("#num_plaz_text").html('Entre <b>'+$("#num_plaz").slider("values", 0)+'</b> y <b>'+ $("#num_plaz").slider("values", 1)+'</b> plazas');
		});

	}
}
function selctorFecha(){
	if ($("#fecha_limite").length > 0){
		$('#fecha_limite').datepicker({
								dateFormat: 'dd-mm-yy',
								firstDay:1,
								dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','Sa'],
								monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
								monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
								prevText: 'Anterior', // Display text for previous month link
								nextText: 'Siguiente',
								showOn: 'button', buttonImage: 'http://www.oposicionesaldia.com/img/generico/11_calendar.gif', buttonImageOnly: true,
								showOn: 'both'
								});

	$('.ui-datepicker-cover').remove();
	}
}
function expandeLista(){
	$('.expande').click(function(){
								if($(this).html() == '-'){
									$(this).html('+');
									$(this).parent().css('font-weight','normal');
								} else {
									$(this).html('-');
									$(this).parent().css('font-weight','bold');
								}
								$(this).siblings('.sublista').toggle();
								return false;
								});
}
function cantosRombos(){
	var z_index = 20;
	$('.jq_cantoRombo').each(function(){
								var altura = $(this).height();
								var ispara = false;
								if(altura%2==0){
								  ispara = true;
								}
								if(ispara == false){altura++};
								$(this).attr('style','min-height:'+altura+'px; height:auto !important; height:'+altura+'px;');
								insertRedondeo = '';
								insertRedondeo += '<b class="jq_cantoRombo_tl"></b>'
								insertRedondeo += '<b class="jq_cantoRombo_tr"></b>'
								insertRedondeo += '<b class="jq_cantoRombo_bl"></b>'
								insertRedondeo += '<b class="jq_cantoRombo_br"></b>';

								$(this).children(':first').before(insertRedondeo);
								$(this).css('z-index',z_index);
								z_index--;
								});
}
function botones(){
	$('.jq_btnOn').each(function(){
			$(this).mouseover(function(){$(this).addClass('btnOn');});
			$(this).mouseout(function(){$(this).removeClass('btnOn');});
									  });
	$('.jq_btnOnBotRight').each(function(){
			$(this).mouseover(function(){$(this).addClass('btnOnBotRight');});
			$(this).mouseout(function(){$(this).removeClass('btnOnBotRight');});
									  });

}
function ligtbox(){
	var AltoContenido = $(document).height();

	$('#jq_lgbx_negro').css('height',AltoContenido).css('opacity',0.5).click(function(){
																					  $('#jq_lgbx').hide();
																					  });
	$('.lightbox_widget_cierra').click(function(){
												$('#jq_lgbx').hide();
												});
}
function lanzaLgBx(){
	$('.lanzaLgBx').click(function(){
								   var contenidoAmostrar = $(this).attr('id');
								   var posX = $(this).offset().left;
								   var posY = $(this).offset().top-100;
								   var Tamanyo = $(this).width();
								   var posXFinal = posX+Tamanyo;
								   $('.lighbox_widget').hide();

								   $('#'+contenidoAmostrar+'_contenido').css('left',posXFinal+'px').css('top',posY+'px').show();
								   $('#jq_lgbx').show();
								   });
}
function ayuda(){
	$('.help').each(function(){
							 $(this).mouseover(function(){
														var textoAyuda = $(this).attr('title');
															             $(this).attr('title','');
														$('#texto_ayuda').html(textoAyuda);

														 var posX = $(this).offset().left+5;
													     var posY = $(this).offset().top;
													     var Tamanyo = $(this).width();
														 var altura = $(this).height()/2;
													     var posXFinal = posX+Tamanyo;

														$('#ayuda').show().css('left',posXFinal+'px').css('top',posY+altura+'px');

														var alturaAyuda = $('#ayuda').height()/2;
														$('#ayuda').css('margin-top','-'+alturaAyuda+'px');
														$('#ayuda_flecha').css('margin-top',alturaAyuda-4+'px');
														});
							 $(this).mouseout(function(){
													   var textoAyuda = $('#texto_ayuda').html();
															             $(this).attr('title',textoAyuda);
														$('#ayuda').hide();
														});

					  });
}
function muestraAyuda(textoAyuda, idData){

		$('#texto_ayuda').html(textoAyuda);
		elemento =  $(':data(jq_rTxtData='+idData+')');
			var posX = elemento.offset().left;
			var posY = elemento.offset().top;
			var Tamanyo = elemento.width()-20;
			var altura = elemento.height();
			$('#texto_ayuda').css('width',Tamanyo+'px');
			$('#titulo_enlace').css('display','inline').css('left',ratonX+'px').css('top',posY+altura+'px');

		//alert(texto+"  ----------  "+idData);
		/*$(':data(jq_rTxtData='+elemmento+')').each(function(){
										 alert($(this).text());
							});*/
}
function ocultaAyuda(){
	$('#titulo_enlace').hide();
}
$().mousemove(function(e){
      ratonX = e.pageX;
});