Cufon.replace('.scroll_box .description b');


$(document).ready(function() {


// Animazione Icone Social Network

$('#icons_box a').mouseover(function(){
	$(this).stop().animate({marginTop : '-4px'}, 'fast');								 
});
$('#icons_box a').mouseout(function(){
	$(this).stop().animate({marginTop : '0px'}, 'fast');								 
});

$('.scrolling-right').mouseover(function(){
	$('.arrow_right').stop().animate({backgroundPosition : '0px -35px'}, 'fast');								 
});
$('.scrolling-right').mouseout(function(){
	$('.arrow_right').stop().animate({backgroundPosition : '0px 0px'}, 'fast');							 
});

$('.scrolling-left').mouseover(function(){
	$('.arrow_left').stop().animate({backgroundPosition : '0px -35px'}, 'fast');								 
});
$('.scrolling-left').mouseout(function(){
	$('.arrow_left').stop().animate({backgroundPosition : '0px 0px'}, 'fast');							 
});

$('.element_clienti a').mouseover(function(){
	$(this).stop().animate({opacity : 0.5}, 'fast');								 
});
$('.element_clienti a').mouseout(function(){
	$(this).stop().animate({opacity : 1}, 'fast');							 
});




// ALESSIO ACCORDION SCROLLER

var HalfScreen = $(window).width()/2;
var OffsetScroll = HalfScreen - 380;
var LastItem = $('#items').children('.element_mobile').length * 380;
var LastItemClient = $('#items').children('.element_clienti').length * 200;


var UpdateInterval = 1;
var PixelPerInterval = 5;
var scorllerInterval;

function scroll_left() { if($('#scroller').children('#items').position().left <= 0) { document.getElementById('scroller').scrollLeft -= PixelPerInterval; } };
function scroll_right() { if($('#scroller').children('#items').position().left > (-LastItem + $(window).width() - 380)) { document.getElementById('scroller').scrollLeft += PixelPerInterval; } };
function scroll_right_client() { if($('#scroller').children('#items').position().left > (-LastItemClient + $(window).width())) { document.getElementById('scroller').scrollLeft += PixelPerInterval; } };
	
function start_scroll_left() { scorllerInterval = setInterval(scroll_left, UpdateInterval); }
function start_scroll_right() { scorllerInterval = setInterval(scroll_right, UpdateInterval); }
function start_scroll_right_client() { scorllerInterval = setInterval(scroll_right_client, UpdateInterval); }

function stop_scrolling() { clearInterval(scorllerInterval); }

$('a.next, .arrow_right').stop().mouseover(function() {  start_scroll_right() }).mouseout(function() { stop_scrolling() });
$('a.prev, .arrow_left, a.prev_cl').stop().mouseover(function() { start_scroll_left() }).mouseout(function() { stop_scrolling() });
$('a.next_cl').stop().mouseover(function() {  start_scroll_right_client() }).mouseout(function() { stop_scrolling() });


// Click Function Accordion

$('.scroll_box').click(function() {
								
		var PHtarget;
	
		if($(this).hasClass('opened') == false) {

			$(this).addClass('CheckedBox');

			$('.opened').animate({width : '380px'}, 600, 'easeInOutQuart', function() {
				PHtarget = ($('.CheckedBox').position().left);
			});
			
			$('.opened').removeClass('opened');
			$('.CheckedBox').addClass('opened');
			$('body .control_inside').css({display: 'none'});
			$('body .description, body .ph5_description').css({display: 'none'});
						
			$('.opened').animate({width : '750px'}, 600, 'easeInOutQuart', function() {
				$("#scroller").animate({scrollLeft: PHtarget-OffsetScroll}, {duration: 600, specialEasing: {width: 'easeInOutQuart'}});
				$('.opened .description, body .ph5_description').fadeIn('medium', function() {
				$('.opened .control_inside').fadeIn('medium');
				$('.CheckedBox').removeClass('CheckedBox');
			})
		});
			
// Caption Immagini Numero
			
function onAfter(curr,next,opts) {
			var msg = (opts.currSlide + 1) + ' / ' + opts.slideCount;
			$('.opened .control_inside .caption').html(msg);
			return false;
};

// END ALESSIO ACCORDION SCROLLABLE
	
				$('.opened').children('.content').children('.img_gallery').cycle({
					fx:     'scrollHorz',
					speed:  'slow',
					timeout: 0,
					prev:   $('.opened .prev_inside', this.parentNode),
					next:   $('.opened .next_inside', this.parentNode),
					after: onAfter,
					nowrap:  1
		});

$('.opened').children('.control_inside').children('.magnify_inside').cycle({
					timeout: 0,
					prev:   '.prev_inside',
					next:   '.next_inside',
					nowrap:  1
				});
};


	
		
	// FancyBox - Images
	
$('.opened').children('.control_inside').children('.magnify_inside').children('a').fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'speedIn'		:	400, 
		'speedOut'		:	300, 
		'overlayShow'	:	true,
		'padding' : 0,
		'overlayOpacity':	0.9,
		'overlayColor' : '#000',
		'hideOnContentClick' : false
	});

	});


});
