;(function($) {

$(document).ready(function () {





function init(){
	$("#banners .item").each(function() {
		$('#'+ $(this).attr('id') + ' h3').css({ opacity: 0 });
		$('#'+ $(this).attr('id') + ' h3').css({ display: 'none' });
		$('#'+ $(this).attr('id') + ' .entry-atributes').css({ opacity: 0 });
		$('#'+ $(this).attr('id') + ' img').css({ marginLeft: -150 });
	});
}

var alfaDown = 0.4;

function fallShade(){
	$("#banners .item").each(function() {
		if(!$(this).hasClass('over')){
			$(this).css({ opacity: alfaDown });	
		}
	});
}

function noneShade(){
	$("#banners .item").each(function() {
		if(!$(this).hasClass('narrow')){
			$(this).css({ opacity: 1 });	
		}
	});
}

function singleNoneShade(){
	$("#banners .item").each(function() {
		if($(this).hasClass('narrow')){
			if($(this).hasClass('over')){
				$(this).css({ opacity: 1 });	
			}
		}
	});
}

function singleShade(){
	$("#banners .item").each(function() {
		if($(this).hasClass('narrow')){
				$(this).css({ opacity: alfaDown });	
		}
	});
}

function singleShadeBottom(){
	$("#bottomquatro .post").each(function() {
		if($(this).hasClass('narrow')){
				$(this).css({ opacity: alfaDown });	
		}
	});
}




var slideCount = 0;
var buttonCount = 0;

var slidesArray = [];
var buttonsArray = [];



var buttonsArray = [];

/////
function images(ide,imgholder){
	
	var slideCount = 0;
	var buttonCount = 0;
	
	var slidesArray = [];
	var buttonsArray = [];
	
	function init() {
		//playAndPause();
		showSliding();
	}
	
	
	$("#"+ide+" .image a").each(function() {
		slidesArray.push($(this));
		$(this).attr('rel',slideCount);
		slideCount++;
	});

	
	var playing = true;
	var current = slidesArray.length - 1;
	
	function playAndPause() {
		if(playing){
			playing = false;
		}else{
			playing = true;
			showSliding();
		}
	}


	function loadPic(which) {	
		//slidesArray[current].animate({ opacity: 0.2 }, 200);
		//alert(which);
		$("#"+imgholder).fadeOut(Math.floor(Math.random()*5000) + 3000, function() {
			$("#"+imgholder).attr('src','');

			$("#"+imgholder).fadeIn(Math.floor(Math.random()*5000) + 3000, function() { 
			
			});
			$("#"+imgholder).attr('src',which);
		});
	}

	
	function showSliding() {
		if(playing){
			switchSlide(false, true);
		}
	}
	function switchSlide(reversed, repeatIt) {
		slidesArray[current].removeClass('active');
		//slidesArray[current].animate({ opacity: 0.2 }, 200);
		if(reversed){
			current--;
		}else{
			current++;
		}
		if(current >= slidesArray.length){
			current = 0;
		}

		if(current < 0){
			current = slidesArray.length;
		}
		loadPic(slidesArray[current].attr('href'));
		slidesArray[current].addClass('active');
		//slidesArray[current].animate({ opacity: 1 }, 1000);
		if(slidesArray.length > 1){
			if(repeatIt){
				setTimeout(function() { showSliding(); }, Math.floor(Math.random()*6000) + 5000);
			}
		}else{

		}
	}

	init();
} ////////

var bottomquatroAlfa = 0.55

	$("#bottomquatro .post").each(function() {
		$(this).css({ opacity: bottomquatroAlfa });
		$(this).mouseover( function() {
			$(this).css({ opacity: 1 });
		});
		$(this).mouseout( function() {
			$(this).css({ opacity: bottomquatroAlfa });
		});
	});

	$("#banners .item").each(function() {
		//images($(this).attr('id'));
		images($(this).attr('id'),$("#"+$(this).attr("id")+" img").attr('id'));
		$(this).mouseover( function() {
			$(this).addClass('over');
			if(!$(this).hasClass('moved')){
				fallShade();
			}
			if($(this).hasClass('narrow')){
				singleNoneShade();
			}			
		});
		$(this).mouseout( function() {
			$(this).removeClass('over');
			if(!$(this).hasClass('moved')){
				noneShade();
			}
			if($(this).hasClass('narrow')){
				singleShade();
			}			
		});
		$(this).click( function() {
			widen($(this).attr('id'));
		});
	});

function widen(which){

	$("#banners .item").each(function() {
	$(this).addClass('moved');
	if($(this).attr('id') == which){
		$('#'+ $(this).attr('id') + ' img').animate({ marginLeft: -50 }, 1500);
		$(this).removeClass('narrow');
		$(this).addClass('open');
		$(this).animate({ width: 350 }, 200, function(){ 
			$('#'+ which + ' h3').css({ display: 'block' });
			$('#'+which+' h3').animate({ opacity: 0.5 }, 1000);
			$('#'+which+' .entry-atributes').animate({ opacity: 0.4 }, 1500);
		});
	}else{
		$(this).animate({ width: 100 }, 200);
		$(this).addClass('narrow');
		$(this).removeClass('open');
		$('#'+ $(this).attr('id') + ' h3').css({ opacity: 0 });
		$('#'+ $(this).attr('id') + ' h3').css({ display: 'none' });
		$('#'+ $(this).attr('id') + ' .entry-atributes').css({ opacity: 0 });
		$(this).css({ opacity: alfaDown });
		$('#'+ $(this).attr('id') + ' img').css({ marginLeft: -150 });
	}
	
	});	
	
}
$('#hd,#foot-block').click( function() {
	$("#banners .item").each(function() {
		$(this).removeClass('moved');
		$(this).removeClass('open');
		$(this).removeClass('narrow');
		$(this).animate({ width: 238 }, 995);
		$('#'+ $(this).attr('id') + ' h3').css({ opacity: 0 });
		$('#'+ $(this).attr('id') + ' h3').css({ display: 'none' });
		$('#'+ $(this).attr('id') + ' .entry-atributes').css({ opacity: 0 });
		$(this).css({ opacity: 1 });
		$('#'+ $(this).attr('id') + ' img').css({ marginLeft: -150 });
	});		
});

init();


});
})(jQuery);

