function loadthumb(imgtarg, src,cb){
    //$(imgtarg).hide();
    imgtarg.hide();
    var img = new Image();
        $(img).load(function(){
        imgtarg.attr('src', src); // attach the image to 'imgtarg' which is still hidden
        imgtarg.fadeIn('slow'); // fade it in!
        cb();
    }).attr('src', src);
    return false;
}



(function($) {
    $.fn.Entry = function(settings) {
        var config = {};
        if (settings) $.extend(config, settings);
        
        return this.each(function() { 
            var $win = $(window),
                $body = $('body'),
                $big_img = $('#preroll>img'),
                $big_img_w = $big_img.attr('width'),
                $big_img_h = $big_img.attr('height');
                //$scroll = ($.browser.mozilla || $.browser.msie) ? $('html') : $body,
                //_scrollPoints = [200,2600],
                //_offsetTop = 175,
                //_entered = false,
                //_isIE7 = ($.browser.msie && parseFloat($.browser.version) <= 7.0);
                //$pane1 = $('<div class="intro-pane"/>').css({backgroundColor: '#000'}), // Black
                //$pane2 = $('<div class="intro-pane"/>').html('<div class="pattern"></div>'), // Stripes
                //$pane3 = $('<div class="intro-pane"/>').css({backgroundColor: '#1d1d1d'}); // Dark grey
            on_resize();
            init();

            function init(){

                // Do the resize to get the splash proportioned correctly.
                $win.bind('resize', on_resize);

            } // End init()

            function on_resize(){

                    var win_w = $win.width(),
                    win_h = $win.height();

                        var dest_w = win_w;
                        var dest_h = dest_w * ($big_img_h / $big_img_w);

                       if(dest_h < win_h) {
                            // need to scale it back up.
                            dest_h = win_h;
                            dest_w = dest_h * ($big_img_w / $big_img_h);
                        }

                        $big_img.attr('width', dest_w);
                        $big_img.attr('height', dest_h);

                        //Offset the margin.
                        if(dest_w > win_w) {
                            $big_img.css({marginLeft: Math.floor((dest_w - win_w) / -2)});
                        } else {
                            $big_img.css({marginLeft: 0});
                        }
                        if(dest_h > win_h) {
                            $big_img.css({marginTop: Math.floor((dest_h - win_h) / -2)});
                        } else {
                            $big_img.css({marginTop: 0});
                        }

            }; // End on_resize()

        });
    };
})(jQuery);


milenaTwitter = function() {
    new TWTR.Widget({
  version: 2,
  id: 'milenaTwitter',
  type: 'profile',
  rpp: 10,
  interval: 6000,
  width: 'auto',
  height: 300,
  theme: {
    shell: {
      background: '#333333',
      color: '#ffffff'
    },
    tweets: {
      background: '#000000',
      color: '#ffffff',
      links: '#4aed05'
    }
  },
  features: {
    scrollbar: false,
    loop: false,
    live: false,
    hashtags: true,
    timestamp: true,
    avatars: false,
    behavior: 'all'
  }
}).render().setUser('milfrat').start();
};

lorenzoTwitter = function() {
    new TWTR.Widget({
  version: 2,
  id: 'lorenzoTwitter',
  type: 'profile',
  rpp: 10,
  interval: 6000,
  width: 'auto',
  height: 300,
  theme: {
    shell: {
      background: '#333333',
      color: '#ffffff'
    },
    tweets: {
      background: '#000000',
      color: '#ffffff',
      links: '#4aed05'
    }
  },
  features: {
    scrollbar: false,
    loop: false,
    live: false,
    hashtags: true,
    timestamp: true,
    avatars: false,
    behavior: 'all'
  }
}).render().setUser('lorenzomassacci').start();
};

jQuery(

  function ($) {
    //var $body   = $('body');
    $('html').Entry();
    $big_img = $('#preroll>img');
    loadthumb($big_img,$big_img.attr('src'),function(){
        setTimeout(function(){
            $('#Twitter').show('drop',{direction: "left",times:3},500,lorenzoTwitter);
            $('#Twitter2').show('drop',{direction: "right",times:3},500,milenaTwitter);
        }, 2500);

  });


  $big_img.click(function(){
      $('#Twitter').hide('drop',{direction: "left",times:3},500,lorenzoTwitter);
      $('#Twitter2').hide('drop',{direction: "right",times:3},500,milenaTwitter);
  })

    //setTimeout(function(){
            //$('#Twitter').show('drop',{direction: "left"},500,lorenzoTwitter);
            //$('#Twitter2').show('drop',{direction: "right"},500,milenaTwitter);
     //   }, 5000);
    

  }

);
