jQuery(document).ready(function(jQuery) {

	/*
	*	## Data ##
	*	Get quotes and tweets about Arc90 & tweets from Arc90.
	*/
	// ## Live tweets from Arc90:
	jQuery("#tweets-content-from").tweet({
		username: "arc90",
		count: 10,
		loading_text: "Loading Arc90&rsquo;s latest tweets&hellip;"
	});

	// ## Local data tweets and quotes:
	jQuery.ajax({
		type: "GET",
		/*
		*	Note: This url path will have to be changed, depending on the site's location.
		*
		*	Ultra Note: Going to have to do some magic with the paths on this for 
		*	cross-site scripting, since it wont work across sub-domains.
		*/
		url: "/wp-content/themes/arc90_theme/arc_talk.json",
		dataType: "json",
		error: function(xhr, status, error) {
			jQuery("#tweets-content-about").html('<li class="error"><p>Sorry, but we&rsquo;re unable to retrieve tweets about Arc90 at this time.</p></li>');

			jQuery("#about-quote").html(
				'<blockquote>Arc90 may be one of the best groups of people you&rsquo;ll ever work with, but they can&rsquo;t seem to access their quotes.</blockquote>' +
				'<p>&mdash;Jonathan Doe <span><a href="http://arc90.com/">Arc90</a></span></p>');
		},
		success: function(data, status) {
			// Format and insert our content:
			for (var quotenum = 0; quotenum < data.quotes.quote.length; quotenum++) {
				var quote = data.quotes.quote[quotenum];
				jQuery("#about-quote").append(
					'<div><blockquote>'+ quote.text +'</blockquote><p><ins>&mdash;</ins><span>'+ quote.name +', <em>' + quote.title + '</em> <a href="'+ quote.clienturl +'">'+ quote.client +'</a></span></p></div>');
			}
			for (var tweetnum = 0; tweetnum < data.tweets.tweet.length; tweetnum++) {
				var tweet = data.tweets.tweet[tweetnum];
				jQuery("#tweets-content-about").append(
					'<li><p>'+ tweet.text +'</p><p class="from"><a href="'+ tweet.statusurl +'">'+ tweet.name +'</a>, '+ tweet.date +'</p></li>');
			}
			// Scroll through tweets:
			jQuery('#tweets-content-about').cycle({
				fx: 'scrollLeft',
				timeout: 8000,
				speed: 750,
				pause: 1
			});
			// Fade through Quotes:
			jQuery('#about-quote').cycle({
				fx: 'fade',
				timeout: 15000,
				pause: 1
			});
		}
	});

	// ## Arc90 Flickr Images for About:
	// if (jQuery("#content").hasClass("about")) {
	// 	jQuery.ajax({
	// 		type: "GET",
	// 		url: "http://api.flickr.com/services/feeds/photos_public.gne?tags=arc90.com&tagmode=any&format=json&getsizes=small&jsoncallback=?",
	// 		dataType: "jsonp",
	// 		error: function(xhr, status, error) {
	// 			console.log("Error retrieving Flickr photos.");
	// 		},
	// 	    success: function(data, status) {
	// 			$.each(data.items, function(i,item){
	// 				// var imagesize = item.media.m.replace("_m.jpg","_t.jpg");
	// 				var listItem = '<li><a href="' + item.link + '"><img src="' + item.media.m + '" width="220" alt="' + item.title + '" /></a></li>';
	// 				// $("#arc-flickr").append('<li><a href="' + pic.link + '"><img src="' + pic.media.m + '" alt="' + pic.title + '" /></a></li>');
	// 				jQuery(listItem).appendTo("#arc-flickr ul");
	// 				if ( i == 3 ) return false;
	// 			});
	// 			// Fade through Photos:
	// 			jQuery('#arc-flickr ul').cycle({
	// 				fx: 'fade',
	// 				timeout: 10000,
	// 				pause: 1
	// 			});
	// 		}
	// 	});
	// }
	
	/*
	*	Visual Effects & Interaction
	*/
	// ## Thumbnail Switcher for Work:
	jQuery(".thumbnails li img").click(function(){
		var thisImage = jQuery(this).attr("class");
		var client = thisImage.split("-");
		var fullPicLi = "#" + client[0] + " .fullpics ." + thisImage;
		var otherItems = "#" + client[0] + " .fullpics li";
		jQuery(otherItems).attr("style","");
		jQuery(fullPicLi).css({"position":"absolute", "top":"0", "left":"0", "z-index":"1000"});
	});

	// ## Team Page Tag Filter
	jQuery("#tag-filter a").click(function() {
		// if (jQuery(this).attr("id") == "show-all") {
		if (jQuery(this).hasClass("active")) {
			jQuery("#tag-filter a").removeClass("active");
			jQuery(this).removeClass("active");
			jQuery("#employees .employee").addClass("active");
		}
		else {
			// Disable all other active elements:
			jQuery("#tag-filter a").removeClass("active");
			jQuery("#employees .employee").removeClass("active");
			// Enable matched elements:
			jQuery(this).addClass("active");
			var getTag = "." + jQuery(this).attr("id");
			jQuery("#employees .employee").find(getTag).parents(".employee").addClass("active");
		}
	});
	// ## Team Page Info Bubble Hovers
	jQuery("#employees li .headshot").hover(function() {
		var thisemployee = jQuery(this).parent();
		jQuery(thisemployee).css("z-index","1");
		jQuery(".infoBubble",thisemployee).fadeIn("fast");
	},
	function() {
		var thisemployee = jQuery(this).parent();
		jQuery(thisemployee).mouseleave(function(){
			jQuery(".infoBubble",this).hide();
			jQuery(thisemployee).css("z-index","0");
		});
	});

    // ## Twitter footer tabs
    jQuery("#tweets-tab-about").click(function() {
        jQuery("#tweets-tab-from").removeClass("active");
        jQuery(this).addClass("active");
        jQuery("#tweets-content-from").hide();
        jQuery("#tweets-content-about").show();
    });
    jQuery("#tweets-tab-from").click(function() {
        jQuery("#tweets-tab-about").removeClass("active");
        jQuery(this).addClass("active");
        jQuery("#tweets-content-about").hide();
        jQuery("#tweets-content-from").show();
    });

    // ## Homepage Work Slideshow
	jQuery('#slideshow').cycle({
		fx: 'fade',
		timeout: 8000,
		pause: 1,
		pager: "#slideshow-pager"
	});
});
