$(document).ready(function() {
	
	$('#logoImage01').hide();
	$('#logoImage01').fadeIn('2000');
	
	$('img[align=right]').css('margin', '0 20px 20px 20px');
	$('img[align=left]').css('margin', '0 20px 20px 20px');
	
	$('h1').hide();
	$('h1').show('slide', { direction: 'right' });
	
	$('h2[name=seasonContent01]').hide();
	
	$('a[name=reveal]').attr('title', 'Click to add...');
	
	$('textarea[class=wysiwyg]').wysiwyg();
	
	$('a[name=revealInput]').click(function(e) {
		e.preventDefault();
		
		var id = $(this).attr('href');
		
		$(id).fadeOut(500, function(e) {
			$(id).html('<input type="text" name="' + id + '" value="" />');
			$(id).fadeIn(500);
		});
	});
	
});

function getSeasonFromHulu(season) {
 
 	$('div[id=seasonContent' + season + ']').toggle('slide', { direction: 'up' });
		
	$('div[id=seasonContent' + season + ']').html('<img src="images/loading-spinner-01.gif" alt="Wait" class="loadingSpinner01" />');
 
 	$.get('asp/proxy.asp?url=http://www.hulu.com/feed/search?query=the+chef%27s+kitchen+season+' + season + '&showname=the+chef%27s+kitchen&sort_by=air_date&type=episode', function(d) {
 
 		var html = "";
 
		//find each 'item' in the file and parse it
		$(d).find('item').each(function() {
	
			var $item = $(this);
			var title = $item.find('title').text();
			var link = $item.find('link').text();
			var description = $item.find('description').text();
			var pubDate = $item.find('pubDate').text();
	
			html += "<div class=\"entry\"><h3 class=\"postTitle\"><a href=\"" + link + "\" target=\"_blank\">" + title + "</a><\/h3>";
			html += "<em class=\"date\">" + pubDate + "</em></p>";
			html += "<p class=\"description\">" + description + "</p>";
			html += "<p><a href=\"" + link + "\" target=\"_blank\">Watch this episode >><\/a></p><\/div>";
		});
	
		$('div[id=seasonContent' + season + ']').html($(html));
		
	});
	
};

function getRecentlyAddedEpisodes(howMany) {
		
	$('div[id=recentlyAddedContent]').html('<img src="images/loading-spinner-01.gif" alt="Wait" class="loadingSpinner02" />');
 
 	$.get('asp/proxy.asp?url=http://www.hulu.com/feed/show/1315/episodes', function(d) {
 
 		var i = 0;
 		var html = "";
		
		//find each 'item' in the file and parse it
		$(d).find('item').each(function() {
			
			var $item = $(this);
			var title = $item.find('title').text();
			title = title.substr(title.search(/ - /) + 3);
			title = title.substr(title.search(/ - /) + 3);
			var link = $item.find('link').text();
			var thumbnail = $item.children('[nodeName=media:thumbnail]').attr('url');
			
			if (thumbnail != null && title != null) {
				html += "<div class=\"entry\"><a href='" + link + "' target='_blank'><img src='" + thumbnail + "' alt='Clip from " + title + "' /></a>";
				html += "<h3><a href='" + link + "' target='_blank'>" + title + "</a></h3></div>";
			
				i++;
				if (i == howMany) return false;
			};
			
		});
				
		$('div[id=recentlyAddedContent]').html($(html));
		
	});
	
};