    var collectionSlide = {
        speed: 1000,
        open: function(e) {
            if ( $('#collection-slide').length )
            {
                return;
            }
            
            var url              = $(e.currentTarget).attr('href');
            var $body            = $(document.body);
            var $collectionSlide = $('<div id="collection-slide"></div>');
            var $collectionSlideWrapper = $('#collection-slide-wrapper');
            
            $body.append($collectionSlide);
            $body.css({'overflow': 'hidden'});
            $('html').css({'overflow': 'hidden'});
            $collectionSlideWrapper.animate({'marginLeft': '-200%'}, this.speed);
            $collectionSlide.animate({'marginLeft': '-100%'}, this.speed, function() { $collectionSlide.load(url); });
            
            return false;
        },
        close: function() {
            var $body            = $(document.body);
            var $collectionSlide = $('#collection-slide');
            var $collectionSlideWrapper = $('#collection-slide-wrapper');
            
            $collectionSlideWrapper.animate({'marginLeft': '0'}, this.speed);
            $collectionSlide.animate({'marginLeft': '0'}, this.speed, function() {
                $(this).remove();
                $body.css({'overflow': 'auto'});
                $('html').css({'overflow': 'auto'});
            });
        }
    }
        
    $(document).ready(function() {				
        var $collectionSlideWrapper = $('<div id="collection-slide-wrapper"></div>');
        $('body').contents().wrapAll($collectionSlideWrapper);
        
		$(".blocco-loghi h2").click(function(){

		$(".loghi:not(:hidden)").slideUp();
		
		$(".blocco-loghi h2 span").attr("class", "apri");
		
		$("span", this).attr("class", "chiudi");
		
 		$("~ .loghi:hidden", this).slideToggle("slow");
		 
		 return false;

 		});
		
		$('.ui-tabs').tabs({fxFade: true, fxSpeed: 'fast'});
        
		dropdown('#menu-primo-livello ul');

		$("#agenti_uid").DefaultValue("username");
		$("#agenti_pwd").DefaultValue("password");
		
		$("#franchisee_uid").DefaultValue("username");
        $("#franchisee_pwd").DefaultValue("password");
		
      	$('a[rel=external]').click(function() {
            window.open($(this).attr('href'));
            
            return false;
        });
		
		$(".open-box").each(function(i){
		
			$(this).click(function() {
			
				if( $('.accesso').hasClass('opened') ) {
			   
				   	$('.accesso').fadeOut('slow');
			   
				} else {
				
					$('.accesso').fadeIn('slow');
					$("#bn-close-l").click();					   
				}
				return false;
				
			});
				  
		});
		
		$("#bn-close").click(function() {
		
			$('.accesso').fadeOut('slow');
			return false;
		
		});	
		
		$("#job").click(function() {
		
			window.open('http://carpisa.easycruit.com/', 'easycruit', 'width=615, height=619');
			return false;
		
		});	
		
		$(".open-box-l").each(function(i){
		
			$(this).click(function() {
			
				if( $('.accesso-l').hasClass('opened') ) {
			   
				   	$('.accesso-l').fadeOut('slow');
			   
				} else {
				
					$('.accesso-l').fadeIn('slow');
					$("#bn-close").click();
					   
				}
				return false;
				
			});
				  
		});
		
		$("#bn-close-l").click(function() {
		
			$('.accesso-l').fadeOut('slow');
			return false;
		
		});	
		
		
			
		$("#carpisa-persone > h3 > a").click(function() {
		
			$('#carpisa-persone > div.news').slideToggle('slow', function() {
    			if ($('#carpisa-persone > h3 > a').attr("class") == "apri")
					$('#carpisa-persone > h3 > a').attr("class", "chiudi");
				else	
					$('#carpisa-persone > h3 > a').attr("class", "apri");
  			});
			return false;
		
		});		
		
		$("#carpisa-project > h3 > a").click(function() {
		
			$('#carpisa-project > div.news').slideToggle('slow', function() {
    			if ($('#carpisa-project > h3 > a').attr("class") == "apri")
					$('#carpisa-project > h3 > a').attr("class", "chiudi");
				else	
					$('#carpisa-project > h3 > a').attr("class", "apri");
  			});
			return false;
		
		});		
        
        //$('.collection').pageSlide({direction: 'left', duration: 'slow', width: '100%'});
        $('.collection').click($.proxy(collectionSlide, 'open'));
		$('.banncoll').click($.proxy(collectionSlide, 'open'));
		$("#carpisa-persone > h3 > a").click();
		$("#carpisa-project > h3 > a").click();
    });
