$(document).ready(function() {
	/* Main menu */
	$('#menu_main > ul > li > a.subMenu').click(function() {
		/*var $parentItem = $(this).parent(), slideAmt = $(this).next().width()+5, direction;
		if (parseInt($parentItem.css('marginLeft'), 10) < 0)
		{
			direction = '+=';
			$(this).removeClass('expanded');
		} else {
			$(this).addClass('expanded');
			direction = '-=';
		}
		
		$parentItem.animate({marginLeft: direction + slideAmt}, 400);*/
		
		id_pag=$(this).attr('ref');
		if( $('#'+id_pag).hasClass('closed') ){
			$('#'+id_pag).animate({marginLeft: '+=' + ($('#'+id_pag).width()+5)}, 400);
			$('#'+id_pag).removeClass('closed');
		}
		else{
			$('#'+id_pag).animate({marginLeft: '-=' + ($('#'+id_pag).width()+5)}, 400);
			$('#'+id_pag).addClass('closed');
		}
		
		//$parentItem.animate({marginLeft: direction + slideAmt}, 400).siblings().animate({marginLeft: '0'}, 150);
		return false;
	});
	/* Close all menu voice if not needed*/
	if ($('#project_cat_list').hasClass('closed'))
	{
		$('#project_cat_list').parent().animate({marginLeft: '-=' + ($('#project_cat_list').width()+5)}, 400);
	}

	if ($('#studio_list').hasClass('closed'))
	{
		$('#studio_list').parent().animate({marginLeft: '-=' + ($('#studio_list').width()+5)}, 400);
	}
	
	/* Home slideshow */
	$('#picture_slider').cycle({
		fx: 		'fade',
		speed: 		2500, 
		timeout: 	5000,
		autostop:      0
	});
	
	/* Home news */
	$(".toggleContainer").hide();
	$(".toggleOpen").show();
	$(".trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
	});
	
	/* Scroll to TOP */
	$(function() {
    	$(".returnTop").click(function() {
      		$.scrollTo("body", {duration: 800, axis:"y"});
    	});
  	});
	
	/* Breadcrumbs */
	$('#breadcrumbs').xBreadcrumbs();
	
	/* Fade effect */
	$(".fade").fadeTo("fast", 0.5);
	$(".fade").hover(function(){
    	$(this).fadeTo("fast", 1.0);
  	},function(){
    	$(this).fadeTo("fast", 0.5);
  	});
	
	/* Lazy load image in project dir */
	$("img.project").lazyload({
		effect      : "fadeIn"
	});
	$("img.showfade").lazyload({
		effect      : "fadeIn"
	});
	
	/* Foto gallery */
	$(function() {
    	$('a[rel^=colorbox]').colorbox({transition:"fade", current:"foto {current} di {total}", previous:"prec", next:"succ", close:"chiudi"});
	});
	
});

Cufon.replace('h2', { fontFamily: 'AvantGarde Bk Bt' });
Cufon.replace('h4', { fontFamily: 'AvantGarde Bk Bt' });
Cufon.replace('h5', { fontFamily: 'AvantGarde Bk Bt' });
