function init_cellstream() {
	
	//remove flicker effect on outer cells
	$('#cellstream').append('<div style="position:absolute;top:22px;left:20px;width:13px;height:200px;z-index:1"/>')
	$('#cellstream').append('<div style="position:absolute;top:22px;left:917px;width:14px;height:200px;z-index:1"/>')
	
	//rollover effect
	$('#cellstream .cell').hover(function() {
				
		$(this).addClass('active')
		lefts = [28, 159, 312, 465, 618, 738]
		$(this).animate({
			width: '174px',
			height: '228px',
			top: '8px',
			left: lefts[this.id.substring(4)] + 5
		}, 100, 'swing')
		
	}, function() { //mouseout
	
		$(this).stop()
		lefts = [20, 173, 326, 479, 632, 785]
		$(this).css({
			width: '146px',
			height: '200px',
			top: '22px',
			left: lefts[this.id.substring(4)]
		})
		$(this).removeClass('active')
	})
	
	$('#author_filter_button').click(function() {
		obj = $(this.parentNode).find('ul').show()
		execOnNextClick = function() { obj.hide() }
		return false
	})
	
	//menu
	$('#author_filter_flyout li a').click(function() {
		setAuthor(this.innerHTML)
		$('#author_filter_flyout ul').hide()
	})
		
	//click handler for paging
	$('#cellstream .previous').click(function() {
		if(globalOptions.pageNumber > 0) {
			globalOptions.pageNumber--
			getAll()
		}
	})
	
	$('#cellstream .next').click(function() {
		if(globalOptions.pageCount > globalOptions.pageNumber + 1) {
			globalOptions.pageNumber++;
			getAll()
		}
	})
	
	$('#cellstream .poweredby').hover(function() {
		$('.poweredby img').css('margin-right', '0')
	}, function() {
		$('.poweredby img').css('margin-right', '-64px')
	})
	
	getAll();
}

globalOptions = new Object()
globalOptions.blast = 'warner.cute'
globalOptions.pageSize = 6 // number of items per stream page
globalOptions.pageNumber = 0
globalOptions.pageCount - 0
globalOptions.author = '' // empty string means all
	
// retrieves XML from the blastmob server
function getAll() {
	url = '/cellStream?'
		+ '&blast=' + globalOptions.blast
		+ '&pageSize=' + globalOptions.pageSize
		+ '&pageNumber=' + globalOptions.pageNumber
	url += globalOptions.author != '' ? '&author=' + globalOptions.author : ''

	$.ajax({
		type: 'GET',
		url: url,
		dataType: 'xml',
		success: function(xml) {
			xmlDataSet = xml
			renderXML(xml)
		},
		error: function(obj, msg, ex) {
			// hide paging and filter if something is wrong
			$('#author_filter_flyout').hide()
		}
	})
}
		
//renders blast XML into posts
function renderXML(data) {
	
	postList = xmlDataSet.getElementsByTagName('postList')[0]
	globalOptions.pageCount = postList.getAttribute('pageCount') // number of pages available
	setArrows() // decides whether the arrows need to be displayed

	posts = xmlDataSet.getElementsByTagName('post') // number of posts available in this listing
		
	for(text_only_alternate = 0, i = 0; i < globalOptions.pageSize; i++) {

		if (i >= posts.length) {
			$('#cell' + i).hide()
			continue
		}
		
		resetCell(i)
		$('#cell' + i).show()

		postId	 = '';
		imageURL = '';
		postText = '';
		postInfo = '';
		
		postId = posts[i].getAttribute("id");

		photoDetailsPageSize = 8
		photoSerial = ((globalOptions.pageNumber * globalOptions.pageSize) + i + 1)
		albumPageid = Math.round(Math.ceil(photoSerial / photoDetailsPageSize))		

		try {
			imageURL = posts[i].getElementsByTagName("image")[0].firstChild.nodeValue
		} catch(err) {}
				
		try {
			postText = posts[i].getElementsByTagName("text")[0].firstChild.nodeValue			
		} catch(err) {}
		
		postAuthor = posts[i].getElementsByTagName("author")[0].firstChild.nodeValue
		postDateTime = posts[i].getElementsByTagName("date")[0].firstChild.nodeValue		
		
		if (imageURL.length > 0) {	//post has image
			tmp = imageURL.substring(imageURL.indexOf("_open") + 5)
			image_url = 'http://blastmob.com/warner/cute_open/netothumbs/198x149' + tmp
		}

		if (postText.length > 0 && imageURL.length == 0) { //text-only post
			$('#cell' + i + ' .content').addClass(text_only_alternate++ % 2 == 0 ? 'text_only' : 'text_only_alternate')
			postText = '<a href="/photoView?album=mobilestream&photo='+postId+'&albumPageid='+albumPageid+'&secAlbumPageid='+albumPageid+'&photoSerial='+photoSerial+'">'+postText+'</a>'
		}

		if(imageURL.length > 0) { //post has image
			$('#cell' + i + ' .image').empty().show().append('<a href="/photoView?album=mobilestream&photo='+postId+'&albumPageid='+albumPageid+'&secAlbumPageid='+albumPageid+'&photoSerial='+photoSerial+'"><img src="' + image_url + '"/></a>')
		}
		
		$('#cell' + i + ' .text')[0].innerHTML = postText
		$('#cell' + i + ' .user')[0].innerHTML = postAuthor + ', '
		$('#cell' + i + ' .timestamp')[0].innerHTML = simpleDate(postDateTime)
	}
}

function resetCell(cell) {
	$('#cell' + i + ' .content').removeClass('text_only').removeClass('text_only_alternate')
	$('#cell' + i + ' .image').hide()
	$('#cell' + i + ' .text').empty()
	$('#cell' + i + ' .user')[0].innerHTML = ''
	$('#cell' + i + ' .timestamp')[0].innerHTML = ''
	$('#cell' + i).hide()
}
		
//deal with left and right arrows
function setArrows() {
	$('#cellstream .previous').addClass('inactive')
	$('#cellstream .next').addClass('inactive')

	if (globalOptions.pageNumber > 0) {
		$('#cellstream .previous').removeClass('inactive')
	}
	
	if (globalOptions.pageNumber < globalOptions.pageCount - 1) {
		$('#cellstream .next').removeClass('inactive')
	}
}

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()+1) + '/' + 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'
}

function setAuthor(authorName) {

	$('#author_filter_button')[0].innerHTML = authorName;
	
	if (authorName == 'Everyone') {
		globalOptions.author = ''
	} 
	else {
		globalOptions.author = authorName;
	}
	
	for(i = 0; i < globalOptions.pageSize; i++) {
		resetCell(i);
	}
	
	globalOptions.pageNumber = 0;
	getAll();
}