rl.people = (function() {
	var accordionSetup = function() {
		if (!($.browser.msie && $.browser.version == "7.0")) {
			var options = {};
			options.header = "h2";
			options.fillSpace = true;
			options.clearStyle = false;
			$("#" + rl.currPage[1] + "Page .accordion").accordion(options);
		} else {
			//don't accordion the sucker, just reset the styles so it looks decent.
			//This should be set as default in an IE7-only style sheet
			$("#peoplePage .bio").css("height", "auto");
			$("#peoplePage .accordionContainer").css('height', 'auto').css('overflow', 'visible');
			$("#peoplePage .ui-accordion-content").css('padding-top', '10px').css('padding-bottom', '10px');
			$(window).trigger("resize");
		}
		$("#titleLoader").hide();
	}
	
	var pageSetup = function() {		
		rl.model.loadAssets($(rl.secPageID + " .postLoad"), function(imgs) {
			var name = $(rl.secPageID + " .peopleMeta").attr("name");
			var title = $(rl.secPageID + " .peopleMeta").attr("title");
			var id = $(rl.secPageID + " .peopleMeta").attr('id');
			var titleH2 = '<span class="name">'+name+'</span><span class="title">'+title+'</span>';
			
			$(rl.primPageID + " .titleBar #peopleSelect h2").html(titleH2);
			//$(rl.primPageID + " .titleBar .subtitle").html(titleH2);
			
			//$(rl.secPageID + " .portrait").html('<img src="assets/img/portrait-' + id + '.jpg" alt="Portrait of ' + name + '"/>');
			//$("#pageBG").css("background-image", 'url("assets/img/bg-people-'+id+'.jpg")');
			
			$(rl.secPageID + " .portrait").html('<img src="'+imgs['portrait'].src+'" alt="Portrait of ' + name + '"/>');
			if (imgs['bg-people']) {
				$("#pageBG").css("background-image", 'url("'+imgs['bg-people'].src+'")');
			}
			
			//Lowlight all dropdown items
			$("#peopleOptions li a").removeClass("active");
			//Highlight the currently active dropdown item
			$("#peopleOptions li a[href='/#people/"+rl.secPageName+"']").addClass("active");
			accordionSetup();
		});
	}
	
	var parseXML = function(feedData) {		
		//handle IE weirdness about loading xml that has content-type of html
		var data;
		if (typeof feedData == "string") {
			data = new ActiveXObject("Microsoft.XMLDOM");
			data.async = false;
			data.loadXML(feedData);
		} else {
			data = feedData;
		}
		//load user feed
		var lis = "";
		$(data).find("entry").each(function(ind, elem) {
			if (ind < 5) {
				//format the date how IE wants it
				var dateStr = $(this).find("published").text().replace(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/g, "$1/$2/$3 $4:$5:$6");
				var date = new Date(dateStr);
				lis += '<li><div class="date">' + date.toDateString() + '</div><a href="' + $(this).find("link").attr("href") + '">'+$(this).find("title").text()+'</a></li>';
			}
		});
		$("#" + rl.currPage[1] + "Page .entriesContainer").html(lis);
		pageSetup();		
	}
	
	var parseXMLNoBlog = function(xhr, status, error) {
		//alert(status);
		$("#" + rl.currPage[1] + "Page .blog").remove();
		pageSetup();
	}
	
	return {
		load : function() {
			$("#titleLoader").show();
			//if there's a blog section, load the blog data
			if ($("#" + rl.currPage[1] + "Page .blog").length > 0) {
				rl.model.loadBlogAuthorFeed(rl.currPage[1], parseXML, parseXMLNoBlog);
			} else {
				//if there isn't a blog section, just set up the page				
				pageSetup();
			}
		},
		init: function() {			
			return;
		}
	};
}());
