function getTeaserType(feed){
	var type = '';
	
	if(feed.img != undefined) {	type = 'type-1'	};
	if(feed.img != undefined && feed.title != undefined) {	type = 'type-2'	};
	if(feed.img != undefined && feed.title != undefined && feed.description != undefined) {	type = 'type-3'	};
	if(feed.img != undefined && feed.title != undefined && feed.children != undefined) {	type = 'type-4'	};	
	
	if(feed.iframe_link != undefined) {	type = 'type-5 iframe'	};

	return type;
}

function getSizeBehaviorFormula(length){
	return (length % 4 == 1) ? 3 : 4;
}

function feedToHtml(obj) {
	var itemCount = 1;
	var items = obj.feed;
	var item;

	var defaultColumnCount = 4;
	var columnCount = obj.num_of_columns == null ? defaultColumnCount : obj.num_of_columns;

	if(items.length <= 12 && (obj.num_of_columns == null || obj.num_of_columns == undefined)) {
		columnCount = getSizeBehaviorFormula(items.length);
	}
	
	var html;
	var width = 650;
	var height = 540;
	
	html = '<div class="web-pane-portlets clearfix" id="web-pane-portlets" >';
	for (var i = 0; i < items.length; i++) {
		
		item = items[i];
				
		var trackingCode = 'omnitureWEPAccessibleClick(\'' + item.id + '\',\'' + item.title + '\') ';
		if(i % columnCount == 0) html += '<div class="clearfix row-spearator">';
			
			html += '<div class="portlets-teaser '+ getTeaserType(item) +  ((i % columnCount==(columnCount-1)) ? ' column-end' : '')  + ' clearfix">';
			if(item.iframe_link != undefined)	
			{												 	
				var _width = (item.iframe_width != undefined) ? item.iframe_width : width ;
				var _height = (item.iframe_height != undefined) ? item.iframe_height : height;
		
				html += "<iframe ";
				var _iframeId = 'teaser-iframe-'+i;
				html += ' id = "' + _iframeId + '"';
				html += ' frameBorder = "0"';
				html += ' style = "width: '+ _width +'px;height: '+ _height +'px"';
				
				if(item.iframe_link != undefined ) 	html += 'src = "'+		item.iframe_link.href +'"';
				if(item.title != undefined ) 		html += 'title = "'+	item.title +'"';
				
				html += "></iframe >";
				if(items.length == 1)
					html += '<script>reloadAccessibleIframe(\'' + _iframeId + '\',\'' + obj.id + '\');</script>'
			} else {

				if(item.img != undefined && item.img.src != ''){
					html += '<div class="teaser-media">'
						html += '<img class="link" border="0" width="58" alt="' + ((item.title != undefined) ? item.title : '')  + '" src="'+ item.img.src +'" ';
						html += ' onclick="'+trackingCode+'" ';
						html += ' />';
					html += '</div>'
				}
				
				html += '<div class="teaser-content">';
			
				if(item.link != undefined && item.title != undefined){
					linkTarget = item.link.target != undefined ? "target='"+ item.link.target +"'" : "";
					
					html += '<h2><a href="'+ item.link.href +'"  '+linkTarget+' title="'+ item.title +'" ';
					html += ' onclick="'+trackingCode+'" ';
					html += '>'+ item.title +'</a></h2>'; 
					
				} else {
					html +=  (item.title != undefined && item.title != '') ? '<h2>' +  item.title  + '</h2>' : '';	
				}

				if(item.link != null && item.description != null && item.description != '' && item.description != undefined) {
					html += '<p><a href="'+ item.link.href +'"  '+linkTarget+' title="'+ item.title +'" ';
					html += ' onclick="'+trackingCode+'" ';
					html += '>'+ item.description +'</a></p>';					
				}
				else if(item.description != null && item.description != '' && item.description != undefined) {
					html += '<p>'+ item.description +'</p>';
				}
				else {
					html += '';
				}

				if(item.children != undefined && item.children.length > 0) {
					var _textVisible = false;
					html += '<ul>';
					for (var C = 0 ; C < item.children.length ; C++) {
						
						child = item.children[C];
						var childTrackingCode = 'omnitureWEPAccessibleClick(\'' + child.id + '\',\'' + child.title + '\') ';
						linkTarget = child.link.target != undefined ? "target='"+ child.link.target +"'" : "";
						linkHref = child.link.href != undefined ? child.link.href : "javascript:void(0);"

						html += '<li><a href="'+ linkHref +'"  '+linkTarget+' title="'+ child.title +'"';
						html += ' onclick="'+childTrackingCode+'" ';;
						html += '>'+ child.title +'</a></li>';
					}
					html += '</ul>';	
				}
				
				html += '</div>';
			}
				html += '</div>';

				if(items.length == itemCount) {
					html += '</div>';
				}
				else if (i % columnCount == (columnCount-1)) {
					html += '</div>';
				}
				
				itemCount++;	
	}
	html += '</div>';
	return html;
}
