$(document).ready(function(){  
	$('#footer a:not(.info), .accetto a').colorbox({width:"600px", height:"500px", iframe:true });
	$('.info').colorbox({width:"500px", height:"350px", iframe:true });	
	$('.headerGallery a').colorbox();
	$("a.blank").click( function() { $(this).attr("target", "_blank") });
	
	$("#menu>ul>li").hover( function() {
		$(this).addClass("open");
	}, function() {		
		$(this).removeClass("open");
	});
	
	$("#menu>ul>li>ul>li:last-child").addClass("noborder");
	
	$("#header .invia").click( function() {
		$(this).closest("div").find("button[type=submit]").click();
		return false;								 
	});
	
	setInterval( "slideSwitch('#slideshow')", 5000 );
	
	
	$(".openLink").click( function() {
		$(this).toggleClass("open");
		$(this).closest("div").find(".scroll").toggle();
		return false;
	});
	
	if ( $('.slideBox li').length != 0 ) {
		setInterval( "slideSwitch('.slideBox')", 3000 );
	}
	
	
	if ( $('#news').length != 0 ) {
		$("#top").addClass("home");
		if($('#news li').length > 1) { 
			$('#news li:eq(0)').addClass("active");	
			setInterval( "slideSwitch2('#news')", 5000 ); }
		else { $('#news li').addClass("active") }
		$("#breadcrumbs").hide();
		$("#content").addClass("home");
	} else {
		$("#container").addClass("interna")
		if( $('#title img').length == 0 ) {
			$("#top").hide();
		}
	}
	
	if ( $('#colDx').length != 0 & $('.headerGallery').length != 0 ) {
		$("#content").addClass("sidebarBoth")
	} else if ( $('#colDx').length != 0 & $('.headerGallery').length == 0 ) {
		$("#content").addClass("sidebarDx");
	} else if ( $('#colDx').length == 0 & $('.headerGallery').length != 0 ) {
		$("#content").addClass("sidebarSx");
	} else if ( $('#colDx').length == 0 & $('.headerGallery').length == 0 ) {
		$("#content").addClass("noSidebar");
	}
	if ( $('.headerGallery').length == 0 ) {
		$(".accordion_content").hide();
	}
	
	
});

function slideSwitch(x) {
    var $active = $(x+' li.active');

    if ( $active.length == 0 ) $active = $(x+' li:last');

    var $next =  $active.next().length ? $active.next()
        : $(x+' li:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
function slideSwitch2(x) {
    var $active = $(x+' li.active');

    if ( $active.length == 0 ) $active = $(x+' li:eq(0)');

    var $next =  $active.next().length ? $active.next()
        : $(x+' li:first');

    $active.removeClass('active').addClass('last-active');

    $next.addClass('active')
}

