//Prepara las funciones que deben ejecutarse al inicio
$(window).load(function(){
	$("#link_buscar").click(function() {
  		$("#form_busc").submit()
  	});
	$('.pub').LDFlash();
	reloj();
});

/****************************************************************************************************************************/

//Enviamos el formulario de suscripcion
function suscripcion(p){
	var page = p;
	var dataString = $("#form_suscript").serialize();
	$.ajax({
		type:"POST", 
		url:page,
		dataType:"json",
		error: function (XMLHttpRequest, textStatus, errorThrown){suscripcion(page);},
		data:dataString,
		timeout:5000,
		success: suscripcion_rsp
	});  
}

function suscripcion_rsp(data){
	if(data.error){
		$(".suscr_marco").hide();
		$(".suscr_marco_no").show();
	}else{
		if(data.e1 == 0){
			$(".suscr_marco").hide();
			$(".suscr_marco_ok").show();
		}else{
			$(".suscr_marco").hide();
			$(".suscr_marco_rep").show();
		}
	}
}

function suscripcion_reset(){
	$(".suscr_marco").show();
	$(".suscr_marco_ok").hide();
	$(".suscr_marco_no").hide();
	$(".suscr_marco_rep").hide();
}




//Se usa para colocar animaciones estáticas en el sitio
(function( $ ){  
	$.fn.LDFlash = function(opciones_user){
		var playerVersion = swfobject.getFlashPlayerVersion();
		var ver = playerVersion.major + "." + playerVersion.minor + "." +playerVersion.release;
		var element = $(this);
		element.each(function(u,v){
			var id = $(this).attr('id');				  
			var title = $(this).attr('title');
			var width = $(this).css('width');
			var height = $(this).css('height');
			var float = $(this).css('float');
			var mt = $(this).css('margin-top');
			var ml = $(this).css('margin-left');
			var mr = $(this).css('margin-right');
			if(id != '' && title != ''){
				$(this).wrap('<div class="'+id+'_new" />');
				var element_new = $('.'+id+'_new');
				element_new.css('width',width);
				element_new.css('height',height);
				element_new.css('float',float);
				element_new.css('margin',mt+' '+mr+' 0px '+ml+'');
				$(this).css('margin',0);
				swfobject.embedSWF(title,id,width,height,ver,{},{},{wmode:'transparent'});	
			}
		});
	}
})(jQuery);

/****************************************************************************************************************************/
//Cargamos el flash player con todas las configuraciones
function flash_embed(f,d,w,h,e,v,p,a){
	if(document.getElementById(d)){	
		var flashvars = v;
		var params = p;
		var attributes = a;
		var playerVersion = swfobject.getFlashPlayerVersion();
		var ver = playerVersion.major + "." + playerVersion.minor + "." +playerVersion.release;
		swfobject.embedSWF(f,d,w,h,ver,e+'swf/expressInstall.swf',flashvars,params,attributes);	
	}
}

/****************************************************************************************************************************/
//Función para la asignacion de una clase a una lista
(function( $ ){  
	$.fn.LDALista = function(opciones_user){
		opciones_default = {
			clase1:'',
			name:'default123'
		};	
		opc = jQuery.extend(opciones_default,opciones_user);
		$(this).each(function(j,u){
			$(this).addClass(opc.name);
			if(j == 0)$(this).addClass(opc.clase1);	
			$(this).click(function(){
				$('.'+opc.name).removeClass(opc.clase1);
				$(this).addClass(opc.clase1);					   
			});
		});
	}
})(jQuery);

/****************************************************************************************************************************/
//Funcion de temporización
var Temporizador = function(){
	this.Intervalo = 1000;
    this.Activo = new Boolean(false);
    this.Ejecucion;
    var temporizadorId = 0;
	var instancia;
	var flag = false;
	instancia = this;
	this.Iniciar = function() {
		this.Activo = new Boolean(true);
        
		if (instancia.Activo){
			this.flag = true;
		    instancia.temporizadorId = setInterval(function(){instancia.Ejecucion(1,0);},instancia.Intervalo);
		}
   	};
	this.Detener = function(){            
		this.flag = false
		instancia.Activo = new Boolean(false);
		clearInterval(instancia.temporizadorId);
    };
	this.Estado = function(){
		return this.flag;
	};
};



function play_fader(d,a){
	var div = d;
	var aux = Array();
	var i = 0;
	$(a).each(function(j,u){
		aux[j] = $(this).attr('id');
		if(j > 0) $(this).hide();
		i++;		
	});
	var xold = 0;
	var xnew = 0;
	var xmax = i-1;
	this.cruzar = function(s,t){
		if(t > 0)
			xnew = (s - 1);
		else
			xnew = xnew + 1;
		if(xnew > xmax)	xnew = 0;
		if(xnew < 0)	xnew = 0;
		$(d).fadeIn('normal', function(){
			$('#'+aux[xold]).hide();
			$('#'+aux[xnew]).show();
			xold = xnew; 
		}).fadeOut('normal');
	};
	
	this.cruzar_fast = function(s,t){
		if(t > 0)
			xnew = (s - 1);
		else
			xnew = xnew + 1;
		if(xnew > xmax)	xnew = 0;
		if(xnew < 0)	xnew = 0;
		$('#'+aux[xold]).hide(0);
		$('#'+aux[xnew]).show(0);
		xold = xnew; 
	};
};



function play_slide(d,a){
	var div = d;
	var aux = Array();
	var i = 0;
	$(a).each(function(j,u){
		aux[j] = $(this).attr('id');
		i++;		
	});
	var xold = 0;
	var xnew = 0;
	var xmax = i-1;
	this.cruzar = function(s){
		if(s >= 0){
			if(s == 1)
				xnew = xnew + 1;
			else
				xnew = xnew - 1;
		}
		else
			xnew = xnew + 1;
		if(xnew > xmax)	xnew = 0;
		if(xnew < 0)	xnew = 0;
		$(d).scrollTo($("#"+aux[xnew]),1500);
	};
};














/* Abrir una pagina como popup */
function imprimir(ancho,alto,pag){
	var Left = (screen.width-ancho)/2;
	var Top = (screen.height-alto)/2;
	var p = 'no';
	var opciones = 'toolbar='+p+',location='+p+',directories='+p+',status='+p+',menubar='+p+',scrollbars=yes,resizable='+p+',';
	opciones = opciones + 'width='+ancho+',height='+alto+',top='+Top+',left='+Left+'';
	window.open(pag,"ventana",opciones);
}

/*Fecha y hora colocados en un div */
var nmes = new Array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre');
var ndia = new Array('Domingo', 'Lunes', 'Martes','Miércoles', 'Jueves', 'Viernes','Sábado');
function reloj(){
	ahora = new Date()
    minuto = ahora.getMinutes()
    segundo = ahora.getSeconds()
	dia = ahora.getDate()
	day = ahora.getDay()
	anio = ahora.getFullYear();
	mes = ahora.getMonth()
	if(minuto < 10)	minuto = '0'+minuto;
	ha = ndia[day]+" "+dia+" de "+nmes[mes]+" de "+anio+" | "+ ahora.getHours()+ ":" + minuto+" hs.";
	document.getElementById('clock').innerHTML = ha;
    setTimeout("reloj()",1000);
}
