$(document).ready(function() {
	//Children of .equalh block are going to be the same height
	$(".equalh").each(function(index) {
		var tallest = 0;
	        $(this).children('div').each(
	                function(index) {
	                        var height = $(this).height();
	                        if (height > tallest) { 
	                                tallest = height; 
	                        }
	                });
			//$(this).children('div').height(tallest + 50);
	 });
	
	
		//Email News Letter
	
  						 
	
	$('#cduwr-cduwr').click(function() {
    $('.lower_sections').slideToggle('slow');
    });
	
	$('#submit_btn').click(function() {
    $('.lower_sections').slideToggle('slow');
    });
	
	
	

    
	
	
	
	//Clideshow on the home page
	$("#slides").cycle({
		fx: 'wipe',
		speed:  500, 
		timeout: 10000,
		pager:  '#pager',
		clip:   'l2r',
		after:   onAfter
		
	});
	
	//Description for each slide
	function onAfter() { 
	    $('#home-slider .clearfix .work-title').html($(this).find('.description').html());
	}
	
	//Little animations to hide font replacement glitch
	$("#main-nav").fadeIn(300);
	$("h1").fadeIn(300);
	$("#tabs ul li").fadeIn(300);
	
	//Forcing every 3rd item to have .last class
	$("#case-studies a:nth-child(3n)").addClass("last");
	
	//Filtering portfolio
	$("#portfolio-filter li a").click(function(e){
		e.preventDefault();
		var filter = $(this).text();
		filter = filter.toLowerCase();
		filter = filter.replace(/(\s)/g, "-");
		filterPortfolio(filter);
		$("#portfolio-filter li a").removeClass("strong");
		$(this).addClass("strong");
	});
	
	function filterPortfolio (filter) {
		$(".portfolio-item").hide();
		$("."+filter).show();
	}
	
	//Accordionizing job positions
	$('.positions').accordion({autoHeight: false, collapsible: true, navigation: true, active: false});
	
	//Setting hash and scrolling to the top
	$('.positions h2').click(function(){
		window.location.hash = $(this).index() / 2 + 1;
		scrollToClass('positions');
	});
	
	//If there's hash, do something useful
	var hash = window.location.hash;
	
	//Scrolling to content block if accessing from footer menu
	if (hash && window.location.pathname == "/work/") {
		hash = hash.substr (1, hash.length);
		scrollToClass(hash);
	}
	
	if (hash && window.location.pathname == "/company/culture/") {
		hash = hash.substr (1, hash.length);
		scrollToClass(hash);
	}
	
	//Opening the position from url
	if (hash && (window.location.pathname == "/contact/careers/" || window.location.pathname == "/contact/internship/")) {
		hash = hash.substr (1, hash.length);
		$('.positions').accordion("activate", hash-1);
	}
	
	function scrollToClass (className) {
		var scrollTo = $('.'+className).offset().top - 20;
		$('html, body').animate({scrollTop:scrollTo}, "slow"); 
	}
	if ($('#office-photos').length) {
		$('#office-photos a').fancybox();
	}
	if ($('#strategy').length) {
		$('#strategy a').fancybox();
	}
	//Social block integration
	if ($('#social-feed').length) {
		$("#social-feed").soSoSocial();
	}
	
	if ($('#social-feed-home').length) {
		$("#social-feed-home").soSoSocial("main");
	}
	
	
	if ($('#social-feed-home1').length) {
		$("#social-feed-home1").soSoSocial1("main");
	}
	
	
	if ($('#proccess').length) {
		var planeX = [];
		
		$(".planes div").each(function(){
			planeX.push($(this).position().left);
			$(this).css("opacity", "0");
		});
		
		$("#proccess .buttons a").click(function(e){
			e.preventDefault();
		});
		var curProcess = -1;
		$("#proccess .buttons a").hover(function(){
			
			var itemIndex = $(this).index();
			
			$('#proccess .copy-blocks div:eq('+itemIndex+')').stop().fadeTo(300, 1);
			
			$("#proccess .buttons a").each(function(){
				if ($(this).index() == itemIndex) {
					if (curProcess != itemIndex) {
						if ($(this).attr("id") != "reapply") {
							$(this).find("div").stop().animate({width: '100%'}, 500);
							$('#proccess .planes div:eq('+itemIndex+')').stop().css("left", (planeX[itemIndex]-10)+"px").delay(200).animate({left: planeX[itemIndex]+"px", opacity: "1"}, 300);

						} else {
							
							$(this).find("div").stop().animate({height: '60px'}, 500);
							$('#proccess .planes div:eq('+itemIndex+')').stop().css("left", (planeX[itemIndex]+10)+"px").delay(200).animate({left: planeX[itemIndex]+"px", opacity: "1"}, 300);
						}
						curProcess = itemIndex;
					} 
				} else {
					var curItemIndex = $(this).index();
					$('#proccess .copy-blocks div:eq('+curItemIndex+')').stop().fadeTo(300, 0);

					if ($(this).attr("id") != "reapply") {
						$(this).find("div").stop().animate({width: '0'}, 500);

						$('#proccess .planes div:eq('+curItemIndex+')').stop().animate({left: (planeX[curItemIndex]+20)+"px", opacity: "0"}, 300);
					} else {
						$(this).find("div").stop().animate({height: '0px'}, 500);
						$('#proccess .planes div:eq('+curItemIndex+')').stop().animate({left: (planeX[curItemIndex]-20)+"px", opacity: "0"}, 300);

					}
				}
			});
			
			
		}, function(){}); 
	}
	
	$("#proccess .buttons a:first").hover();
	
	if ($('#timeline').length) {
		$('#timeline a.button').hover(function(){}, function(){
			
		});
		$('#timeline a.button').click(function(e){
			e.preventDefault();
		});
		
		var i = 0;
		var year = 2002;
		var curIndex = 0;
		var eventArr = [];
		var lastDate = $('a.button:last-child .data-date').text();
		var totalEvents = $('a.button').length;
		var dateArr = lastDate.split("-");
		var maxYear = parseInt(dateArr[0] - 2);
		var maxMonth = parseInt(dateArr[1]);
		var totalMonths = maxYear * 12 + maxMonth + 10;
		var gap = 926 / totalMonths;
		$('#timeline').mousemove(function(e) {
			offset = $(this).offset();
			mouseX = e.pageX - offset.left - gap/2 - 13; //Minus margin
			var closestDist = 1000;
			var closestIndex = 0;
			for (index in eventArr) {
				if (Math.abs(mouseX - eventArr[index]) < closestDist) {
					closestDist = Math.abs(mouseX - eventArr[index]);
					closestIndex = index;
				}
			}
			
			
			if (curIndex != closestIndex) {
				curIndex = closestIndex;
				var eventToShow = $('a.button:eq('+curIndex+')');
				showEvent(eventToShow);
			}
			//console.log(e.pageX - offset.left);	
		});
		for (i = 0; i < totalMonths; i++) {
			var newtag = $('<div class="monthtag"></div>');
			if (i%12 == 0) {
				newtag = $('<div class="yeartag">'+(year++)+'</div>');
			}
			newtag.css({left: Math.round(i*gap)+"px"})
			//newtag.offset({left: Math.round(i*gap)});
			$("#tags").append(newtag);
		}
		$('a.button').each(function(){
			var eventDate = $(this).find('.data-date').text();
			dateArr = eventDate.split("-");
			var eventPos = Math.round(((parseInt(dateArr[0])-2) * 12 + (parseInt(dateArr[1])) - 1) * gap);
			
			var newevent = $('<div class="eventtag" style="height: '+(80 + Math.floor((Math.random()*24)))+'px"></div>');
			
			newevent.css({left: eventPos+"px"})
			
			eventArr.push(eventPos);
			
			$("#tags").append(newevent);
		});
		
		//console.log(eventArr);
	
		//console.log(gap);
	}
	
	
	function showEvent(evtTag){
	//console.log($(this).find(".data-coord").text()-40);
	var bubblePos = evtTag.find(".data-coord").text()-30;
	bubblePos = eventArr[curIndex] - 22;
	var newTitle = evtTag.find(".data-title").html();
	var newText = evtTag.find(".data-text").html();
	var newImage = "no";
	if (evtTag.find(".data-image").length) {
		newImage = evtTag.find(".data-image").html();
	}
	
	var type = "left";
	if (bubblePos > 540) {
		type = "right";
		bubblePos = bubblePos - 350;
	}
	$("#bubble").stop();
	$("#bubble-wrap").stop();
	$("#bubble").animate( { opacity:0}, 100, function () {
		//swapping info
		//console.log(type);
		if (type == "right") {
			$("#bubble").addClass("rt");
			bubblePos = bubblePos - 250;
		} else {
			$("#bubble").removeClass("rt");
		}
		$("#bubble").show();
		$("#bubble-text h2").html(newTitle);
		$("#bubble-text p").html(newText);
		if (newImage!="no") {
			$("#bubble-image").html(newImage);
			$("#bubble-image").show();
		} else {
			$("#bubble-image").hide();
		}
		
		$("#bubble").animate( { opacity:1}, 100);
	} );
	$("#bubble-wrap").animate( { left:bubblePos+"px"}, 500 );
	
	}
	
	
	
	//G-Finance Test
	
	if ($('#gfinance').length) {
		$.get('http://pipes.yahoo.com/pipes/pipe.run?_id=c8235f22cd4b0fbef17a2e5618ce265d&_render=rss', function(d){
			console.log(d);
		});
	}
	
	function showData(data) {
		console.log(data);
	}
	
		
	
});





/*
	* Developed by J.P. Given
	* http://johnpatrickgiven.com
	
	******************************************************************************************************
	* NOTE: DON'T DELETE ANY VARIABLES FROM THIS PAGE.  IF YOU DON'T USE A SERVICE SIMPLY LEAVE IT BLANK.*
	******************************************************************************************************
	
	* This file is required for the plug in to work.  Do not erase any of the Javascript variables on this page.
	* If you don't use one of the services below simply leave the value blank ('').
	
	* NOTE: all RSS feed links need to be fully qualified URLs.  ie http://...
*/

// Twitter RSS.  My Twitter RSS feed is in here as an example.
var TWITTER_RSS = 'http://twitter.com/statuses/user_timeline/75092926.rss';
//var TWITTER_RSS = '';

//Custom RSS
var CUSTOM_RSS = '';

// LastFM RSS.
var LASTFM_RSS = '';

// Facebook RSS.
// How do you get it?  It's annoying but here's how.
// After logging in click the link to your profile.
// Scroll down the page and on the left hand side there is a section called "Links".
// Click "See All"
// On the right you'll see a link to the RSS FEED.  Click it.
// Grab that URL.
var FACEBOOK_RSS = '';

// Flickr RSS.
var FLICKR_RSS = '';

// Delicious RSS.
var DELICIOUS_RSS = '';

//Tumblr RSS.
var TUMBLR_RSS = '';

//Wordpress RSS.
var WORDPRESS_RSS = 'http://blog.suitcaseinteractive.com/feed/';
// We don't show the blog feed on the blog, but we do on the main site


// How many to display.  Recommend no more than 25 since RSS only goes back so far.  0 = show all.
var LIMIT = 3;


//Wordpress RSS.
var WORDPRESS_RSS1 = 'http://blog.suitcaseinteractive.com/feed/';
// We don't show the blog feed on the blog, but we do on the main site


// How many to display.  Recommend no more than 25 since RSS only goes back so far.  0 = show all.
var LIMIT1 = 1;



/******************************************************
	* jQuery plug-in
	* So So Social Activity Feed
	* Services accessed: Facebook, Delicious, Twitter, Last.FM, Flickr
	* Developed by J.P. Given (http://johnpatrickgiven.com)
	* Useage: anyone so long as credit is left alone
******************************************************/

var sssJ = {};

sssJ.ACTIVITY_ARRAY1 = new Array();
sssJ.WORDPRESS_FINISHED1 = 0;
sssJ.CONTAINER1 = null;
sssJ.COUNT1 = 0;

(function($) {
	$.fn.soSoSocial1 = function(callback) {
		
		sssJ.CONTAINER1 = $(this);
		
		
		/************************************************************************************
			* Repeated code is not ideal
			* However in this case you want multiple jQuery get's
		************************************************************************************/
		
		
		//Wordpress
		if (WORDPRESS_RSS1 != '') {
			$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22"+encodeURIComponent(WORDPRESS_RSS1)+"%22&format=json&callback=?", function(d) {
				//grab ever rss item from the json result request
				if (d.query.results.rss) {
					$(d.query.results.rss.channel.item).each(function() {
						//if set up to be infinite or the LIMIT1 is not reached, keep grabbing items
						var title = this.title;
						var link = this.link;
						var description = this.description;
						var pubDate = this.pubDate;
						pubDate = pubDate.replace(/\,/g,'');

						//append to the div
						sssJ.ACTIVITY_ARRAY1[sssJ.COUNT1] = new Array();
						sssJ.ACTIVITY_ARRAY1[sssJ.COUNT1][0] = '<li class="clearfix"><div class="social-thumb"><a href="' + link + '"><img src="http://suitcaseinteractive.com/public/images/big-icon-blog.png" alt="" /></a></div><div class="social-status">Posted <a href="'+link+'">' + title + '</a> on our blog.';
						sssJ.ACTIVITY_ARRAY1[sssJ.COUNT1][1] = relative_time1(pubDate);
						sssJ.ACTIVITY_ARRAY1[sssJ.COUNT1][2] = get_delta1(pubDate);
						sssJ.COUNT1++;
					});

					sssJ.WORDPRESS_FINISHED1 = 1;
				} else {
					console.log('SoSoSocial ERROR: Wordpress feed seems to be down.');
					sssJ.WORDPRESS_FINISHED1 = 1;
				}
				

			});
		} else {
			sssJ.WORDPRESS_FINISHED1 = 1;
		}

			print_array1($(this));

		if (typeof callback == 'function') { // make sure the callback is a function
			callback.call(this); // brings the scope to the callback
		}
		
		
		
	};
})(jQuery);

// Print the array! 
function print_array1(obj) {
	
	if (sssJ.WORDPRESS_FINISHED1 == 1) {
		
		if ( (LIMIT1 == 0) || (sssJ.ACTIVITY_ARRAY1.length < LIMIT1) ) {
			LIMIT1 = sssJ.ACTIVITY_ARRAY1.length;
		}
		
		sssJ.CONTAINER1.html("");
		
		sssJ.ACTIVITY_ARRAY1.sort(by(2,1));
		var html = '<ul>';
		for (j = 0; j < LIMIT1; j++) {
			html += sssJ.ACTIVITY_ARRAY1[j][0] + ' (' + sssJ.ACTIVITY_ARRAY1[j][1] + ')</li>';
		}
		html += '</ul>';
		sssJ.CONTAINER1.append(html);
	} else {
		setTimeout("print_array1()", 1000);
	}
}

// pubDate delta1 function
function get_delta1(time_value1) {
	var values1 = time_value1.split(" ");
	time_value1 = values1[2] + " " + values1[1] + ", " + values1[3] + " " + values1[4];
	var parsed_date1 = Date.parse(time_value1);
	var relative_to1 = (arguments.length > 1) ? arguments[1] : new Date();
	var delta1 = parseInt((relative_to1.getTime() - parsed_date1) / 1000);
	if (values1[5] == "+0000") {
		delta1 = delta1 + (relative_to1.getTimezoneOffset() * 60);
	} else {
		delta1 = delta1 + relative_to1.getTimezoneOffset();
	}
	
	
	return delta1;
}

// Function to return the relative time based off of delta1.
function relative_time1(time_value1) {
	
	var delta1 = get_delta1(time_value1);

	if (delta1 < 60) {
		return 'less than a minute ago';
	} else if(delta1 < 120) {
		return 'about a minute ago';
	} else if(delta1 < (60*60)) {
		return (parseInt(delta1 / 60)).toString() + ' minutes ago';
	} else if(delta1 < (120*60)) {
		return 'about an hour ago';
	} else if(delta1 < (24*60*60)) {
		return 'about ' + (parseInt(delta1 / 3600)).toString() + ' hours ago';
	} else if(delta1 < (48*60*60)) {
		return '1 day ago';
	} else {
		return (parseInt(delta1 / 86400)).toString() + ' days ago';
	}
}

// Multi-Dementional Array sort.
function by(i,dir) {
	return function(c,d){c = c[i];d = d[i];return c == d ? 0 : (c < d ? -1*dir : dir)}
}












/******************************************************
	* jQuery plug-in
	* So So Social Activity Feed
	* Services accessed: Facebook, Delicious, Twitter, Last.FM, Flickr
	* Developed by J.P. Given (http://johnpatrickgiven.com)
	* Useage: anyone so long as credit is left alone
******************************************************/

var ACTIVITY_ARRAY = new Array();
var TWITTER_FINISHED = 0;
var FACEBOOK_FINISHED = 0;
var FLICKR_FINISHED = 0;
var LASTFM_FINISHED = 0;
var DELICIOUS_FINISHED = 0;
var TUMBLR_FINISHED = 0;
var CUSTOM_FINISHED = 0;
var CONTAINER = null;
var COUNT = 0;

(function($) {
	$.fn.soSoSocial = function(location, callback) {
		if (location == "main") LIMIT = 3;
		CONTAINER = $(this);
		
		
		/************************************************************************************
			* Repeated code is not ideal
			* However in this case you want multiple jQuery get's
		************************************************************************************/
		
		
		// Twitter
		if (TWITTER_RSS != "") {
			$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22"+encodeURIComponent(TWITTER_RSS)+"%22&format=json&callback=?", function(d) {
				//grab ever rss item from the json result request
				$(d.query.results.rss.channel.item).each(function() {
					//if set up to be infinite or the limit is not reached, keep grabbing items
					var title = this.title;
					var link = this.link;
					var description = this.description;
					var pubDate = this.pubDate;
					pubDate = pubDate.replace(/\,/g,'');
					
					var status = title.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
						return '<a href="'+url+'">'+url+'</a>';
					}).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
						return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
					});
					
					//Remove twitter username from front of status.
					status = '@' + status;
					status = status.replace(/\B@([_a-z0-9]+):/ig, "");
					
					//append to the div
					ACTIVITY_ARRAY[COUNT] = new Array();
					ACTIVITY_ARRAY[COUNT][0] = '<li class="clearfix"><div class="social-thumb"><a href="' + link + '" target="_blank"><img src="http://suitcaseinteractive.com/public/images/big-icon-twitter.png" alt="" /></a></div><div class="social-status">' + status;
					ACTIVITY_ARRAY[COUNT][1] = relative_time(pubDate);
					ACTIVITY_ARRAY[COUNT][2] = get_delta(pubDate);
					COUNT++;
				});
				
				TWITTER_FINISHED = 1;
				
			});
			
		} else { //if not on twitter set it to done.
			TWITTER_FINISHED = 1;
		}
		
		//LastFM
		if (LASTFM_RSS != '') {
			$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22"+encodeURIComponent(LASTFM_RSS)+"%22&format=json&callback=?", function(d) {
				//grab ever rss item from the json result request
				$(d.query.results.rss.channel.item).each(function() {
					//if set up to be infinite or the limit is not reached, keep grabbing items
					var title = this.title;
					var link = this.link;
					var description = this.description;
					var pubDate = this.pubDate;
					pubDate = pubDate.replace(/\,/g,'');
					
					//append to the div
					ACTIVITY_ARRAY[COUNT] = new Array();
					ACTIVITY_ARRAY[COUNT][0] = '<li style="background: url(http://farm5.static.flickr.com/4007/4495300744_5c8afb3149_o.png) no-repeat left center;">Listened to <a href="' + link + '" target="_blank">' + title + '</a>';
					ACTIVITY_ARRAY[COUNT][1] = relative_time(pubDate);
					ACTIVITY_ARRAY[COUNT][2] = get_delta(pubDate);
					COUNT++;
				});
				
				LASTFM_FINISHED = 1;
				

				
			});
		
		} else {
			LASTFM_FINISHED = 1;
		}
		
		if (FACEBOOK_RSS != '') {
			$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22"+encodeURIComponent(FACEBOOK_RSS)+"%22&format=json&callback=?", function(d) {
				//grab ever rss item from the json result request
				
				$(d.query.results.rss.channel.item).each(function() {
					//if set up to be infinite or the limit is not reached, keep grabbing items
					var title = this.title;
					var link = this.link;
					//var description = this.description;
					var pubDate = this.pubDate;
					pubDate = pubDate.replace(/\,/g,'');
					
					//append to the div
					ACTIVITY_ARRAY[COUNT] = new Array();
					
					ACTIVITY_ARRAY[COUNT][0] = '<li class="clearfix"><div class="social-thumb"><a href="' + link + '" target="_blank"><img src="/staging/sites/all/themes/unitedway/images/big-icon-facebook.png" alt="" /></a></div><div class="social-status">' + 'Posted <a href="' + link + '" target="_blank">' + title + '</a>';
					
					ACTIVITY_ARRAY[COUNT][1] = relative_time(pubDate);
					ACTIVITY_ARRAY[COUNT][2] = get_delta(pubDate);
					COUNT++;
				});
				
				FACEBOOK_FINISHED = 1;
				
			});
		} else {
			FACEBOOK_FINISHED = 1;
		}
		
		//Flickr
		if (FLICKR_RSS != '') {
			$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22"+encodeURIComponent(FLICKR_RSS)+"%22&format=json&callback=?", function(d) {
				//grab ever rss item from the json result request
				$(d.query.results.rss.channel.item).each(function() {
					//if set up to be infinite or the limit is not reached, keep grabbing items
					var title = this.title;
					var link = this.link;
					var description = this.description;
					var pubDate = this.pubDate;
					pubDate = pubDate.replace(/\,/g,'');
					title = title.toString();
					title = title.split(",");
					title = title[0];
					
					//append to the div
					ACTIVITY_ARRAY[COUNT] = new Array();
					ACTIVITY_ARRAY[COUNT][0] = '<li style="background: url(http://farm3.static.flickr.com/2727/4494661413_0228be5f32_o.png) no-repeat left center;">Uploaded <a href="' + link + '" target="_blank">' + title + '</a>';
					ACTIVITY_ARRAY[COUNT][1] = relative_time(pubDate);
					ACTIVITY_ARRAY[COUNT][2] = get_delta(pubDate);
					COUNT++;
				});
				
				FLICKR_FINISHED = 1;
				
			});
		} else {
			FLICKR_FINISHED = 1;
		}
		
		//Delicious
		if (DELICIOUS_RSS != '') {
			$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22"+encodeURIComponent(DELICIOUS_RSS)+"%22&format=json&callback=?", function(d) {
				//grab ever rss item from the json result request
				$(d.query.results.rss.channel.item).each(function() {
					//if set up to be infinite or the limit is not reached, keep grabbing items
					var title = this.title;
					var link = this.link;
					var description = this.description;
					var pubDate = this.pubDate;
					pubDate = pubDate.replace(/\,/g,'');
					
					//append to the div
					ACTIVITY_ARRAY[COUNT] = new Array();
					ACTIVITY_ARRAY[COUNT][0] = '<li style="background: url(http://farm5.static.flickr.com/4064/4495300640_2a7cbbb922_o.png) no-repeat left center;">Saved <a href="' + link + '" target="_blank">' + title + '</a>.';
					ACTIVITY_ARRAY[COUNT][1] = relative_time(pubDate);
					ACTIVITY_ARRAY[COUNT][2] = get_delta(pubDate);
					COUNT++;
				});
				
				DELICIOUS_FINISHED = 1;
				
			});
		} else {
			DELICIOUS_FINISHED = 1;
		}
		
		print_array($(this));
		
		if (typeof callback == 'function') { // make sure the callback is a function
			callback.call(this); // brings the scope to the callback
		}
		
		//Tumblr
		if (TUMBLR_RSS != '') {
			$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22"+encodeURIComponent(TUMBLR_RSS)+"%22&format=json&callback=?", function(d) {
				//grab ever rss item from the json result request
				$(d.query.results.rss.channel.item).each(function() {
					//if set up to be infinite or the limit is not reached, keep grabbing items
					var title = this.title;
					var link = this.link;
					var description = this.description;
					var pubDate = this.pubDate;
					pubDate = pubDate.replace(/\,/g,'');

					//append to the div
					ACTIVITY_ARRAY[COUNT] = new Array();
					ACTIVITY_ARRAY[COUNT][0] = '<li style="background: url(http://farm5.static.flickr.com/4022/4494661551_3d68321873_o.png) no-repeat left center;">Posted <a href="' + link + '" target="_blank">' + title + '</a>.';
					ACTIVITY_ARRAY[COUNT][1] = relative_time(pubDate);
					ACTIVITY_ARRAY[COUNT][2] = get_delta(pubDate);
					COUNT++;
				});

				TUMBLR_FINISHED = 1;

			});
		} else {
			TUMBLR_FINISHED = 1;
		}

			print_array($(this));

		if (typeof callback == 'function') { // make sure the callback is a function
			callback.call(this); // brings the scope to the callback
		}
		
		
		
		
		//Custom RSS
		if (CUSTOM_RSS != '') {
			$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22"+encodeURIComponent(CUSTOM_RSS)+"%22&format=json&callback=?", function(d) {
				//grab ever rss item from the json result request
				$(d.query.results.channel.item).each(function() {
					//if set up to be infinite or the limit is not reached, keep grabbing items
					var title = this.title;
					var link = this.link;
					//var description = this.description;
					var pubDate = this.pubDate;
					pubDate = pubDate.replace(/\,/g,'');

					//append to the div
					ACTIVITY_ARRAY[COUNT] = new Array();
					ACTIVITY_ARRAY[COUNT][0] = '<li style="background: url(http://farm5.static.flickr.com/4060/4495300842_3f39a6b514_o.png) no-repeat left center;">Posted <a href="' + link + '" target="_blank">' + title + '</a> on Tumblr.';
					ACTIVITY_ARRAY[COUNT][1] = relative_time(pubDate);
					ACTIVITY_ARRAY[COUNT][2] = get_delta(pubDate);
					COUNT++;
				});

				CUSTOM_FINISHED = 1;

			});
		} else {
			CUSTOM_FINISHED = 1;
		}

			print_array($(this));

		if (typeof callback == 'function') { // make sure the callback is a function
			callback.call(this); // brings the scope to the callback
		}
		
	};
})(jQuery);

// Print the array! 
function print_array(obj) {
	
	if (LIMIT == 0) {
		LIMIT = ACTIVITY_ARRAY.length;
	}
	
	if ((FLICKR_FINISHED == 1) && (TWITTER_FINISHED == 1) && (FACEBOOK_FINISHED == 1) && (LASTFM_FINISHED == 1) && (DELICIOUS_FINISHED == 1) && (TUMBLR_FINISHED == 1) && (CUSTOM_FINISHED == 1)) {
		
		CONTAINER.html("");
		
		ACTIVITY_ARRAY.sort(by(2,1));
		var html = '<ul>';
		for (j = 0; j < LIMIT; j++) {
			html += ACTIVITY_ARRAY[j][0] + ' <span class="date"><nobr>(' + ACTIVITY_ARRAY[j][1] + ')</nobr></span></div></li>';
		}
		html += '</ul>';
		CONTAINER.append(html);
	} else {
		setTimeout("print_array()", 1000);
	}
}

// pubDate delta function
function get_delta(time_value) {
	var values = time_value.split(" ");
	time_value = values[2] + " " + values[1] + ", " + values[3] + " " + values[4];
	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);
	
	return delta;
}

// Function to return the relative time based off of delta.
function relative_time(time_value) {
	
	var delta = get_delta(time_value);

	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';
	}
}

// Multi-Dementional Array sort.
function by(i,dir) {
	return function(a,b){a = a[i];b = b[i];return a == b ? 0 : (a < b ? -1*dir : dir)}
}


/*
	jQuery OneFBLike v1.0 - http://onerutter.com/open-source/jquery-facebook-like-plugin.html
	Copyright (c) 2010 Jake Rutter
	This plugin available for use in all personal or commercial projects under both MIT and GPL licenses.
*/

(function($){  
    $.fn.extend({
        oneFBLike: function(options) {  
        
            //Set the default values, use comma to separate the settings 
            var defaults = {  
            	appID: '',
            	siteTitle: '',
            	siteName: '',
            	siteImage: '',
            	buttonWidth: 450,
            	buttonHeight: 80,
            	showfaces: true,
            	font: 'lucida grande',
            	layout: 'normal',
            	action: 'like',
            	colorscheme: 'light'
            	
            }  
            
            var options =  $.extend(defaults, options);  
                        
            return this.each(function() {  
                var o = options;  
                var obj = $(this);
                
                // Add Meta Tags for additional data - options
                jQuery('head').append('<meta property="og:title" content="'+o.siteTitle+'"/>');
                jQuery('head').append('<meta property="og:site_name" content="'+o.siteName+'"/>');
                jQuery('head').append('<meta property="og:image" content="'+o.siteImage+'"/>');
                
                // Add #fb-root div - mandatory - do not remove
                jQuery('body').append('<div id="fb-root"></div>');
                
                // setup FB Developers App Link - do not touch
                window.fbAsyncInit = function() {
				FB.init({appId: o.appID, status: true, cookie: true, xfbml: true});
				};
				(function() {
				var e = document.createElement('script'); e.async = true;
				e.src = document.location.protocol +
				'//connect.facebook.net/en_US/all.js';
				document.getElementById('fb-root').appendChild(e);
				}());


                // Grab the URL and assign it to a variable
                var dynUrl = document.location;
                var fbDIV = obj;
                                
                              
                // Apply the like button to an element on the page and include all available options
                // If no options are passed in from the page, the defaults will be applied            
                jQuery(fbDIV).html('<fb:like href="'+dynUrl+'" width="'+o.buttonWidth+'" height="'+o.buttonHeight+'" show_faces="'+o.showfaces+'" font="'+o.font+'" layout="'+o.layout+'" action="'+o.action+'" colorscheme="'+o.colorscheme+'"/>')

                              
            });  
        } 
    }); 
})(jQuery);


