/******************************************************SCROLLING*********************************************************/
//Scroll dell'Home in entrata'
$(document).ready(function(){
        $('#homepage').animate({left: '0px', opacity: '1'}, 800);
})


//Scroll dell'Home e del Portfolio
$(document).ready(function(){
        $('#link_portfolio').click(function(){
            $('#link_homepage').removeClass('active');
            $('#link_portfolio').addClass('active');
            $('#page_body').animate({left: '-100%'}, 1000);
            $('#portfolio').css("display", "block");
            $("#footer").append("<div class='top'><a href='#'>Top &uarr;</a></div>");
            if (!$.browser.msie)
            {
                $('#homepage').animate({opacity: '0'}, 1000);
                $('#portfolio').animate({opacity: '1'}, 1000);
            }
            return false;
        });
})
        
$(document).ready(function(){
        $('#link_homepage').click(function(){
            $('#link_portfolio').removeClass('active');
            $('#link_homepage').addClass('active');
            $('#page_body').animate({left: '0%'}, 1000, function(){
                $('#portfolio').css("display", "none");
                $('.top').detach();
            });               
            if (!$.browser.msie)
            {
                $('#portfolio').animate({opacity: '0'}, 1000);
                $('#homepage').animate({opacity: '1'}, 1000);
            }
            return false;
        });
});


//Scroll degli articoli del Portofolio
$(function(){
    $('.top-article a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({scrollTop: targetOffset}, 1000);
                return false;
            }
        }
    });
});


/*****************************************************MOUSEDOWN*********************************************************/

// Funzione per bloccare la descrizione testuale degli articoli allo scorrimento della pagina
(function(){
if ($.browser.msie) {
    $(window).unbind('scroll.portfolio').unbind('resize.portfolio');
        $('#portfolio .description').css({
            'position':'relative'
        });
}
else {
    $(window).bind('scroll.portfolio resize.portfolio',function(){
        $('#portfolio #article').each(function(n){
            var wTop=$(window).scrollTop();
            var $collection=$(this);
            var $tool=$collection.find('.description');
            var xTop=$collection.offset().top;
            var xBottom=xTop+$collection.height()-150;
            if(xTop<=wTop&&xBottom>=wTop){
                $tool.addClass('range');
                var top=0;
                var bottomBreakPoint=xBottom-$tool.height();
                if(bottomBreakPoint<=wTop){
                    top=bottomBreakPoint-wTop;
                    $tool.addClass('breakpoint');
                }else{
                    $tool.removeClass('breakpoint');
                }
                $tool.css({
                    'position':'fixed',
                    'top':top,
                    'left':$(this).offset().left+$(this).width()-$tool.width()
                    });
                $collection.trigger('focus');
            }else{
                $tool.removeClass('range breakpoint');
                $tool.css({
                    'position':'relative',
                    'top':0,
                    'left':'auto',
                    'right':0
                });
                $collection.trigger('blur');
            }
        });
    });
}
    /*else {}
    if($.browser.msie){
        $(window).unbind('scroll.portfolio').unbind('resize.portfolio');
        $('#portfolio .description').css({
            'position':'relative',
            'top': top,
            'right':0
        }).removeClass('range breakpoint');
    }*/
})();

/*****************************************************COPYRIGHT*********************************************************/

//Copyraght di Craq all'hover del mouse
$(document).ready(function(){
        $('.link_copyright').mouseover(function(){
            $('.cartoon').css('display', 'inline-block');
        });
        $('.link_copyright').mouseout(function(){
            $('.cartoon').css('display', 'none');
        });
});

/***************************************************TWITTER STYLE*******************************************************/

//Formattazione stile di twitter
$(window).bind('load', function(){
    $('.twtr-bd').css({'display':'block', 'font-size':'13px', 'font-family':'Helvetica'});
    $('.twtr-tweet-wrap').css('padding' , '0');
});


