jQuery(document).ready(function() {
	$('#slideshow IMG:first').addClass('active');
	$('#slideshow IMG:first').css({
		opacity: 1.0
	});
	$('#slideshow_port .img_portfolio:first').addClass('active');
	$('#slideshow_port .img_portfolio:first').css({
		opacity: 1.0
	});

});

function initBtnGallery() {
	if (imgGallTot <= 1) {
		$('.right').hide();
		$('.left').hide();
	} else if (step == 1) {
		$('.right').show();
		$('.left').hide();
	}
	$('.right').click(slideSwitchNext);
	$('.left').click(slideSwitchPrev);
	$('.numerazione').html(step+'/'+imgGallTot);

}
function openContact() {
	$('#contact').show();
	$('.contact').addClass('selected');
	$('#agent').hide();
	$('.agent').removeClass('selected');
	return false;
}
function openAgent() {
	$('#contact').hide();
	$('.contact').removeClass('selected');
	$('#agent').show();
	$('.agent').addClass('selected');
	return false;
}
function resetMenu() {
	$('.contact').removeClass('selected');
	$('#contact').hide();
	$('.agent').removeClass('selected');
	$('#agent').hide();	
}
function slideSwitchNext() {
	step++;
	$('.numerazione').html(step+'/'+imgGallTot);

	if (step == 1) {
		$('.right').show();
		$('.left').hide();
	} else if (step >= 1) {
		$('.right').show();
		$('.left').show();
	}
	if (step == imgGallTot) {
		$('.right').hide();
		$('.left').show();
	}
	$('#slideshow IMG').css({
		opacity: 0.0
	});
	var $active = $('#slideshow IMG.active');
	if ($active.length == 0) $active = $('#slideshow IMG:last');
	var $next = $active.next().length ? $active.next() : $('#slideshow IMG:first');
	$active.addClass('last-active');
	$next.css({
		opacity: 0.0
	}).addClass('active').animate({
		opacity: 1.0
	}, 1000, function() {
		$active.removeClass('active last-active');
	});
	return false;
}
function slideSwitchPrev() {
	step--;
	$('.numerazione').html(step+'/'+imgGallTot);

	if (step == 1) {
		$('.right').show();
		$('.left').hide();
	} else if (step >= 1) {
		$('.right').show();
		$('.left').show();
	}
	if (step == imgGallTot) {
		$('.right').hide();
		$('.left').show();
	}
	$('#slideshow IMG').css({
		opacity: 0.0
	});
	var $active = $('#slideshow IMG.active');
	if ($active.length == 0) $active = $('#slideshow IMG:last');
	var $next = $active.prev().length ? $active.prev() : $('#slideshow IMG:first');
	$active.addClass('last-active');
	$next.css({
		opacity: 0.0
	}).addClass('active').animate({
		opacity: 1.0
	}, 1000, function() {
		$active.removeClass('active last-active');
	});
	return false;
}

function initBtnGalleryPortfolio() {
	if (imgGallTot <= 1) {
		$('.right').hide();
		$('.left').hide();
	} else if (step == 1) {
		$('.right').show();
		$('.left').hide();
	}
	$('.right').click(slideSwitchNextPort);
	$('.left').click(slideSwitchPrevPort);
	$('.numerazione').html(step+'/'+imgGallTot);

}

function slideSwitchNextPort() {
	step++;
	$('.numerazione').html(step+'/'+imgGallTot);

	if (step == 1) {
		$('.right').show();
		$('.left').hide();
	} else if (step >= 1) {
		$('.right').show();
		$('.left').show();
	}
	if (step == imgGallTot) {
		$('.right').hide();
		$('.left').show();
	}
	$('#slideshow_port .img_portfolio').css({
		opacity: 0.0
	});
	var $active = $('#slideshow_port .img_portfolio.active');
	if ($active.length == 0) $active = $('#slideshow_port .img_portfolio:last');
	var $next = $active.next().length ? $active.next() : $('#slideshow_port .img_portfolio:first');
	$active.addClass('last-active');
	$next.css({
		opacity: 0.0
	}).addClass('active').animate({
		opacity: 1.0
	}, 1000, function() {
		$active.removeClass('active last-active');
	});
	return false;
}
function slideSwitchPrevPort() {
	step--;
	$('.numerazione').html(step+'/'+imgGallTot);

	if (step == 1) {
		$('.right').show();
		$('.left').hide();
	} else if (step >= 1) {
		$('.right').show();
		$('.left').show();
	}
	if (step == imgGallTot) {
		$('.right').hide();
		$('.left').show();
	}
	$('#slideshow_port .img_portfolio').css({
		opacity: 0.0
	});
	var $active = $('#slideshow_port .img_portfolio.active');
	if ($active.length == 0) $active = $('#slideshow_port .img_portfolio:last');
	var $next = $active.prev().length ? $active.prev() : $('#slideshow_port .img_portfolio:first');
	$active.addClass('last-active');
	$next.css({
		opacity: 0.0
	}).addClass('active').animate({
		opacity: 1.0
	}, 1000, function() {
		$active.removeClass('active last-active');
	});
	return false;
}

