// RESTRICT NUMERIC INPUT
jQuery.fn.forceNumeric = function () {

	return this.each(function () {
	    $(this).keydown(function (e) {
	        var key = e.which || e.keyCode;

	        if (!e.shiftKey && !e.altKey && !e.ctrlKey &&
	        // numbers   
	            key >= 48 && key <= 57 ||
	        // Numeric keypad
	            key >= 96 && key <= 105 ||
	        // comma, period and minus, . on keypad
	           key == 190 || key == 188 || key == 109 || key == 110 ||
	        // Backspace and Tab and Enter
	           key == 8 || key == 9 || key == 13 ||
	        // Home and End
	           key == 35 || key == 36 ||
	        // left and right arrows
	           key == 37 || key == 39 ||
	        // Del and Ins
	           key == 46 || key == 45)
	            return true;

	        return false;
	    });
	});
}

$(window).load(function() {
	
	// FLEXSLIDER
	$('.flexslider').flexslider();

	// JCAROUSEL
	$('#mycarousel').jcarousel();
	
	$('#mycarousel figure').hover(function() {
		$(this).parent('.jcarousel-item').css('width', 'auto');
		$(this).children('.nombre').show();
	}, function() {
		$(this).parent('.jcarousel-item').css('width', 70);
		$(this).children('.nombre').hide();
	});

	// // COUNTDOWN
	// 	$(function () {
	// 	var austDay = new Date();
	// 	austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 26);
	// 	$('#defaultCountdown').countdown({until: austDay});
	// 	$('#year').text(austDay.getFullYear());
	// });
	
	// COUNTDOWN
	$(function () {
		$('#defaultCountdown').countdown({
		    until: new Date(2012, 3 - 1, 13,1-4)});
	});
	
	/* http://keith-wood.name/countdown.html
	 * Spanish initialisation for the jQuery countdown extension
	 * Written by Sergio Carracedo Martinez webmaster@neodisenoweb.com (2008) */
	(function($) {
		$.countdown.regional['es'] = {
			labels: ['Años', 'Meses', 'Semanas', 'Días', 'Horas', 'Min.', 'Seg.'],
			labels1: ['Año', 'Mes', 'Semana', 'Día', 'Hora', 'Min.', 'Seg.'],
			compactLabels: ['a', 'm', 's', 'g'],
			whichLabels: null,
			timeSeparator: ':', isRTL: false};
		$.countdown.setDefaults($.countdown.regional['es']);
	})(jQuery);

	// ACCORDION
	$('#accordion').liteAccordion();

	
	// COLORBOX
	$('.colorbox').each(function(){
	  	$(this).colorbox({rel:$(this).attr('data-group')});
	});

	$('.videobox').each(function(){
		  $(this).colorbox({width:'630', height:'380', inline:true, href:"#" + $(this).attr('data-group')});
	});

	// TABS
	$('.tabs').tabs({ fx: { height: 'toggle', opacity: 'toggle' } });
	
	// MENU LOS CASANDRAS
	$('#los-casandra').hover(function() {
		$('#casandras').show();
	});
	
	$('#casandras').mouseleave(function() {
		$(this).hide();
	});

	// MENU CASANDRA 2012
	$('#casandra-2012').hover(function() {
		$('#menu2012').show();
	});
	
	$('#menu2012').mouseleave(function() {
		$(this).hide();
	});
	
	// MENU MULTIMEDIA
	$('#multimedia').hover(function() {
		$('#menuMultimedia').show();
	});
	
	$('#menuMultimedia').mouseleave(function() {
		$(this).hide();
	});
	
	// FORM VALUE
	$('#fbrp__40_1').val('Correo');
	
	// FORCE NUMERIC
	$("#cedula").forceNumeric();
	$("#telefono").forceNumeric();
	
	// TERMINOS CASTING POPUP
	$('.popup').click(function() {
	  $('#terminos').toggle('slow', function() {
	  });
	});
	
	// ROLLOVER CASANDRA PUBLICO
	$('#poll .choice').hover(function() {
		$(this).find('span').css('display', 'inherit');
	}, function() {
		$(this).find('span').css('display', 'none');
	});
	
});
