
//////////////////////////
//                      //
//   jQuery functions   //
//                      //
//////////////////////////


$(document).ready(function() {
						   
		// Email address obfuscator
		// adapted from Colin Viebrock's method: http://viebrock.ca/code/51/email-protection-with-jquery
		// turns <a href="#" rel="me/example.com" class="email"></a> 
		// into  <a href="mailto:me@example.com" class="email">me@example.com</a>
		$('a.email').each(function(){ 
			e = this.rel.replace('/','@'); 
			this.href = 'mailto:' + e; 
			$(this).text(e); 
		}); 
						   
		// Form autofocus -- focuses on the first form field on any given page:				   
		$("input:visible:enabled:first").focus();
		
		
		// Cycle Lite 
		// fades containers in and out in sequence -- we're using for praise quotes
		/*
		$.fn.cycle.defaults = { 
			timeout:       4000,  // milliseconds between slide transitions (0 to disable auto advance) 
			speed:         1000,  // speed of the transition (any valid fx speed value) 
			next:          null,  // id of element to use as click trigger for next slide 
			prev:          null,  // id of element to use as click trigger for previous slide 
			before:        null,  // transition callback (scope set to element to be shown) 
			after:         null,  // transition callback (scope set to element that was shown) 
			height:       'auto', // container height 
			sync:          1,     // true if in/out transitions should occur simultaneously 
			fit:           0,     // force slides to fit container 
			pause:         0,     // true to enable "pause on hover" 
			delay:         0,     // additional delay (in ms) for first transition (hint: can be negative) 
			slideExpr:     null,  // expression for selecting slides (if something other than all children is required) 
		}; 
		*/
		$('#quote-holder.cycle').cycle({ 
			 fx:    'fade', 
			 timeout: 10000, 
			 speed:  2500,
			 pause:  1 
        });
		
		/*
		$('#teaser').feedreader({
 			targeturl: 'http://blog.kevinroose.com/wp-rss.php',
 			items: 1,
 			descLength: 10
 		});
		*/
		$.ajax({
			type: "GET",
			// url: "feed.xml",
			url: "http://blog.kevinroose.com/feed/",
			success: function(rss) {
				strRSS = "<h4>" + $("/rss/channel/title",rss).text() + "</h4>";
				$("/rss/channel/item/title:lt(5)",rss).each(function(i) {
					strRSS += "<p><strong><a href='";
					strRSS += $("/rss/channel/item/link:eq(" + i + ")",rss).text();
					strRSS += "'>";
					strRSS += $(this).text();
					strRSS += "</a></strong><br />";
					strRSS += ($("/rss/channel/item/description:eq(" + i + ")",rss).text()).substring(0,200) + "...</p>";
				});
		
				$("#teaser").html(strRSS);
			}
		});
		
		/*		
		Technosophos RSS Widget
		by Matt Butcher
		
		Installation:
		=============
		To install the RSS Widget, simply unpack it in the desired directory somewhere
		in your web directory. The jQuery library (http://jquery.com) is required, 
		too. It is provided with this package.
		
		Using RSS Widget:
		=================
		Basic use of the RSS Widget is simple. Make sure that both jquery.js and rsswidget.js
		are loaded in your HTML. Then, create the new widget:
		
		<script>
		var feed = "/rss.xml";
		var target_id = "#rss-widget"; // <-- ID of the div element.
		Technosophos.rssWidget(feed, target_id);
		</script>
		 
		 Later in the body, add a container element into which the widget will be written:
		 
		 <div id="rss-widget"></div>
		 
		 When the document is loaded, the widget will be inserted into that div.
		 
		var feed = "/blog/feed/";
		var target_id = "#teaser"; // <-- ID of the div element.
		Technosophos.rssWidget(feed, target_id);
		*/
		
		
		
}); /*  END jQuery functions */


//////////////////////////////
//                          //
//   Non-jQuery functions   //
//                          //
//////////////////////////////

/*  Google Feeds API */
/*  Pulls last blog post title into an element with id="feed" */

google.load("feeds", "1");

function initialize() {
  var feed = new google.feeds.Feed("http://www.kevinroose.com/blog/feed/");

  feed.load(function(result) {
	if (!result.error) {
	  var container = document.getElementById("feed");
	  // for (var i = 0; i < result.feed.entries.length; i++) {
	  for (var i = 0; i < 1; i++) { // just one headline
		var entry = result.feed.entries[i];

		// var div = document.createElement("div");
		var div = document.createElement("span");
		div.appendChild(document.createTextNode(entry.title));
		container.appendChild(div);
	  }
	}
  });
}

google.setOnLoadCallback(initialize);
