// JavaScript Document
$(document).ready(function() {
	$('ul li:has(ul)').hover(
	function(a)
	{
		$(this).find('ul').slideDown("slow");
	},
	function(a)
	{
		$(this).find('ul').slideUp("slow");
	}
);
	$('.submenu li a').css( {backgroundPosition: "0px 0px"} ).hover(
		function(){
		$(this).stop().animate({backgroundPosition: "(0px -99px)"}, 250);
		},
		function(){
		$(this).stop().animate({backgroundPosition: "(0px 0px)"}, 250);
		}
	);	
});

$(document).ready(function() {
	// Muestra y oculta los menús
	$('ol li:has(ol)').hover(
		function(e)
		{
			$(this).find('ol').fadeIn("slow");
		},
		function(e)
		{
			$(this).find('ol').fadeOut("slow");
		}
	);
});

$(document).ready(function(){
         $('.boton_contacto a').hover(function(){
		         $(this).stop().animate({'opacity' : '0'}, 500);
		 }, function(){$(this).stop().animate({'opacity' : '1'}, 500);});
});
$(document).ready(function(){
         $('.boton_calendario a').hover(function(){
		         $(this).stop().animate({'opacity' : '0'}, 500);
		 }, function(){$(this).stop().animate({'opacity' : '1'}, 500);});
});
$(document).ready(function(){
         $('.boton_aula a').hover(function(){
		         $(this).stop().animate({'opacity' : '0'}, 500);
		 }, function(){$(this).stop().animate({'opacity' : '1'}, 500);});
});
$(document).ready(function(){
         $('.boton_catalogo a').hover(function(){
		         $(this).stop().animate({'opacity' : '0'}, 500);
		 }, function(){$(this).stop().animate({'opacity' : '1'}, 500);});
});
$(document).ready(function(){
         $('.boton_idiomas a').hover(function(){
		         $(this).stop().animate({'opacity' : '0'}, 500);
		 }, function(){$(this).stop().animate({'opacity' : '1'}, 500);});
});
$(document).ready(function(){
         $('.boton_sep a').hover(function(){
		         $(this).stop().animate({'opacity' : '0'}, 500);
		 }, function(){$(this).stop().animate({'opacity' : '1'}, 500);});
});
$(document).ready(function(){
         $('.boton_ia a').hover(function(){
		         $(this).stop().animate({'opacity' : '0'}, 500);
		 }, function(){$(this).stop().animate({'opacity' : '1'}, 500);});
});
$(document).ready(function(){
         $('.boton_si a').hover(function(){
		         $(this).stop().animate({'opacity' : '0'}, 500);
		 }, function(){$(this).stop().animate({'opacity' : '1'}, 500);});
});
$(document).ready(function(){
         $('.boton_rt a').hover(function(){
		         $(this).stop().animate({'opacity' : '0'}, 500);
		 }, function(){$(this).stop().animate({'opacity' : '1'}, 500);});
});
$(document).ready(function(){
         $('.boton_registro a').hover(function(){
		         $(this).stop().animate({'opacity' : '0'}, 500);
		 }, function(){$(this).stop().animate({'opacity' : '1'}, 500);});
});
$(document).ready(function(){
         $('.boton_video a').hover(function(){
		         $(this).stop().animate({'opacity' : '0'}, 500);
		 }, function(){$(this).stop().animate({'opacity' : '1'}, 500);});
});
/* paginacion convo, talleres, casos*/
(function($){

// Creating the sweetPages jQuery plugin:
$.fn.sweetPages = function(opts){
	
	// If no options were passed, create an empty opts object
	if(!opts) opts = {};
	
	var resultsPerPage = opts.perPage || 3;
	
	// The plugin works best for unordered lists, althugh ols would do just as well:
	var ul = this;
	var li = ul.find('li');
	
	li.each(function(){
		// Calculating the height of each li element, and storing it with the data method:
		var el = $(this);
		el.data('height',el.outerHeight(true));
	});
	
	// Calculating the total number of pages:
	var pagesNumber = Math.ceil(li.length/resultsPerPage);
	
	// If the pages are less than two, do nothing:
	if(pagesNumber<2) return this;

	// Creating the controls div:
	var swControls = $('<div class="swControls">');
	
	for(var i=0;i<pagesNumber;i++)
	{
		// Slice a portion of the lis, and wrap it in a swPage div:
		li.slice(i*resultsPerPage,(i+1)*resultsPerPage).wrapAll('<div class="swPage" />');
		
		// Adding a link to the swControls div:
		swControls.append('<a href="" class="swShowPage">'+(i+1)+'</a>');
	}

	ul.append(swControls);
	
	var maxHeight = 0;
	var totalWidth = 0;
	
	var swPage = ul.find('.swPage');
	swPage.each(function(){
		
		// Looping through all the newly created pages:
		
		var elem = $(this);

		var tmpHeight = 0;
		elem.find('li').each(function(){tmpHeight+=$(this).data('height');});

		if(tmpHeight>maxHeight)
			maxHeight = tmpHeight;

		totalWidth+=elem.outerWidth();
		
		elem.css('float','left').width(ul.width());
	});
	
	swPage.wrapAll('<div class="swSlider" />');
	
	// Setting the height of the ul to the height of the tallest page:
	ul.height(maxHeight);
	
	var swSlider = ul.find('.swSlider');
	swSlider.append('<div class="clear" />').width(totalWidth);

	var hyperLinks = ul.find('a.swShowPage');
	
	hyperLinks.click(function(e){
		
		// If one of the control links is clicked, slide the swSlider div 
		// (which contains all the pages) and mark it as active:

		$(this).addClass('active').siblings().removeClass('active');
		
		swSlider.stop().animate({'margin-left':-(parseInt($(this).text())-1)*ul.width()},'slow');
		e.preventDefault();
	});
	
	// Mark the first link as active the first time this code runs:
	hyperLinks.eq(0).addClass('active');
	
	// Center the control div:
	swControls.css({
		'left':'50%',
		'margin-left':-swControls.width()/2
	});
	
	return this;
	
}})(jQuery);

/*convocatoria, cartelera, casos */
$(document).ready(function(){
	/* The following code is executed once the DOM is loaded */
	
	// Calling the jQuery plugin and splitting the
	// #holder UL into pages of 3 LIs each:
	
	$('#holder').sweetPages({perPage:3});
	
	// The default behaviour of the plugin is to insert the 
	// page links in the ul, but we need them in the main container:

	var controls = $('.swControls').detach();
	controls.appendTo('#main');
	
});

/* Noticias NO*/
$(function() {
        $('.imgb').hover(function() {
            $(this).children('.notice').stop().animate({ "top" : '160px'}, 600);   
        }, function() {
            $(this).children('.notice').stop().animate({ "top" : '0px'}, 300);       
        });
    });
/*lig*/
$(document).ready(function() {
	$('a.jq').hover(function() {
		$(this).animate({paddingLeft: '20px'},400);
	}, function() {
		$(this).animate({paddingLeft: 0}, 400);
	});
});
/*Video*/
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#boton").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
