$(document).ready(function () {

	urlFor616 = 'http://plentycreative.com/six.one.six/';
	urlForJWM = 'http://ilovethejw.com/';
	addSiteLinks();

	formatDates();
//	manipulateDates();
	convertArchivesToSelect();
//	convertLabelsToSelect();
	resizeFBWidget();
});


	function resizeFBWidget(){
		$('.FB_fan').width('160px');
		$('.FB_SERVER_IFRAME').width('160px').height('800px');
	}

  function formatDates(){
		$('.blog-posts h2.date-header').each(function(){
			dateParts = $(this).html().split(' ');
			dateMonth = dateParts[0];
			dateDay = parseInt(dateParts[1]);
			$(this).html('<span class="dateMonth">'+dateMonth+'</span><span class="dateDay">'+dateDay+'</span>');
		});
	}

	function configureSidebar(){
		// Remove all H2s which are immediate children of #sidebar .widget
		$("#sidebar .widget").children('h2').remove();
	
		// Prepend new divs to hang background image CSS on
		$("#Profile1").prepend('<div id="profileTitle" class="widgetTitle"></div>');
		$("#BlogArchive1").prepend('<div id="archiveTitle" class="widgetTitle"></div>');
	}

	function resetImageWidths(){
		// Replace values determining width of image, remove inline style, add class
		$("#Blog1 .post-body img[id^=BLOGGER_PHOTO_ID_]").each(function(){
			$(this).attr('src' , $(this).attr('src').replace('/s400/','/s1600/'))
			.removeAttr('style')
//			.removeAttr('height')
			.addClass('blogImage');
		});

		/*
		$('.post .post-body img').each(function(){
			$(this).attr('src' , $(this).attr('src').replace('/s400/','/s1600/'))
			.removeAttr('style')
			.removeAttr('height')
			.addClass('blogImage');
		});
		*/
	}

	function manipulateDates(){
		dateOfThisPost = '';
		$("#Blog1 .post").each(function(){
			dateOfThisPost = ($(this).prev('h2.date-header').html() == null) ? dateOfThisPost : $(this).prev('h2.date-header').html();
			$(this).find('.published').html(dateOfThisPost);
			$(this).find('.post-timestamp').html($(this).find('.timestamp-link'));
			$(this).find('.post-footer-line-1').append($(this).find('.post-labels'));
			$(this).find('.post-labels').html($(this).find('.post-labels').html().replace('Labels:',' in'));
		});
	}

	function addSiteLinks(){
		siteLinks  = '';
		siteLinks += '<div id="siteLinks">';
		siteLinks += 	'<a id="linkTo616" href="../../616/js/'+urlFor616+'" target="_blank" title="Visit the six.one.six website"></a>';
		siteLinks += 	'<a id="linkToJWM" href="../../616/js/'+urlForJWM+'" target="_blank" title="Visit the J.W. Marriott Grand Rapids website"></a>';
		siteLinks += '</div>';
		$("#Label1").prepend(siteLinks);
	}

	function convertLabelsToSelect(){
		$('.list-label-widget-content').prepend('<select id="labelSelect"></select>');
		$('#labelSelect').prepend('<option value="" selected="selected">'+$("#Label1 h2").text()+'</option>');
		$("#Label1 h2").remove();
		$('.list-label-widget-content ul li').each(function(){
			$('#labelSelect').append('<option value="'+$(this).find('a').attr('href')+'">'+$(this).find('a').html()+' '+$(this).find('span').html()+'</option>');
		});
		$('.list-label-widget-content ul').remove();
		$("#labelSelect").change(function(){
			if($(this).val() != ''){
				window.location.href = $(this).val();
			}
		});
	}

	function convertArchivesToSelect(){
		$("#ArchiveList .toggle").remove();

		$('#ArchiveList').prepend('<select id="archiveSelect"></select>');		
		$("#archiveSelect").prepend('<option value="">Select...</option>');

		$("#ArchiveList .archivedate .archivedate").each(function(){
			monthOption  = '';
			monthOption += '<option class="monthVal" value="' + $(this).find('a').attr('href') + '">';
			monthOption += $(this).find('a').html() + ', ' + $(this).parents('.archivedate').children('a').html() + ' ' + $(this).find('.post-count').html();
			monthOption += '</option>';
			$("#archiveSelect").append(monthOption);
			$(this).find('.posts a').each(function(){
				$("#archiveSelect").append('<option class="postLink" value="'+$(this).attr('href')+'">&nbsp;&nbsp;'+$(this).html()+'</option>');
			});
		});

		$("#archiveSelect").change(function(){
			if($(this).val() != ''){
				window.location.href = $(this).val();
			}
		});
		
		$("#BlogArchive1_ArchiveList").remove();

	}






























