

Blog = 
{
	getBlog: function(title, date, content, tags, id) {	
		
		var display = "";
			
		var _date = extractDate(date);//extract date
		var _time = date.substring(10, date.length);//extract time
		var _type = "";
		
		var url = "http://pdxartswatch.com/single.html?id="+id;
		
		if (tags == null || tags == "null") {
			_type = "commentary";
			tags = "commentary";
		} else {
			_type = tags.substring(1, tags.length-1);//get type of post
		}
		
		_time = extractTime(_time);
		
		var css = getCSSElements(_type);//get css elements for a specific post
			
			display += "<div id='"+css.id+"'>";
			//@header
			display += "  <div id='top'></div>";
			display += "  <div id='top-2'>";
			display += "    <div id='title'>"+title+"</div>";
			display += "    <div id='date'>"+ _date+"</div>";
			display += "    <div id='breaker'></div>";
			display += "  </div><!-- top-2 -->";
			display += "  <div id='top-3'></div>";
			//@details / contents 
			display += "  <div id='"+css.detailsID+"'>";
			display += "   <div>";
			display +=      clean(extractContents(content).outline) + "<a href='single.html?id="+id+"'> [read more] </a>" ;
			display += "    <p id='tags'><b>Tags:</b> "+ tags +"</p>"; // --->> tags                    
			display += "   </div>";
			display += "  </div><!-- details -->";
			//@footer (comments | share | posted at )
			display += "  <div id='"+css.footerID+"'>";
			display += "   <div>";
			display += "    <span id='comments'><img src='images/icons/comments.gif' /><a href='#' ><span>0</span> Comments </a></span>";
			display += "    <span id='share'>";
			display += "		<a class='addthis_button' href='http://addthis.com/bookmark.php?v=250&amp;username=xa-4bfb60f770da4260' addthis:url='"+url+"'>";
			display += "		<img src='http://s7.addthis.com/static/btn/sm-share-en.gif' width='83' height='16' alt='Bookmark and Share' style='border:0'/>";
			display += "		</a><script type='text/javascript' src='http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4bfb60f770da4260'></script>";
			display += "	</span>";
			display += "    <span id='posted'><img src='images/icons/info.png' /> Posted " + rearrangeDate(date) + " at "+_time+"</span>";
			display += "    <div id='breaker'></div>";
			display += "   </div>";
			display += "  </div><!-- footer -->";
			
			display += "</div>";
				
		
		return display;
	},
	
	//@funtion that will render display for a single post
	getSinglePost: function(params) {
		
		var display = "";
		var _date = extractDate(params.time);//extract date
		var _time = (params.time).substring(10, (params.time).length);//extract time
		var type ="";//get type of post
		if (params.tags == null || params.tags == "null") {
			type = "commentary";
		} else {
			type = (params.tags).substring(1, (params.tags).length-1);//get type of post
		}
		_time = extractTime(_time);
		
		var css = getCSSElements(type);//get css elements for a specif post
			
			display += "<div id='"+css.id+"'>";
			//@header
			display += "  <div id='top'></div>"
			display += "  <div id='top-2'>";
			display += "    <div id='title'>"+params.title+"</div>";
			display += "    <div id='date'>"+ _date+"</div>";
			display += "    <div id='breaker'></div>";
			display += "  </div><!-- top-2 -->";
			display += "  <div id='top-3'></div>"
			//@details / contents 			
			display += "  	<div id='"+css.detailsID+"'>";
			display += "  	 <div>";
			display +=        clean(params.content).replace("[hh:read more]", " " );
			display += "	  <p id='tags'><b>Tags:</b> "+ params.tags +"</p>"; // --->> tags                   
			display += "  	 </div>";
			display += "  	</div><!-- details -->";
			//@footer (comments | share | posted at )
			display += "  <div id='"+css.footerID+"'>";
			display += "   <div>";
			display += "    <span id='comments'><img src='images/icons/comments.gif' /><a href='#' ><span>0</span> Comments </a></span>";
			display += "    <span id='share'>";
			display += "		<a class='addthis_button' href='http://addthis.com/bookmark.php?v=250&amp;username=xa-4bfb60f770da4260'>";
			display += "		<img src='http://s7.addthis.com/static/btn/sm-share-en.gif' width='83' height='16' alt='Bookmark and Share' style='border:0'/>";
			display += "		</a><script type='text/javascript' src='http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4bfb60f770da4260'></script>";
			display += "	</span>";
			display += "    <span id='posted'><img src='images/icons/info.png' /> Posted "+rearrangeDate(params.time) +" at "+_time+"</span>";
			display += "    <div id='breaker'></div>";
			display += "   </div>";
			display += "  </div><!-- footer -->";
			
			display += "</div>";
		
		
		return display;
	}
};

	function getCSSElements(type) {		
		
		var elements = {};
			if (type == "aggregation" || type=="aggregatio") {
				elements = {"id":"aggregation", "headerID":"aggregation-header", "detailsID": "aggregation-details", "footerID":"aggregation-footer"};
			}
			else if ( type == "commentary" ) { 
				elements = {"id":"journal", "headerID":"journal-header", "detailsID": "journal-details", "footerID":"journal-footer"};
			} 
			else if ( type == "news" || type == "new" ) {
				elements = {"id":"news", "headerID":"news-header", "detailsID": "news-details", "footerID":"news-footer"}
			}
			else {
				elements = {"id":"commentary", "headerID":"aggregation-header", "detailsID": "aggregation-details", "footerID":"aggregation-footer"};
			}
			return elements;
	}
	
	//@function that will extract the first and second part of the paragraph
	function extractContents(content) {
		
		try {
			
			var temp = content.split("[hh:read more]");	
			
			return {"outline":temp[0],"second-outline": temp[1]};
			
		} catch (e) {
			//anticipating if in case the entry
			//is too short and does not have [hh:read more]
			//return the whole content instead..
			return {"outline":content,"second-outline": "..."};
		}
	}
	
	//@function that will extract all \n and turn them into <br />
	function clean(details) {

		var temp = details.split("\r");
		var _temp = "";
		for ( var i = 0; i < temp.length; i++) {
			_temp +=  temp[i] + "<br />";
		}	
		return _temp;
	 }
	
	//@function that will remove all white spaces in between words
	function removeWhiteSpace(field){
		 field = field.replace(/\s/g, "");	 
		 return field;	 
	}
	
	
	//@function that will extract the date and return it to this format Month day, year
	function extractDate(date) {
		var temp = date.substring(0,10);	
		var temp2 = temp.split("-");
	
		var month = convertMonth(temp2[1]);
		var year = temp2[0];
		var day = temp2[2];
		
		return month + " " + day + ", " + year;
	}
	
	//@function that will convert the numeric value of a month and turn them into 3 english letters
	function convertMonth(month) {	
		switch (month) {
			case "01":  return "Jan";	break;
			case "02":  return "Feb"; 	break;
			case "03":  return "Mar"; 	break;
			case "04":  return "Apr";	break;
			case "05":  return "May";	break;
			case "06":  return "Jun";	break;
			case "07":  return "Jul";	break;
			case "08":  return "Aug";	break;
			case "09":  return "Sep";	break;
			case 10: return "Oct";	break;
			case 11: return "Nov";	break;
			case 12: return "Dec";	break;
		}//switch
		
	}//convertMonth
	
	function extractTime(time) {
	
		var temp = removeWhiteSpace(time).replace("Etc/GMT",""); 
		var _temp = temp.split(":");		
		var daylight = "";
		
		if (_temp[0] <= 12) {daylight = "AM";}
		else {daylight = "PM";}
		
		switch(_temp[0]) {
			case "13":_temp[0] = 1;break;
			case "14":_temp[0] = 2;break;
			case "15":_temp[0] = 3;break;
			case "16":_temp[0] = 4;break;
			case "17":_temp[0] = 5;break;
			case "18":_temp[0] = 6;break;
			case "19":_temp[0] = 7;break;
			case "20":_temp[0] = 8;break;
			case "21":_temp[0] = 9;break;
			case "22":_temp[0] = 10;break;
			case "23":_temp[0] = 11;break;
			case "24":_temp[0] = 12;break;
		}//switch
		
		return " <b> "+_temp[0]+": "+_temp[1]+" "+daylight+"</b>";
	}
	
	//@function that will extract the date and return it to this format Month day, year
	function rearrangeDate(date) {
		var temp = date.substring(0,10);	
		var temp2 = temp.split("-");
	
		var month = convertMonth(temp2[1]);
		var year = temp2[0];
		var day = temp2[2];
		
		return "<b>" + day + " " + month + " " + year + "</b>";
	}
