var cellStreamOptions = new Object();
cellStreamOptions.blast = '';
cellStreamOptions.pageSize = 3; // number of items per stream page
cellStreamOptions.pageNumber = 0;
cellStreamOptions.pageCount = 0;
cellStreamOptions.availablePages = 0;
cellStreamOptions.author = ''; // empty string means all

var csCurrentPageElement;
var csCount = 0;
//Variables to set the co-ordinates for an active cellstream cell. 
var csActiveLeftCoor =0 ;
var csActiveTopCoor = [0,175,374];
var csActiveHeight = 253;
var csActiveWidth = 225;
//Variables to set the co-ordinates for a normal cellstream cell. 
var csNormalTopCoor = [0,203,406];
var csNormalHeight = 193;
var csNormalWidth = 129;
var csNormalLeftCoor = 0;

//Cellstream-detail page URL prefix
var csDetailUrlPrefix = '/cellstream?id=';

/* Sets the maximum number of tour dates to be shown with in the module.*/
var tourDateMaxItems = 5; 

/*This is the View All Link of the Tour Date module.*/
var tdViewAllLink="/tour-dates/"; 

/* Text that is displayed when no shows are available */
var tdNoShowsText="No shows scheduled. Check again later";


var monthNames = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun",
			"Jul", "Aug", "Sep", "Oct", "Nov", "Dec");


/* Twitter text */
var followTwitterText = "Follow [Band Name] on Twitter";

renderRSSModule = function(data,format, div) {
	
	if (div.attr("id") == "rss_content-382956") {
	
		div.empty();
		if ($("body").is("#home")) {
			/* This is tours module in the home page. In this module a maximum of 
		 * above set tour dates are displayed.
		 * The tdAllFlag is set to false, so that it displays only the set number of tour dates in the module.
		 */
			tdAllFlag = false;
		}
		else {
			/* This is tours module in the concerts landing page module. In this module 
		 * all the tour dates are displayed.The tdAllFlag is set to true, so that
		 * it displays all the tour dates.
		 */
			tdAllFlag = true;
		}
		tourDatesWrapper = tourDatesBuildStructure(tdAllFlag, data);
		div.append(tourDatesWrapper);
	} 
	/** International feed ***/
	else if (div.attr("id") == "rss_content-838558") {		 
		 var feed = new InternationalFeed(div.attr("id"), div, data, 5);
		 feed.showNextPage();		
	}else if (div.attr("id") == "rss_content-838375") {		 
		 var feed = new InternationalFeed(div.attr("id"), div, data, 5);
		 feed.showNextPage();		
	}
	else if ($(div).attr("id") == "rss_content-413300") {		
		if ($("#cellstream").length > 0	){
				/* Cellstream details page: Div id of Cellstream Details section */
				div.empty();
				// ciscoeos.com?someparam=name&otherparam=8&id=6
				var selectedID = $.urlParam('id');		
				var isInputParam=false;			
				
				
				/* If the param - id is not null */
				if (selectedID != 0) {			
					isInputParam=true;	
					csDetailsWrapper=csDetailsBuildStructure(data,selectedID,isInputParam);
					div.append(csDetailsWrapper);		
				}		
				else {				
					/* Param id is blank */
					isInputParam=false;	
					csDetailsWrapper=csDetailsBuildStructure(data,selectedID,isInputParam);
					div.append(csDetailsWrapper);
				}							
		}
		else{
			/* Cell stream rss module */
			initCellstream(div, data);	
			/*div.empty();
			cellStreamWrapper=cellstreamBuildStructure(data);
			div.append(cellStreamWrapper);
			cellStreamOptions.pageNumber = 0;
			registerPreviousNextEvents();
			/* Setting the previous and next buttons */
			/* Display the first page */
			/*showCSPage(0);
			registerHover();*/
		}	
			
		
	}
	else if (div.attr("id") == "rss_content-399814") { 
			renderRSSModuleEOS(data, format, div);
			titleDiv = $("#rss_content-399814 h3");
			$("#rss_content-399814").append($("#rss_content-399814 h3"));
			$("#rss_content-399814 h3 a").text(followTwitterText);
			$("#rss_content-399814 a").attr("target", "_new");
	}else if (div.attr("id") == "rss_content-699114") {
			bbcDiscussionWrapper=renderDiscussionModule(data);
			div.append(bbcDiscussionWrapper);
	}
	else {
		/* Default RSS Ingester module functionality */
		//if this isn't the cellstream RSS module then use the EOS default copied and pasted below
		renderRSSModuleEOS(data, format, div);
	}

}


renderRSSModuleEOS=function(c,a,b){jQuery.getFeed({xml:c,success:function(g){jQuery(b).append('<h3><a href="'+g.link+'">'+g.title+"</a></h3>");var e="";for(var d=0;d<g.items.length&&d<5;d++){var f=g.items[d];e+="<h4>";if(f.link.length>0){e+='<a href="'+f.link+'">'+f.title+"</a>"}else{e+=f.title}e+="</h4>";e+='<div class="updated">'+f.updated+"</div>";e+="<div>"+f.description+"</div>";if(f.image){e+='<div class="image"><img src="'+f.image+'"></div>'}}jQuery(b).append(e)}})};


function createTourDateUnit(title, venueName,venueCountry,venueState,venueCity,venueLocation,buyLink, appearingWith,dateFirstUnit){
		
	tourDatesUnit = document.createElement('div');
	$(tourDatesUnit).attr("class","tourDatesUnit");
	if((dateFirstUnit==0)){
		$(tourDatesUnit).addClass("first");
	}
	if(!(dateFirstUnit%2)){
		$(tourDatesUnit).addClass("oddEntry");
	}	
	
	//create tour date unit
	tdDateUnit = document.createElement('div');
	$(tdDateUnit).attr("class","tdDateField");
	var day;
	var dateInTitle = "" + title.match(/\d{1,2}\/\d{1,2}/);	
	var unFormatDay ="" +title.match(/- \w{3}/);	
	if(unFormatDay != null){
		day=unFormatDay.substring(2,5);
	}	
	var dateString = "";
	var monthString = "";
	if(dateInTitle != null ) {
		var dateArray = dateInTitle.split("\/");		
		monthString = monthNames[dateArray[0]-1];
		dateString = dateArray[1];		
	}
	//$(tdDateUnit).append('<div class="tdDay">'+ day +'</div><div class="tdDM">'+ dateInTitle +'</div>');
	
	$(tdDateUnit).append('<div class="tdMonth">'+ monthString +'</div><div class="tdDD">'+ dateString +'</div>');
	
	//create tourVenueBuyWrapper	
	tourVenueBuyWrapper = document.createElement('div');
	$(tourVenueBuyWrapper).attr("class","tourVenueBuyWrapper");

	//create tour venue unit
	tdVenueField = document.createElement('div');
	$(tdVenueField).attr("class","tdVenueField");
	
	
	venueString="<span>";
	if ($.trim(venueLocation) != "" ){venueString += $.trim(venueLocation)}
	venueString += "</span>"
	$(tdVenueField).append('<div class="tdVenue">' + venueString + '</div>' + venueName);
	
	if (appearingWith.replace(/\s/g,"") != ""){
		$(tdVenueField).append('<div class="tdArtistName">'+ "Appearing with " + appearingWith +'</div>');
	}
	$(tourVenueBuyWrapper).append(tdVenueField);

	//create purchase tickets unit
	if (buyLink != ""){
		tdBuyLinksField = document.createElement('div');
		$(tdBuyLinksField).attr("class","tdBuyLinksField");
		$(tdBuyLinksField).append('<div class="tdBuyLinks"><a href="'+ buyLink +'" target="_blank">Buy Tickets</a></div>');
		$(tourVenueBuyWrapper).append(tdBuyLinksField);
		$(tourVenueBuyWrapper).append('<div class="clear"></div>');		
	}
	
	$(tourDatesUnit).append(tdDateUnit);
	$(tourDatesUnit).append(tourVenueBuyWrapper);
	$(tourDatesUnit).append('<div class="clear"></div>');
	return tourDatesUnit;
}

function tourDatesBuildStructure(tdAllFlag,data){
	tourDateCount = 0;
	var dateFirstUnit=0;
	
	//Load into XML DOM
	xmlDom = getXMLDOM(data);
	tourDatesWrapper = document.createElement('div');
	$(tourDatesWrapper).attr("class","tourDatesWrapper");
	totalTourItems = ($(xmlDom).find('item').length);
	tourDateLimit = tdAllFlag ? totalTourItems : tourDateMaxItems;
	if ($(xmlDom).find('item').length <= 0){
		$(tourDatesWrapper).append('<span class="tdErrorText">'+ tdNoShowsText + '</span>');
	}else {
		if(!tdAllFlag && totalTourItems > tourDateLimit) {
			$(tourDatesWrapper).append('<div class="tdViewAll header"><a href="' + tdViewAllLink + '">View All</a></div');
		}
	}
	
	var itemLen=$(xmlDom).find('item').length;
	var titleText=($(xmlDom).find('item').children("title").text());


if (!(itemLen == 1 && (jQuery.trim(titleText).indexOf("Sorry", 0) != -1))) {
	$(xmlDom).find('item').each(function(){
		title = $(this).children("title").text();
		venueName = $(this).children("venueName").text();
		venueCountry = $(this).children("venueCountry").text();
		venueCity = $(this).children("venueCity").text();
		venueState = $(this).children("venueState").text();
		venueLocation = $(this).children("venueLocation").text();
		buyLink = $(this).children("buylink").text();
		appearingWith = $(this).children("appearingWith").text();
		tourDatesUnit = createTourDateUnit(title, venueName, venueCountry, venueState, venueCity, venueLocation, buyLink, appearingWith, dateFirstUnit);
		$(tourDatesWrapper).append(tourDatesUnit);
		tourDateCount++;
		dateFirstUnit++;
		if (tourDateCount == tourDateLimit) {
			return false;
		}
	})
}

	if (!($(xmlDom).find('item').length <= 0)) {
		if(!tdAllFlag && totalTourItems > tourDateLimit) {
			$(tourDatesWrapper).append('<div class="tdViewAll"><a href="' + tdViewAllLink + '">View All</a></div');
		}
	}
	return tourDatesWrapper;
}

/*
 * Functions for Cellstream pagination
 */




function generateCellStreamCell(author,authorFirstName,date,text,image,video,i,csPage,postid){
	
	var cellElement = document.createElement('div');
	var contentElement = document.createElement('div');
	$(contentElement).attr("class","csContent");
	/* Add the image if available */
	if (image != ""){
		$(contentElement).append('<div class="image"><a href="' + csDetailUrlPrefix + postid+'"><img src="' + image + '"/></a></div>');
	}
	/* To add Cell Stream Details 
	   <a href="' + csDetailUrlPrefix + postid+'"></a>
	 */
	/* Add the video if available */
	if ($(video).text() !=""){
		var videoElement = document.createElement('div');
		$(videoElement).attr("class","video");
		$(videoElement).attr("id","cellStreamVideoPlayer"+i);
		$(videoElement).append('<img class="image" src="'+ $(video).children("flvUrl").text()+ '.jpg' +'"/>');
		$(contentElement).append(videoElement);

		var videoParams = document.createElement('div');
		$(videoParams).attr("class","csVideoParams");
		$(videoParams).append('<span class="videoParams csFlvUrl">'+ $(video).children("flvUrl").text() +'</span');
		$(videoParams).append('<span class="videoParams csSwfUrl">'+ $(video).children("swfUrl").text() +'</span');
		$(videoParams).append('<span class="videoParams csConfigUrl">'+ $(video).children("configUrl").text() +'</span');
		$(videoParams).append('<span class="videoParams playerId">'+ "cellStreamVideoPlayer"+i +'</span');
		$(contentElement).append(videoParams);
	}
	
	/* Handle Text only case */
	if ($(video).text() != "" || image!= "") {
		$(contentElement).addClass('imageVideo')
	}
	
	if ($(video).text() == "" && image== "") {
		$(contentElement).append('<div class="fullText text">'+text+'</div>');
	} else {
		$(contentElement).append('<div class="text">'+text+'</div>');
	}
	
	$(contentElement).append('<div class="text">'+text+'</div>');
	

	/* Create the Wrapper */
	var wrapperElement = document.createElement('div');
	$(wrapperElement).attr("class","csWrapper");	
	dateString = simpleDate(date);
	$(wrapperElement).append('<div class="timestamp">' + dateString + '</div>');
	$(wrapperElement).append('<div class="user">' + author + '</div>');
	$(wrapperElement).append('<div class="clear"></div>');
	
	/* Adding all of them to the cell element */
	$(cellElement).attr("id", "csCell" + i);
	$(cellElement).attr("class", "csCell");
	$(cellElement).addClass("csCell" + csPage);
	$(cellElement).append(contentElement);
	$(cellElement).append(wrapperElement);
	
	return cellElement;
	
}

/* This function is used to build CellStream- Details module */
function csDetailsBuildStructure(data,selectedID,isInputParam){

	if (isInputParam == true) {
		var isPhotoAvl=false;	

		data = data.replace(/image>/g, 'image-url>');
		xmlDom = getXMLDOM(data);			
		// Search for post id in the feed and adding up the components if present
		$(xmlDom).find("post").filter("[id^='" + selectedID + "']").each(function(){
			isPhotoAvl = true;				
			csDetailsWrapper = document.createElement('div');
			$(csDetailsWrapper).attr("id", "csPhotosViewWrapper");
			cellStreamElement = document.createElement('div');
			$(cellStreamElement).attr("id", "cellStreamPhotosViewer");
			csPage = csCount % cellStreamOptions.pageSize;
			
			if (csPage == 0) {
				csCurrentPageElement = document.createElement('div');
				$(csCurrentPageElement).attr("id", "csPage" + csCount / cellStreamOptions.pageSize);
				$(csCurrentPageElement).attr("class", "csPage");
			}						
			author = $(this).children("author").text();
			authorFirstName = $(this).children("authorFirstName").text();
			date = $(this).children("date").text();
			text = $(this).children("text").text();
			image = $(this).children("image-url").text();
			video = $(this).children("video");			
			/* Generate the cell element using the data and add to Cellstream Slider */
			nodeHtml = getSelectedPhoto(author, authorFirstName, date, text, image, video, csCount, csPage);
			$(csCurrentPageElement).append(nodeHtml);
			$(cellStreamElement).append(csCurrentPageElement)
			csCount++;			
		});
		
		/* If id is not available or Junk value */
		if (isPhotoAvl == false) {
			csDetailsWrapper = document.createElement('div');
			$(csDetailsWrapper).attr("id", "csPhotosNotAvl");
			cellStreamElement = document.createElement('div');
			$(cellStreamElement).attr("id", "cellStreamPhotosNotAvl");			
			$(cellStreamElement).append('<div class="noImageText">Image not Found</div>');			
		}		
		
		$(csDetailsWrapper).append(cellStreamElement);		
		
	}else{
		/* If id is Blank */
		//Image Not found	
		csDetailsWrapper = document.createElement('div');
		$(csDetailsWrapper).attr("id","csPhotosNotAvl");
		cellStreamElement = document.createElement('div');
		$(cellStreamElement).attr("id","cellStreamPhotosNotAvl");
		csCurrentPageElement = document.createElement('div');							
							
		/* Add the text content */
		$(csCurrentPageElement).append('<div class="noImageText">Image not Found</div>');								
		$(cellStreamElement).append(csCurrentPageElement);	
		$(csDetailsWrapper).append(cellStreamElement);					
	}
	
	return csDetailsWrapper;							
}

/* Convert the timestamp to text format */
function simpleDate(timestamp) {

	currentDate = new Date();
	postedDate = new Date(timestamp);
	
	offset = currentDate.getTime() - postedDate.getTime();
	
	/*display full timestamp if posted Date is in the future or more than 10 days ago*/
	if(offset < 0 || offset > 10 * 24 * 60 * 60 * 1000) {
		return postedDate.getMonth() + '/' + postedDate.getDate() + '/' + (postedDate.getYear() + 1900)
	}
	
	//display mins if less then an hour ago
	if(offset < 60 * 60 * 1000) {
		mins = Math.round(offset / (60 * 1000));
		return  mins + ' min' + (mins > 1 ? 's' : '') + ' ago';
	}
	
	//display hours if less than a day ago
	if(offset < 24 * 60 * 60 * 1000) {
		hrs = Math.round(offset / (60 * 60 * 1000));
		return  hrs + ' hr' + (hrs > 1 ? 's' : '') + ' ago';
	}

	//display days
	days = Math.round(offset / (24 * 60 * 60 * 1000));
	return days + ' day' + (days > 1 ? 's' : '') + ' ago';
}
//Registering the event for the Previous and Next Button clicks

function registerPreviousNextEvents(){
	$(

		function (){
			
			$(".csPrevious").click(function (event){
				if (cellStreamOptions.pageNumber > 0){
					cellStreamOptions.pageNumber--;
					showCSPage(cellStreamOptions.pageNumber);
				}
				event.preventDefault();
			});
			$(".csNext").click(function(event){
				if (cellStreamOptions.pageNumber < cellStreamOptions.pageCount){
					cellStreamOptions.pageNumber++; 
					showCSPage(cellStreamOptions.pageNumber);
				}
				event.preventDefault();
			});
		}
	);
}


//function to hit all CS pages other than one given. 
function showCSPage(pageNumber){
	$("#cellStreamSlider").children().each(function (){
		if ( $(this).attr("id") == "csPage"+pageNumber){
			$(this).fadeIn();
		}else{
			$(this).hide();
		}
	});
	setArrows();
}
/* Create the pagination buttons */
function appendPreviousNextButtons(div){
	buttonWrap=document.createElement('div');
	$(buttonWrap).attr("id","csButtonWrapBot");
	$(buttonWrap).attr("class","csButtonWrap");
	$(buttonWrap).append('<a href="#" id="csPrevious" class="csPrevious"><span></span></a>');
	$(buttonWrap).append('<a href="#" id="csNext" class="csNext"><span></span></a>');
	$(buttonWrap).append('<span class="clear"/>');
	$(div).append(buttonWrap);
	registerPreviousNextEvents();
}

/* Register hovering effect on the images and videos */
function registerHover(){
	$('#cellStreamSlider .csCell').hover(function() { //mouseover
		
		if(!$('#cellStreamSlider .csCell').hasClass('active')){
			className = $(this).attr("class");
			index = className.substring(13); 
			$(this).animate({
					width: csActiveWidth+"px",
					height: csActiveHeight+"px",
					top: csActiveTopCoor[index]+'px',
					left: csActiveLeftCoor+ 'px'
					}, 200, 'swing');
			
			if ($(this).find('.csFlvUrl').text() != '' ){
				csSwfUrl = $(this ).find(".csSwfUrl").text();
				csConfigUrl = $(this).find(".csConfigUrl").text()
				csFlvUrl = $(this).find(".csFlvUrl").text();
				csPlayerId = $(this).find(".playerId").text();
				$("#"+csPlayerId).empty();
				var swf = new SWFObject(csSwfUrl,"cs_player","203","155","8");
                                swf.addVariable("config",csConfigUrl);
                                swf.addParam("allowfullscreen","true");
				swf.addVariable("file",csFlvUrl);
				swf.addVariable("image",csFlvUrl+".jpg");
				swf.addVariable("width","203");
				swf.addVariable("height","155");
				swf.addParam('allowscriptaccess','always');
				swf.write(csPlayerId);
				$("#"+csPlayerId).append('<div class="csFlvClose"><a id="csFlvCloseButton" href="JavaScript:void(0)">X<a/></div>')
				activateCsFlvClose($(this));
			}
		
			$(this).addClass('active');
		}
	}, function() { //mouseout
		if (playerIdle()) {
			$(this).stop();
			$(this).removeClass('active');
			resetActiveToNormal($(this));
			if ($(this).find('.csFlvUrl').text() != '' ){
				hidePlayer($(this));
			}
		}
	})
}
function getSelectedPhoto(author, authorFirstName, date, text, image, video, i, csPage){

	/* Create the Cell */
	var cellElement = document.createElement('div');
	
	/* Create the Cell content */
	var contentElement = document.createElement('div');
	$(contentElement).attr("class","csPVContent");
	/* Add the image if available */
	if (image != ""){
		$(contentElement).append('<div class="image"><img src="' + image + '"/></div>');				
	}
	
	/* Add the text content */
	$(contentElement).append('<div class="text">'+text+'</div>');
	
	/* Create the Wrapper */
	var wrapperElement = document.createElement('div');
	$(wrapperElement).attr("class","csWrapper");	
	dateString = simpleDate(date);
	$(wrapperElement).append('<div class="timestamp">' + dateString + '</div>');
	$(wrapperElement).append('<div class="user">' + author + '</div>');
	$(wrapperElement).append('<div class="clear"></div>');
	
	/* Adding all of them to the cell element */
	$(cellElement).attr("id", "csCell" + i);
	$(cellElement).attr("class", "csCell");
	$(cellElement).addClass("csCell" + csPage);
	$(cellElement).append(contentElement);
	$(cellElement).append(wrapperElement);
	
	return cellElement;	
}


function resetActiveToNormal(cell){
	className = cell.attr("class");
	index = className.substring(13); 
	cell.css({
		width: csNormalWidth+'px',
		height: csNormalHeight+'px',
		top: csNormalTopCoor[index]+'px',
		left: csNormalLeftCoor+'px'
	})
	
}

function activateCsFlvClose(cell){
	$('#csFlvCloseButton').click(function(){
		cell=$("#cellStreamSlider").find('.active');
		cell.stop();
		cell.removeClass('active');
		resetActiveToNormal(cell);
		if (cell.find('.csFlvUrl').text() != '' ){
			hidePlayer(cell);
		}
	});
}
/* Function to hide the player */
function hidePlayer(cell) {
    if (!playerIdle()) {
   		sendEvent('cs_player','stop')
   	}
	state=-1;
	csPlayerId = cell.find(".playerId").text();
	csFlvUrl = cell.find(".csFlvUrl").text();
	$("#"+csPlayerId).empty();
	$("#"+csPlayerId).append('<img class="image" src="'+ csFlvUrl + '.jpg' +'"/>');
}

/* Check if the player is idle */	
var state=-1;
function playerIdle(){
	if (state <1){
		return true;
	}else {
		return false;
	}
}
 
function sendEvent(swf,typ,prm) { 
  try {
  thisMovie(swf).sendEvent(typ,prm); 
  }catch(err){
	writeToConsole(err);
  }
};
 
function getUpdate(typ,pr1,pr2,swf) {
if (typ=='state'){
       state = pr1;
  };
};
function thisMovie(swf) {
  if(navigator.appName.indexOf("Microsoft") != -1) {
    return window[swf];
  } else {
    return document[swf];
  }
};

/* Disable and Enable pagination buttons based on the page */
function setArrows() {
	if (cellStreamOptions.pageNumber > 0) {
		$('.csPrevious').removeClass('csPreviousDisabled');
		$('.csPrevious').addClass('csPreviousEnabled');
	} else {
		$('.csPrevious').removeClass('csPreviousEnabled');
		$('.csPrevious').addClass('csPreviousDisabled');
	}
	if (cellStreamOptions.pageNumber < cellStreamOptions.pageCount) {
		$('.csNext').removeClass('csNextDisabled');
		$('.csNext').addClass('csNextEnabled');
	} else {

		$('.csNext').removeClass('csNextEnabled');
		$('.csNext').addClass('csNextDisabled');
	}
}

/* This function is used to build CellStream module */
function cellstreamBuildStructure(data){	
		
		/* Create Wrapper and Slider */
		cellStreamWrapper = document.createElement('div');
		$(cellStreamWrapper).attr("id", "cellStreamWrapper");
		
		buttonWrap=document.createElement('div');
		$(buttonWrap).attr("id","csButtonWrap");
		$(buttonWrap).attr("class","csButtonWrap");
		$(buttonWrap).append('<a href="#" id="csPrevious" class="csPrevious"><span></span></a>');
		$(buttonWrap).append('<a href="#" id="csNext" class="csNext"><span></span></a>');
		$(buttonWrap).append('<span class="clear"/>');	
		$(cellStreamWrapper).append(buttonWrap);
		
		cellStreamElement = document.createElement('div');
		$(cellStreamElement).attr("id", "cellStreamSlider");
		
		data = data.replace(/image>/g, 'image-url>');	
		/* Handle MicroSoft Browsers */	
		xmlDom = getXMLDOM(data);
		
		/* Obtain the rss and loop through individual posts */
		csTotalPosts = ($('post', xmlDom).length);
		$('post', xmlDom).each(function(){
			csPage = csCount % cellStreamOptions.pageSize;
			if (csPage == 0) {
				csCurrentPageElement = document.createElement('div');
				$(csCurrentPageElement).attr("id", "csPage" + csCount / cellStreamOptions.pageSize);
				$(csCurrentPageElement).attr("class", "csPage");
			}
			postid= $(this).attr("id");
			author = $(this).children("author").text();
			authorFirstName = $(this).children("authorFirstName").text();
			date = $(this).children("date").text();
			text = $(this).children("text").text();
			image = $(this).children("image-url").text();
			video = $(this).children("video");
			
			feedItemUri = $(this).children("feedItemUri").text();

			if(feedItemUri != null && feedItemUri.indexOf('twitter') >= 0) {
				try {
					author = text.substring(0, text.indexOf(':'));
					author= '<a target="_blank" href="http://twitter.com/' + author + '">from twitter</a>';
				} catch(err) {}
			}

			/* Generate the cell element using the data and add to Cellstream Slider */
			nodeHtml = generateCellStreamCell(author, authorFirstName, date, text, image, video, csCount, csPage,postid);
			$(csCurrentPageElement).append(nodeHtml);
			if (csPage == cellStreamOptions.pageSize - 1 || csTotalPosts == csCount + 1) {
				$(cellStreamElement).append(csCurrentPageElement)
			}
			csCount++;
		});

		
		/* Set the page count */
		cellStreamOptions.pageCount = csTotalPosts / cellStreamOptions.pageSize - 1;
		csCount = 0;
		$(cellStreamWrapper).append(cellStreamElement);
		appendPreviousNextButtons(cellStreamWrapper);
		sigElement = document.createElement('div');
		$(sigElement).attr("id", "csLogoElement");
		$(sigElement).text("powered by blastmob");		
		$(cellStreamWrapper).append(sigElement);
		
		return cellStreamWrapper;
		
}

function getXMLDOM(xml){
    if( window.ActiveXObject && window.GetObject ) {
        var dom = new ActiveXObject( 'Microsoft.XMLDOM' );
        dom.loadXML( xml );
        return dom;
    }
    if( window.DOMParser )
        return new DOMParser().parseFromString( xml, 'text/xml' );
    throw new Error( 'No XML parser available' );
}

function writeToConsole(obj){
	if(window.console && window.console.log){
		switch(typeof obj){
			case 'string': case 'integer':
				window.console.log('Eos > '+obj); break;
			default:
				window.console.log(obj); break;
		}
	}
};

$.urlParam = function(name){
	var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
	if (results == null) {
		return 0;
	}
	else {
		return results[1];
	}
}


/* Sets the maximum number of discussions to be shown with in the module.*/
var discussionsMaxItems = 5;
/*Discussion board builder*/
/* Function for the discussion boards on the ARRISTNAME */
function renderDiscussionModule(data){
	
	var discussionCount =0;
	
	xmlDom = getXMLDOM(data);
	bbcDiscussionWrapper = document.createElement('ul');
	$(bbcDiscussionWrapper).attr("id","bbcDiscussionWrapper");
	$(bbcDiscussionWrapper).attr("class","topics");
	
	var itemsFromFeed = $(xmlDom).find('item').length;
	if(itemsFromFeed <=0){
		$(bbcDiscussionWrapper).append('<span class="discussionErrorText">'+ noBBCDiscussionText + '</span>' );
	}

	$(xmlDom).find('item').each(function(){
		discussionTitle =$(this).children("title").text();
		discussionLink = $(this).children("link").text();
		discussionDescription = $(this).children("description").text();
		writeToConsole("discussion text" + discussionTitle +"end of it");
		if (discussionTitle ==""){
			discussionTitle= standinDiscussionTitle;
		}
		if (discussionCount < discussionsMaxItems) {
		
			discussionUnit = createDiscussionUnits(discussionTitle, discussionLink, discussionDescription, discussionCount);
			$(bbcDiscussionWrapper).append(discussionUnit);
			discussionCount++;
		}
	})
	
	return bbcDiscussionWrapper;
}


function createDiscussionUnits(discussionTitle,discussionLink,discussionDescription,discussionCount){
	bbcDiscussionUnit= document.createElement('li');
	$(bbcDiscussionUnit).attr("class","bbcDiscussionUnit");
	
	if((discussionCount==0)){
			$(bbcDiscussionUnit).addClass("first");
	}
	if(!(discussionCount%2)){
			$(bbcDiscussionUnit).addClass("odd");
	}	
	var discussionUnitString = '<div class="title"><h4 class="bbcTitle"><a target= "_blank" href="'+ discussionLink +'">'+ discussionTitle +'</a></h4></div><div class="bbcDescription">'+ discussionDescription +'</div>'
	$(bbcDiscussionUnit).append(discussionUnitString);	
	return $(bbcDiscussionUnit);
}

