/* =============
three hover boxes
 ============= */
$(function() {
			$('ul.hover_block li').hover(function(){
				$(this).find('.slider-reveal').animate({top:'0px'},{queue:false,duration:500});
			}, function(){
				$(this).find('.slider-reveal').animate({top:'97px'},{queue:false,duration:500});
			});
		});



/* =============
start onload
============= */

$("document").ready (function () {

/* =============
home slideshow
 ============= */

$('#bluesky-home-sld').cycle({ 
fx:     'fade', 
next: "#slide-nxt",
prev: "#slide-prv",
speed:  700,
timeout:  12000 
});


/* =============
service options
 ============= */

$("#full ul#blockgrid li:nth-child(3n)").removeClass("option").addClass("option-end");
$("#left ul#blockgrid li:nth-child(2n)").removeClass("option").addClass("option-end");

/* =============
team page grid
 ============= */

$("ul#teamgrid li:nth-child(5n)").removeClass("option").addClass("option-end");

/* =============
portfolio thumb fade
 ============= */
$("#left ul#blockgrid li").hover(function(){$(this).find("a").stop().animate({opacity:"0.1"},"fast")},function(){$(this).find("a").stop().animate({opacity:"1"},"fast")});



/* =============
select random testimonail
 ============= */

var numoftest = $('.testi-block').length;
var randomnumber = Math.floor(Math.random()*numoftest);
$('.testi-block').hide();
$('.testi-block').eq(randomnumber).show();

 
/* =============
jsonp twitter call 
 ============= */

$.ajax({ url: "http://twitter.com/statuses/user_timeline/BlueskyTeam.json?count=20&amp;include_rts=1",
 dataType: "jsonp", type: "GET", cache: false, contentType: 'application/json; charset=utf-8',
 error: function (data) {
       //alert(data.status + ' ' + data.statusText);
 },
 complete: function (data) {
        //alert(data.status + ' ' + data.statusText + ' ' + data );
 },
 beforeSend: function () {
      // $('#msg').text('Loading Tweets...');
 },
  success: function (data) {
        var list = '';
        var lid = 0;
		
        if (data != null) {
        $.each(data, function () {
		var username = this.user.screen_name;	
		//alert(username);
		var status = this.text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function (url) {
        return '<a href="' + url + '" target="_blank">' + url + '</a>'; 
        }).replace(/\B@([_a-z0-9]+)/ig, function (reply) {
         return reply.charAt(0) + '<a target="_blank" href="http://twitter.com/' + reply.substring(1) + '">' + reply.substring(1) + '</a>';
        });

		function relative_time(time_value) {
        var values = time_value.split(" ");
        time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
        var parsed_date = Date.parse(time_value);
        var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
        var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
        delta = delta + (relative_to.getTimezoneOffset() * 60);
        if (delta < 60) {
            return 'less than a minute ago';
        } else if (delta < 120) {
            return 'about a minute ago';
        } else if (delta < (60 * 60)) {
            return (parseInt(delta / 60)).toString() + ' minutes ago';
        } else if (delta < (120 * 60)) {
            return 'about an hour ago';
        } else if (delta < (24 * 60 * 60)) {
            return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
        } else if (delta < (48 * 60 * 60)) {
            return '1 day ago';
        } else {
            return (parseInt(delta / 86400)).toString() + ' days ago';
        }
        }
		list += '<li><span>' + status + ' <a href="http://twitter.com/' + username + '/statuses/' + this.id_str + '" style="font-size:85%" target="_blank">' + relative_time(this.created_at) + '</a> </span></li> ';							
		});
		}
   		$('#twitter_update_list').prepend(list);
		/* rotate them*/
		rotateTweets();
		
		//end if 
  		}
	//end success function
  }
 
);
 

$('#meet-team').css({ opacity:0, visibility:'visible'}); 
//end of document ready 	
});




function rotateTweets() {

$('ul#twitter_update_list').cycle({ 
		fx:     'fade', 
		next: "#tweet-nxt",
		prev: "#tweet-prv",
		speed:  700,
		timeout:  12000 
		});

}





/* =============
team page grid filters
 ============= */
 
  
$(function(){

      var 
        speed = 1000,   // animation speed
        $wall = $('#meet-team-grid').find('#meet-team ul'),

        masonryOptions = {         // initial masonry options
          columnWidth: 192, 
		  itemSelector: '.box:not(.invis)',
          animate: true,
          animationOptions: {
            duration: speed,
            queue: false
          }
        }
      ;

      // run on window.load so we can capture any incoming hashes
      $(window).load(function(){
				$('.meet-team-loading').hide();			  
		  $('#meet-team').css({ opacity:0, visibility:'visible'}).fadeTo("slow", 1); 
        // run masonry on start-up to capture all the boxes we'll need
        $wall.masonry(masonryOptions);
		
		$('#meet-team-filter a.everyone').parent().addClass("selected");
		
        if ( window.location.hash ) {
          // get rid of the '#' from the hash
          var possibleFilterClass = window.location.hash.replace('#', '');		  
		  $('#meet-team-filter li').removeClass("selected");
		  $('#meet-team-filter a.' + possibleFilterClass + '').parent().addClass("selected");
		  
          switch (possibleFilterClass) {
          // if the hash matches the following words
		  
          case 'everyone' : case 'designers' : case 'developers' : case 'e-marketing' : case 'account-managers' : case 'directors' : case 'accounts-admin' :
            // set masonry options animate to false
            masonryOptions.animate = false;
            // hide boxes that don't match the filter class
            $wall.children().not('.'+possibleFilterClass)
              .toggleClass('invis').hide();
            // run masonry again, this time with the necessary stuff hidden
            $wall.masonry(masonryOptions);
            break;
          }
        }

      });

      $('#meet-team-filter ul li a').click(function(){
		    $(this).parent().parent().removeClass("active");
			
			
			$('#meet-team-filter ul li').removeClass("selected");
			
			 $(this).parent().addClass("selected");
			
        var 
          color = $(this).attr('class'),
          filterClass = '.' + color;
        ;

        if(filterClass=='.all') {
          // show all hidden boxes
          $wall.children('.invis')
            .toggleClass('invis').fadeIn(speed);
        } else {
          // hide visible boxes 
          $wall.children().not(filterClass).not('.invis')
            .toggleClass('invis').fadeOut(speed);
          // show hidden boxes
          $wall.children(filterClass+'.invis')
            .toggleClass('invis').fadeIn(speed);

        }
        $wall.masonry({ animate: true });
        // set hash in URL
 $('#meet-team-filter ul li').removeClass("active");
  $(this).parent().parent().addClass("active");

        window.location.hash = color;
        return false;
      });
    });
