/**
 * @author GLEONE
 */

$(window).load(
    function(){
        $('#nivoSlider').nivoSlider({
            effect: 'random',
            //Specify sets like: 'fold,fade,sliceDown'
            slices: 15,
            animSpeed: 500,
            pauseTime: 4000,
            startSlide: 0,
            //Set starting Slide (0 index)
            directionNav: false,
            //Next & Prev
            directionNavHide: false,
            //Only show on hover
            controlNav: false,
            //1,2,3...
            controlNavThumbs: false,
            //Use thumbnails for Control Nav
            controlNavThumbsFromRel: false,
            //Use image rel for thumbs
            keyboardNav: false,
            //Use left & right arrows
            pauseOnHover: false,
            //Stop animation while hovering
            manualAdvance: false,
            //Force manual transitions
            captionOpacity: 0.6,
            //Universal caption opacity
            captionHover: false,
            beforeChange: function() {},
            afterChange: function() {},
            slideshowEnd: function() {} //Triggers after all slides have been shown           
        });
    }
);// end of window.load

$(document).ready(
  function() {
      
      $('#services ul li').addClass('noreplace');
      
      // FONT
      // ----
      Cufon.replace('a', { hover:true });
      Cufon.replace('li:not(.noreplace), footer, header, a, p');
      // TOOLTIPS
      // --------
     // $('.tipsy').tipsy({fade:true, gravity:'w'});
      
      $('#flash').flash({
            src: 'media/games.swf',
            width: 220,
            height: 50
        });
      
      $('a').each(
          function(){
              if(location.pathname.indexOf($(this).attr('href')) != -1)
              {
                  $(this)
                  //disable reloading current page
                  .click(function(e){e.preventDefault();})  
                  // evidenzia il link della pagina attiva                                
                  .toggleClass('red');
              }  
          }
      );      
      
      // disable dead links (to pages not created)
      $('a.deadLink').each(
          function(){
               $(this).attr({'href':'#'});
          }
      );
      
      
      // 3 - citazioni
      /*$.getJSON('data/citazioni.json',  function (data){
          //$('#citazioni').text("minchia");
          //Cufon.refresh();
      });*/
     
     // 4 - color <a> of !href protocols
     $('article a').each(
         function(){
             var href = $(this).attr('href');
             var protocol = href.split(':')[0];
             if(protocol != 'http')
                $(this).addClass('specialProtocol');
             if(protocol == 'https')
                $(this).addClass('securedProtocol').attr('target', '_blank');
             
             Cufon.refresh();
         }
     );
     
     // twitter starting ...
     $('.tweet').tweet({
            username: "seaofclouds",//"gpleone"/*["gpleone", "robpenner", "mesh"]*/,
            /*list: "developerlist",*/
            join_text: "auto",
            avatar_size: 32,
            count: 3,
            loading_text: "loading tweets...",
            refresh_interval: 30,
            filter: function(t){ return ! /^@\w+/.test(t["tweet_raw_text"]); },
            query:generateRandomQuery()
        }).bind('loaded', function(){
            $(this)
            .find('a').attr({target:'_blank'/*, title:'view tweet on twitter'*/})
            /*.addClass('tipsy')*/;
            //$('.tipsy').tipsy({fade:true, gravity:'n'});
        });
     
  }  
);// end of document.ready

function generateRandomQuery(){
    var words = ['#actionscript', '#jquery', '#adobe', '#html5'];
    return words[Math.floor(Math.random() * words.length)];
}



