// JavaScript Document

$(document).ready(function() {
	//$('#rss').RssFill('http://feeds2.feedburner.com/UrbanOrganicGardener', 3, 'rss_full_template.html', doAlert);
	//$('#picsRss').RssFill('http://feeds2.feedburner.com/RawFoodPhotos', 3, 'rss_description_only_template.html');
	//$('#quotesRss').RssFill('http://feeds2.feedburner.com/QuotesThatMakeYouGoHmm', 3, 'rss_description_only_template.html');
	$('#uog_posts').RssFill('http://feeds2.feedburner.com/UrbanOrganicGardener', 3, 'rss_title_only_template.html');
	$('#srr_posts').RssFill('http://feeds.feedburner.com/SimplyRawRecipes', 3, 'rss_title_only_template.html');
	$('#365_posts').RssFill('http://feeds2.feedburner.com/365WaysToGoGreen', 3, 'rss_title_only_template.html');
	$('#quotes').RssFill('http://feeds2.feedburner.com/QuotesThatMakeYouGoHmm', 3, 'rss_quotes_template.html', afterQuotes);
	$('#recipe_photos').RssFill('http://feeds2.feedburner.com/RawFoodPhotos', 3, 'rss_photos_template.html', afterTumblr);
});

function afterTumblr() {
	$('.feedflare').remove();	
}

var maxCharQuotes = 225;
function afterQuotes() {
	afterTumblr();
	
	$('.quote').each(function() {
		var item = $(this);
		var l = item.text().length;
		if(l > maxCharQuotes) {
			var html = item.html();
			var index = html.indexOf('<br');
			var first = html.substring(0, index-3-(l-maxCharQuotes));
			var last = html.substring(index);
			var iSpace = first.lastIndexOf(' ');
			first = first.substring(0, iSpace);
			item.html(first + '...' + last);
		}
		
	 });
}


function processForm()
  {
    $('submit').disabled = true;
    $('submit').value = "Processing.  Please Wait...";

    $('contact_form').request({
      onSuccess: function(transport)
      {
        if(transport.responseText.match(/^OK/) != null) {
          alert('Your message has been sent!');
          $('contact_form').reset();
        } else {
          alert(transport.responseText);
        }

        $('submit').value = 'Send Message';
        $('submit').disabled = false;
      }
    });

    return false;
  }
