
function rollover(target, from, to) {
	target.mouseenter(function() {
		$(this).stop();
		$(this).animate({
			backgroundPosition: '0 -'+to+'px'
		}, 100, 'easeOutQuad');
	});
	target.mouseleave(function() {
		$(this).stop();
		$(this).animate({
			backgroundPosition: '0 -'+from+'px'
		}, 100, 'easeInQuad');
	});
}

$(document).ready(function() {
	
	// COMMON
	
	$('nav a').mouseenter(function() {
		var span = $(this).find('span');
		span.stop();
		span.animate({
			width: $(this).width()
		}, 250);
	});
	$('nav a').mouseleave(function() {
		var span = $(this).find('span');
		span.stop();
		span.animate({
			width: 0
		}, 250);
	});
	
	if ( $('body').attr('class') != 'home_body'){
		$('.work .visu').mouseenter(function() {
			if ($(this).parent().attr('id') != 'work_visu') {
				$(this).find(':first').stop();
				$(this).find(':first').animate({
					marginTop: -186
				}, 250, 'easeOutQuad');
			}
		});
		$('.work .visu').mouseleave(function() {
			if ($(this).parent().attr('id') != 'work_visu') {
				$(this).find(':first').stop();
				$(this).find(':first').animate({
					marginTop: 0
				}, 250, 'easeInQuad');
			}
		});
	}

	
	
	// INDEX
	
	
	
	
	// TRABAJOS
	
	if ($('body').attr('id') == 'works' || $('body').attr('id') == 'work_details')  {
	
		$('#work_visu').nivoSlider({
			effect: 'sliceUpDown',
			slices: 6,
			animSpeed: 500,
			pauseTime: 5000
		});
		
	}
	
	if ($('body').attr('id') == 'works') {
		$('.work_expand').css('height', 0);
		
		$('#all_works .work').mouseenter(function() {
			var expandable = $(this).find('.work_expand');
			expandable.stop();
			expandable.animate({
				height: 199
			}, 250);
		});
		
		$('#all_works .work').mouseleave(function() {
			var expandable = $(this).find('.work_expand');
			expandable.stop();
			expandable.animate({
				height: 0
			}, 250);
		});
		
		var url = $('#main_work').attr('href');
	
		$('#main_work').remove();
	
		$('.nivo-slice').css('cursor', 'pointer');
		$('.nivo-slice').click(function() {
			window.location.href = url;
		});
		
				
	}
	
	
	
	if ($('body').attr('id') == 'work_details') {
	
		rollover($('#visit'), 46, 69);
		rollover($('#imagenes'), 220, 243);
		rollover($('#video1'), 0, 23);
		rollover($('#video2'), 0, 23);
		rollover($('#video3'), 0, 23);
		rollover($('#video4'), 0, 23);
		rollover($('#video5'), 0, 23);
		rollover($('#suscribir'), 174, 197);
		rollover($('#cerrar'), 92, 110);
		//rollover($('#watch_video'), 688, 720);
		
	}
	
});
