$(document).ready(function() {


//PHOTOS

$.getJSON("https://graph.facebook.com/10150101342064521/photos&callback=?",function(json){
  $.each(json.data,function(){
  $('<li></li>')
    .append('<a href="' + this.images[0].source + '"><img src="' + this.images[0].source + '" title="' + this.name + '"/></a>')
	.appendTo('.photos ul');
  });

 $('.photos ul').jcarousel({
 	wrap: 'both',
 	scroll: 2
 });
 
  $(".photos a").fancybox({
	'speedIn'		:	100, 
	'speedOut'		:	100,
	'overlay'		: 	false
 });

});


//VIDEOS

$.getJSON("https://gdata.youtube.com/feeds/api/playlists/73FD3C035FCC9081?alt=jsonc&v=2&callback=?", function(json) {
var url = (json.data.items[0].video.thumbnail.hqDefault);
var id = (json.data.items[0].video.id);
var title = (json.data.items[0].video.title);
$('.videos').html('<h3>Videos</h3><span class="thumb" style="background: url(' + url + ');"><a href="http://www.youtube.com/watch?v=' + id + '" class="play"></a></span><p class="title">' + title + '</p>');

$('.videos a').click(function() {
	$.fancybox({
 	'padding'             : 0,
	'autoScale'   		: false,
	'transitionIn'        : 'none',
	'transitionOut'       : 'none',
	'title'               : this.title,
	'width'               : 640,
	'height'              : 385,
	'href'				: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
	'type'                : 'swf', 
	'swf'                 : {'allowfullscreen':'true'}
	});
	return false;
	}); 


});


//HEADER

  $.getJSON("https://graph.facebook.com/255116931204956/photos&callback=?",function(json){
    $.each(json.data,function(){
	$('<li></li>')
    .append('<img src="' + this.images[0].source + '" title="' + this.name + '"/>')
	.appendTo('#featured');
  });
  });

$(window).load(function() {
  $('#featured').nivoSlider({
	effect: 'fade',
	animSpeed: 800, // Slide transition speed
    pauseTime: 5000,
	width: 500,
	captionOpacity: 1
  });
});

  $.getJSON("https://graph.facebook.com/hulugivesback/&access_token=AAACEdEose0cBAF9u5Ez30rErtIDVno5HxFRxLvXZCv6xy6kq3ZCKeef2jMZAUe2o9UORiD8pQcD4BM5dny6v3nPQjZCDTSMZD&limit=1&callback=?",function(json){
   $('.mission p').html(json.mission);
  });

/*-TWITTER

$.getJSON("http://twitter.com/statuses/user_timeline/hulu.json?callback=?", function(data) {
 var tweet = (data[0].text).replace(/(https?[^ ]*)/g, '<a target="_blank" href="$1">$1</a>');
 var tweetid = (data[0].id_str);
 $('.twitter').html(tweet + ' <a class="retweet" href="javascript:void(0);"  onclick="openWindow(\'https://twitter.com/intent/retweet?tweet_id=' + tweetid + '\', \'follow\',530,340);"></a> <span class="tweetcount">' + data[0].retweet_count + '</span>');
});-*/


//NEWS

  $.getJSON("https://graph.facebook.com/hulu/notes&access_token=AAACEdEose0cBAF9u5Ez30rErtIDVno5HxFRxLvXZCv6xy6kq3ZCKeef2jMZAUe2o9UORiD8pQcD4BM5dny6v3nPQjZCDTSMZD&limit=2&callback=?",function(json){
    $.each(json.data,function(){
    var pub = (this.created_time).match('\\d+-\\d+-\\d+');
	$('<span class="entry"></span>')
    .append('<a href="https://www.facebook.com/note.php?note_id=' + this.id + '" target="_blank" class="headline">' + this.subject + '</a><br><span class="pub">' + pub + '</span><span class="excerpt">' + this.message + '</span><a class="more" href="https://www.facebook.com/note.php?note_id=' + this.id + '">read more</a>')
	.appendTo('.news');
  });
  
  var maxNum = function($limit, num) {
    var $this;
    $limit.each(function() {
        $this = $(this); 
        $this.text( $this.text().split(/\s+/).slice(0,num).join(" ") );
    });
}

$(function() {
    maxNum($('.news .excerpt'),30);
});
  
  });


//EVENTS

  $.getJSON("https://graph.facebook.com/coldplay/events&access_token=AAACEdEose0cBAF9u5Ez30rErtIDVno5HxFRxLvXZCv6xy6kq3ZCKeef2jMZAUe2o9UORiD8pQcD4BM5dny6v3nPQjZCDTSMZD&limit=3&callback=?",function(json){
    $.each(json.data,function(){
    var date = (this.start_time).match('\\d+-\\d+-\\d+');
	$('<li></li>')
    .append('<span class="date">' + date + '</span> ' + this.name + ' <span class="view"><a target="_blank" href="https://www.facebook.com/events/' + this.id +'">view event</a> <a href="">rsvp</a></span>')
	.appendTo('.events ul');
  });
  });


//E4M

$('input.clear').each(function() {
	$(this)
		.data('default', $(this).val())
		.addClass('inactive')
		.focus(function() {
			$(this).removeClass('inactive');
			if ($(this).val() == $(this).data('default') || '') {
				$(this).val('');
			}
		})
		.blur(function() {
			var default_val = $(this).data('default');
			if ($(this).val() == '') {
				$(this).addClass('inactive');
				$(this).val($(this).data('default'));
			}
		});
	});



$('#signup').submit(function() { 
        $(this).ajaxSubmit();
        $('#signup #email').val('thanks!');
		return false; 
	});



});//end
