//Smooth Scroll
$(document).ready(function(){
    $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({scrollTop: targetOffset}, 1000);
                return false;   
            }   
        } 
    }); 
});
//menu fade
$(document).ready(function() {
	$("ul#menuFade li").hover(function() { //On hover...
		var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'
		//Set a background image(thumbOver) on the <a> tag - Set position to bottom
		$(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
		//Animate the image to 0 opacity (fade it out)
		$(this).find("span").stop().fadeTo('normal', 0 , function() {
			$(this).hide() //Hide the image after fade
		});
	} , function() { //on hover out...
		//Fade the image to full opacity 
		$(this).find("span").stop().fadeTo('normal', 1).show();
	});

});
//noticias fade
$(document).ready( function(){
	$('#news').innerfade({
		animationtype: 'fade',
		speed: 1000,
		timeout: 4000,
		type: 'random', 
		containerheight: '2em'
	});
	$('#statsFade').innerfade({
		animationtype: 'fade',
		speed: 1000,
		timeout: 6000,
		type: 'sequence', 
		containerheight: '20px'
	}); 
	$('#afiliados').innerfade({ 
		animationtype: 'fade',
		speed: 1000,
		timeout: 8000,
		type: 'random', 
		containerheight: '80px'
	}); 
} );
//boton efecto salta
function botonSalta(clase){
$(document).ready(function(){
		$("."+clase).hover(function() {
			$(this).animate({ 
				height: "100px",
				top: "100px",
		  }, 300 );
			$(this).animate({ 
				top: "150px",
				height: "100px",
		  }, 300 );
		},
		function() {
			$(this).animate({ 
				top: "100px",
				height: "100px",
		  }, 250 );
			$(this).animate({ 
				top: "150px",
				height: "50px",
		  }, 200 );
		});
	});
}
botonSalta("feis");
botonSalta("youtube");
botonSalta("twitter");

//Slideshow
$(document).ready(function(){
	var currentPosition = 0;
	var slideWidth = 620;
	var smooth=25;
	var slides = $('.slide');
	var numberOfSlides = slides.length;
	$('#slidesContainer').css('overflow', 'hidden');
	slides.wrapAll('<div id="slideInner"></div>')
	.css({
	  'float' : 'left',
	  'width' : slideWidth
	});
	$('#slideInner').css('width', slideWidth * numberOfSlides);
	$('#slideshow')
		.prepend('<span class="control" id="leftControl">Anterior</span>')
		.append('<span class="control" id="rightControl">Siguiente</span>');
	manageControls(currentPosition);
	
	$('.control').bind('click', function(){
		currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
		manageControls(currentPosition);
		$('#slideInner').animate({
			'marginLeft' : slideWidth*(-currentPosition)
		});
	});
	function manageControls(position){
		if(position==-1){ 
			currentPosition = numberOfSlides-1;
			manageControls(currentPosition);
			$('#slideInner').animate({
				'marginLeft' : slideWidth*(currentPosition)
			});
		}
		if(position==numberOfSlides){
			currentPosition = 0;
			manageControls(currentPosition);
			$('#slideInner').animate({
				'marginLeft' : (slideWidth*(-numberOfSlides+1))-smooth
			});
			$('#slideInner').animate({
				'marginLeft' : (slideWidth*(-currentPosition))+smooth
			});
			$('#slideInner').animate({
				'marginLeft' : slideWidth*(-currentPosition)
			});
		} 
	}
	$.timer(18000, function (timer) {
		currentPosition = currentPosition+1;
		manageControls(currentPosition);
		$('#slideInner').animate({
			'marginLeft' : slideWidth*(-currentPosition)
		});
	});
});