
function fadeImages(el, img1, img2) {
	
	el.css('background-image', 'url(' + img1.attr('src') + ')');
	img1.hide();
	img2.fadeIn();
	
}

jQuery(document).ready(function() {

	
	jQuery('#pattern').mousemove(function(e) {
		
		var x = e.pageX;
		var w = jQuery(window).width();
		
		if (x > (w/4)*3) {
			jQuery('#background-speed').val(2);
		}else if (x > w/2) {
			jQuery('#background-speed').val(1);
		}else if (x > w/4) {
			jQuery('#background-speed').val(-1);
		} else {
			jQuery('#background-speed').val(-2);
		}
		
	});
	
	
	jQuery('#pattern').mouseout(function() {
		
		jQuery('#background-speed').val(0);
		
	});
	
	function scrollBackground() {
	

		
			var p = jQuery('body').css('background-position').replace(' ', '').replace('px', '').replace('50%', '');
			p = parseInt(p);
			//alert(jQuery('body').css('background-position'));
			//alert(p);
			var s = jQuery('#background-speed').val();
			s = parseInt(s);
			jQuery('body').css('background-position', p + s + 'px 50%');
			//sleep(1000);

		
		//alert(p + s);
		setTimeout(function() {scrollBackground();}, 60);
	
	}
	
	scrollBackground();
	
	
	jQuery(window).scroll(function() {
		
		jQuery('#menu').css('left', jQuery(window).scrollLeft() + 'px');
        jQuery('#secretaria').css('right', '-' + (jQuery(window).scrollLeft() - 30) + 'px');
		
	});
	
	jQuery('div.home_fotos').each(function() {
		
		jQuery(this).css('background-image', 'url(' + jQuery(this).children('img.cor').attr('src') + ')');
		
	});
	
	jQuery('.home_fotos_overlay').hover(
	
		function() {
			
			var el = jQuery(this).parents('div.home_fotos');
			
			var img1 = el.children('img.pb');
			var img2 = el.children('img.cor');
			fadeImages(el, img1, img2);
			
			
		},
		function() {
			var el = jQuery(this).parents('div.home_fotos');
			var img2 = el.children('img.pb');
			var img1 = el.children('img.cor');
			fadeImages(el, img1, img2);
		}
	
	
	);

	jQuery('.home_destaques_unicos').hover(function() {
	
		//jQuery(this).children('img').css('z-index', 10);
		
		var idAtual = this.id;
		
		jQuery('.home_destaques').each(function() {
		
			if (this.id != idAtual)
				jQuery(this).animate({opacity: 0.3});
		
		});
		
		jQuery(this).children('.home_destaques_unicos_details').css('z-index', 5).css('opacity', 0).show().animate(
			{
			left: '80px',
			opacity: 1
			}
		);
		
	
		}, 
		function() {
			var th= this;
			jQuery(this).children('.home_destaques_unicos_details').animate(
				{
				left: '0px',
				opacity: 0
				},
				'normal',
				'swing',
				function() { jQuery(th).children('.home_destaques_unicos_details').hide(); }
			);
			//jQuery(this).children('img').css('z-index', 1);
			
			var idAtual = this.id;
			
			jQuery('.home_destaques').each(function() {
			
				if (this.id != idAtual)
					jQuery(this).animate({opacity: 1});
			
			});
		
		
		}
		
	);


});
