function Cargo(){
	$(".cargo").click(function(){
		UpdateDiv(this.href, this.rel);
		return false;
	});
}

function UpdateDiv(Url, Capa){
	Capa = Capa||"data";
	$.ajax({
		type: 'get',
		url: Url,
		dataType: 'html',
		success: function(data){
			$("#"+Capa).html(data)
		}
	});
}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

$(document).ready(function(){

		$('.clasificacion').find('tr.par, tr.impar').hover(function() {
			$(this).addClass('ui-widget-header');
		}, function() {
			$(this).removeClass('ui-widget-header');
		});

       $("ul.sf-menu").show().supersubs({
           minWidth:    17,   // minimum width of sub-menus in em units
           maxWidth:    17,   // maximum width of sub-menus in em units
           extraWidth:  1     // extra width can ensure lines don't sometimes turn over
                              // due to slight rounding differences and font-family
       }).superfish();  // call supersubs first, then superfish, so that subs are
                        // not display:none when measuring. Call before initialising
                        // containing tabs for same reason.
	$('.menu ul ul li:last-child a').attr('class', 'last');
	if($.browser.msie){
		userAgent = $.browser.version;
		userAgent = userAgent.substring(0,userAgent.indexOf('.'));
		version = userAgent;
		if (version == 6) {
			DD_belatedPNG.fix('img, div, form, input');
		}
	}

	$(".main_image .desc").show(); //Show Banner
	$(".main_image .block").animate({ opacity: 0.85 }, 1 ); //Set Opacity

	//Click and Hover events for thumbnail list
	$(".image_thumb ul li:first").addClass('active');
	$(".image_thumb ul li").click(function(){
		//Set Variables
		var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
		var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
		var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
		var imgDescHeight = $(".main_image").find('.block').height();	//Calculate height of block
		if ($(this).is(".active")) {  //If it's already active, then...
			return false; // Don't click through
		}
		else {
			//Animate the Teaser
			$(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
				$(".main_image .block").html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 250 );
				$(".main_image").css('background', '#fff url("'+ imgTitle +'") no-repeat center top');
				$(".main_image img").remove();
			});
		}
		$(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
		$(this).addClass('active');  //add class of 'active' on this list only
		return false;
	}) .hover(function(){
		$(this).addClass('hover');
		}, function() {
		$(this).removeClass('hover');
	});

	//Toggle Teaser
	$("a.collapse").click(function(){
		$(".main_image .block").slideToggle();
		$("a.collapse").toggleClass("show");
		return false;
	});

	jQuery('#mycarousel').jcarousel({
        auto: 5,
        initCallback: mycarousel_initCallback
    });

	Cargo();
	$('.live').live('click', function() {
		var $titulo = $(this).attr('href');
		$('body').append('<iframe id="resgal" src="'+$titulo+'" style="width:1000px;height:auto; overflow:hidden;"></iframe>');
		$('#resgal').dialog({
			autoOpen: true,
			width:1024,
			title: 'Directo',
			height: 'auto',
			resizable: false,
			draggable: false,
			modal: true,
			close: function(event, ui) {
				$('#resgal').remove();
			}
		});

		return false;
	});

	$('.der .bloque .fecha a').live('click', function() {
		var $titulo = $(this).attr('href');
		$('body').append('<iframe id="res" src="'+$titulo+'" style="width:760px;height:550px; overflow:hidden;" frameborder="0"></iframe>');
		$('#res').dialog({
			autoOpen: true,
			width:800,
			title: 'Estadísticas',
			height: 500,
			resizable: false,
			draggable: false,
			modal: true,
			close: function(event, ui) {
				$('#res').remove();
			}
		});

		return false;
	});

	$('.image').live('click', function() {
		var $titulo = $(this).attr('href');
		$('body').append('<iframe id="resgal2" src="'+$titulo+'" style="width:800px;height:auto; overflow:hidden;border:0"></iframe>');
		$('#resgal2').dialog({
			autoOpen: true,
			width:824,
			title: 'Galeria',
			height: 'auto',
			resizable: false,
			draggable: false,
			modal: true,
			close: function(event, ui) {
				$('#resgal2').remove();
			}
		});
		return false;
	});
});

$('.ishare').ishare();

$('.masgalerias').live('click', function() {
	var destino = $('#ts-display-pf-col-3');
	destino.hide('slide', '', 500, function() {
		destino.attr('lang', parseInt(destino.attr('lang'))+1);
		$.ajax({
			url: 'modulos/multimedia.php',
			type: 'POST',
			data: { mas: 1, pag: destino.attr('lang') },
			success: function(data) {
				destino.html(data.datos);
				if (data.pagina >= destino.attr('lang')) {
					$('.masgalerias').hide(100);
				}
				if (destino.attr('lang') > 0) {
					$('.menosgalerias').show(100);
				}
			},
			complete: function() {
				destino.show('slide', '', 500);
			}
		});
	});
});

$('.menosgalerias').live('click', function() {
	var destino = $('#ts-display-pf-col-3');
	destino.hide('slide', '', 500, function() {
		destino.attr('lang', parseInt(destino.attr('lang'))-1);
		$.ajax({
			url: 'modulos/multimedia.php',
			type: 'POST',
			data: { mas: 1, pag: destino.attr('lang') },
			success: function(data) {
				destino.html(data.datos);
				if (data.pagina >= destino.attr('lang')) {
					$('.masgalerias').show(100);
				}
				if (destino.attr('lang') == 0) {
					$('.menosgalerias').hide(100);
				}
			},
			complete: function() {
				destino.show('slide', '', 500);
			}
		});
	});
});


