function jquery_ap (elemento, loading, rule) {
    var url     =   elemento.href;
    var esDeCod = url.match(/\?/g);
    if (esDeCod==null){
        url = unescape(url);
    }
    var args = url.split("?")[1];
    var aP = args.split("aP=")[1];
    aP = unescape(aP.split("&")[0]);
    var ctn = args.split("ctn=")[1];
    ctn = ctn.split("&")[0];

	if (arguments.length == 3) {
    	var fin =  function () {
        	$("#"+ctn).each(rule);
    	};
	} else {
		var fin = function() {
			void(0);
		};
	}

	if (arguments.length == 1)
		loading = false;

	var contenido = $('#'+ctn).attr('innerHTML');

	$.ajax({
   		type: "GET",
	    url: "/modulo/index.html",
   		data: aP,
		complete: fin,
		beforeSend: function() {
			if (!loading) {
				void(0);
			} else {
	        	$('#'+ctn).attr('innerHTML', TEXTO_CARGANDO_PESTANA);
			}
	    },
   		success: function(html) {
			html=html.replace(/[\t\n]+/g," ");
			var patt = new RegExp(/<!-- -1 -->/);
			if (!patt.test(html)) {
					var patt = new RegExp(/<script/i);
					if (patt.test(html)) {

						var patt = new RegExp("(.*)<sc"+"ript[^>]*>(.*)</sc"+"ript>(.*)");
						var result = patt.exec(html);

						cabhtml = result[1].replace(/"/g, '\\"');
						piehtml = result[3].replace(/"/g, '\\"');

						var scrt = document.createElement('script');

						scrt.language = 'javascript'; 
						scrt.type = 'text/javascript';
						scrt.defer = true;
						scrt.text = result[2]+'loadEmbedObjectInDiv(document.getElementById("'+ctn+'"),"'+cabhtml+'"+strAux+"'+piehtml+'");';

						document.getElementsByTagName("head")[0].appendChild(scrt);

					} else
						$('#'+ctn).attr('innerHTML', html);
						//$('#player-videos').attr('innerHTML', html);
			} else {
						$('#'+ctn).attr('innerHTML', contenido);
						//$('#player-videos').attr('innerHTML', contenido);
			}
		}
	});
}

var fotogalerias_olimpiadas = {
	pagina: 0,
	medio: null,
    xref: null
}



function Mio_reloadCallback(a) {
}

var carga_pestanas_multimedia = function(){
		$('a#pestana_videos_ya_no_se_usa').click(function(){
                        $('#pestana_fot').removeClass("der_marc"); 
                        $('#pestana_fot').addClass("der");
                        $('#pestana_grf').removeClass("centro_marc"); 
                        $('#pestana_grf').addClass("centro");

                        $('#pestana_vid').removeClass("izq");
                        $('#pestana_vid').addClass("izq_marc");
			$.ajax({
				type: "GET",
				data: "modulo=ESPOlimpiadasVideosPortadillaOU&params=vista%3Dportadilla%26medio%3D"+fotogalerias_olimpiadas.medio,
				url: "/modulo/index.html",
				success: function(datos){
					$('#contenido_multimedia').html(datos);
					//recarga_otros_videos();
					$('div#carrusel-videos').each(carga_lista_videos);
				},
                                complete: function() {
	                                $('#carrusel-videos ul').jcarousel({
						scroll: 1,
						reloadCallback: Mio_reloadCallback
					});
					recarga_otros_videos();
                                }
			});
			return false;
		}),

		$('li#pestana_fot a#pestana_fotos').click(function(e){
                        $('#pestana_vid').removeClass("izq_marc");
                        $('#pestana_vid').addClass("izq");
			$('#pestana_grf').removeClass("centro_marc"); 
			$('#pestana_grf').addClass("centro");

                        $('#pestana_fot').removeClass("der");
                        $('#pestana_fot').addClass("der_marc");
			$.ajax({
				type: "GET",
				data: "modulo=ESPOlimpiadasFotos&params=pagina%3D"+fotogalerias_olimpiadas.pagina+'%26medio%3D'+fotogalerias_olimpiadas.medio,
				url: "/modulo/index.html",
				success: function(datos){
					$('#contenido_multimedia').html(datos);
					$('div#player-videos div.meta').each(carga_fotogaleria_paginado);
					$('div#carrusel-videos').each(carga_carrusel_fotogalerias);
				}, 
                complete: function() {
                    $('#carrusel-videos ul').jcarousel();
                }
			});
			return false;
		}),
		$('#pestana_graficos').click(function(e){
			$('#pestana_vid').removeClass("izq_marc");
			$('#pestana_vid').addClass("izq");
			$('#pestana_fot').removeClass("der_marc");
			$('#pestana_fot').addClass("der");

			$('#pestana_grf').removeClass("centro"); 
			$('#pestana_grf').addClass("centro_marc");
			$.ajax({
				type: "GET",
				data: 'modulo=ESPOlimpiadasGraficosContedoraOU&params=medio%3D'+fotogalerias_olimpiadas.medio,
				url: "/modulo/index.html",
				success: function(datos){
					$('#contenido_multimedia').html(datos);
					$('div#graficos div.inferior').each(carga_lista_graficos);
					$('div#carrusel-videos').each(sin_carrusel);
				}
			});
			return false;
		})
}

var carga_lista_graficos = function() {
	$('div#graficos div.inferior a').click(
		function() {
			var datos = this.getAttribute('data');

			$.ajax({
				type: "GET",
				data: datos,

				url: "/modulo/index.html",
				success: function(datos){
					$('#contenido_multimedia').html(datos);
					$('div#graficos div.inferior').each(carga_lista_graficos);
				}
			});
			
			return false;
		}
	)
}

var sin_carrusel = function() {
	$('div#carrusel-videos ul.estirar li a.video-token,div.mod-videos ul li.estirar a').click(
		function() {}
	)
}

var carga_lista_videos = function() {
		$('div#carrusel-videos ul.estirar li a.video-token,div.mod-videos ul li.estirar a').click(
			function() {
				$('div#player_video_olimpiadas').html('');
				var a = document.createElement('a');
				a.href= this.getAttribute('link');

				//jquery_ap(a, false, carga_jcarrusel_lista_videos);
				jquery_ap(a, false);
				return false;
			}
		)
}


var otros_videos=function() {

        $('div.video-anterior_no_se_usa a').click (
            function(){
                 $('div#player_video_olimpiadas').html('');
                 var a = document.createElement('a');
                 a.href= this.getAttribute('link');

                 jquery_ap(a, false, carga_jcarrusel_lista_videos);
                 return false;
                 }
    )                                                                             
}


var carga_jcarrusel_lista_videos = function() {
	$('#carrusel-videos ul').jcarousel();
	$('div#carrusel-videos ul,div.mod-videos ul').each(carga_lista_videos);
    //$('div.anteriores').ready (otros_videos);
    $('div.anteriores').ready (carga_lista_videos);
}



var modulo_videos_portada=function() {
        $('div#contenido_modulo_multimedia  a').click(
            function(){
                $('div#contenido_modulo_multimedia').html('');
                var a = document.createElement('a');
                a.href= this.getAttribute('link');
                jquery_ap(a, false, modulo_videos_portada);
               return false;
            }
            )
}

var carga_carrusel_fotogalerias = function() {
	$('div#carrusel-videos ul.jcarousel-list li.jcarousel-item a.fotogaleria-token').click(
		function() {
				var xref = this.getAttribute('xref');
                fotogalerias_olimpiadas.xref = xref;
                fotogalerias_olimpiadas.pagina = 0;
				$.ajax({
						type: "GET",
	data: "modulo=ESPOlimpiadasFotos&params=pagina%3D0%26xref%3D"+xref+'%26medio%3D'+fotogalerias_olimpiadas.medio+'%26nav%3D1',
						url: "/modulo/index.html",
						success: function(datos){
								//$('#contenido_multimedia').html(datos);
								$('#nav_multimedia_oli').html(datos);
								$('div#player-videos div.meta').each(carga_fotogaleria_paginado);
								//$('div#carrusel-videos').each(carga_carrusel_fotogalerias);
						}
				});

				return false;
		}
	)
}

var carga_fotogaleria_paginado = function() {
		$('div#player-videos div.meta a#anterior_fotog,div#player-videos div.meta a#siguiente_fotog').click(
			function() {
					switch (this.getAttribute('id')) {
						case 'anterior_fotog':
							if (fotogalerias_olimpiadas.pagina > 0)
								fotogalerias_olimpiadas.pagina = fotogalerias_olimpiadas.pagina - 1;
							break;
						case 'siguiente_fotog':
							fotogalerias_olimpiadas.pagina = fotogalerias_olimpiadas.pagina + 1;
							break;
					}
					
					var url_datos = "modulo=ESPOlimpiadasFotos&params=pagina%3D"+fotogalerias_olimpiadas.pagina+'%26nav%3D1%26%26medio%3D'+fotogalerias_olimpiadas.medio;
                    if (fotogalerias_olimpiadas.xref)
					    url_datos = url_datos + '%26xref%3D'+fotogalerias_olimpiadas.xref;
					$.ajax({
						type: "GET",
						data: url_datos,

						url: "/modulo/index.html",
						success: function(datos){
								$('#nav_multimedia_oli').html(datos);
								$('div#player-videos div.meta').each(carga_fotogaleria_paginado);
								//$('div#carrusel-videos').each(carga_carrusel_fotogalerias);
						}
				});

				return false;
			}
		)
}
$(document).ready(modulo_videos_portada);
$(document).ready(carga_pestanas_multimedia);
$(document).ready(carga_carrusel_fotogalerias);
$(document).ready(carga_fotogaleria_paginado);
$(document).ready(carga_lista_videos);
//$(document).ready(otros_videos);
$(document).ready(
    function(){
            $('#carrusel-videos ul').jcarousel();
    }
);
                



function recarga_otros_videos() {

		$('.a-anterior').click(
			function() {
                $('div#player_video_olimpiadas').html('');
	            var a = document.createElement('a');
				a.href= this.getAttribute('link');
				//jquery_ap(a, false, carga_jcarrusel_lista_videos);
				//jquery_ap(a, false, "player-videos");
				jquery_ap(a, false);
				//return false;
			}
		);
}


$('div.anteriores').ready (
	function() {
		recarga_otros_videos();
	}
);


//$(document).ready(recarga_otros_videos());





function pestanas_modulo_multimedia(){
        $('#modulo_fotos').click(function(e){
               $('#modulo_videos').removeClass("activo");
               $('#modulo_graficos').removeClass("activo"); 
               $('#modulo_audios').removeClass("activo");
               $('#modulo_fotos').addClass("activo");

               $.ajax({
                       type: "GET",
                       data: "modulo=ESPOlimpiadasFotos&params=pagina%3D"+fotogalerias_olimpiadas.pagina+'%26medio%3D'+fotogalerias_olimpiadas.medio+'%26tipo%3Dmodulo',
                       url: "/modulo/index.html",
                       success: function(datos){
                               $('#contenido_modulo_multimedia').html(datos);
                               $('div#carrusel-videos').each(carga_lista_videos);
                       }
               });

               return false;
        }),
        
        $('#modulo_videos').click(function(e){
               $('#modulo_videos').addClass("activo");
               $('#modulo_graficos').removeClass("activo");
               $('#modulo_audios').removeClass("activo");
               $('#modulo_fotos').removeClass("activo");

               $.ajax({
                       type: "GET",
                       data: "modulo=ESPOlimpiadasVideosPortadillaOU&params=vista%3Dmodulo%26medio%3D"+fotogalerias_olimpiadas.medio,
                       url: "/modulo/index.html",
                       success: function(datos){
                               $('#contenido_modulo_multimedia').html(datos);
                               $('div#carrusel-videos').each(carga_lista_videos);
			       $(document).ready(modulo_videos_portada);
                       }
               });

               return false;
        }),
        
        $('#modulo_audios').click(function(e){
               $('#modulo_videos').removeClass("activo");
               $('#modulo_audios').addClass("activo");
               $('#modulo_fotos').removeClass("activo");

               $.ajax({
                       type: "GET",
                       data: "modulo=ESPMODOlimpiadaAudiosCadenaserOU&params=vista%3DmoduloMultimedia",
                       url: "/modulo/index.html",
                       success: function(datos){
                               $('#contenido_modulo_multimedia').html(datos);
                       }
               });

               return false;
        });
}


$(document).ready(pestanas_modulo_multimedia);
