function init_photoblast() {

	//rollover effect
	$('#photoblast .post').hover(function() {

		if(!$('#photoblast .post').hasClass('active')){
			$(this).addClass('active')
			lefts = [16, 165, 314, 463, 612]
			$(this).animate({
				width: '195px',
				height: '213px',
				top: '-17px',
				left: lefts[this.id.substring(4)] - 20
			}, 100, 'swing')
			// for video player
			if ($(this).find('div.player').is('*') != ''){
				$(this).find(' .video').show()
				$(this).find(' .image').hide()
				if ($('#photoblast_player').is('*')) {
					$('#photoblast_player').css({ position: 'absolute', top: '390px', width: '149px', zIndex: '100', left: lefts[this.id.substring(4)] + 25})
					$('#photoblast_close_button').css({ position: 'absolute', top: '377px', width: '149px', zIndex: '100', left: lefts[this.id.substring(4)] + 210})
					var swf = new SWFObject("http://64.124.176.198/flash/flvplayer.swf","player","198","149","7");
					swf.addParam("allowfullscreen","true");
					swf.addVariable("file","http://64.124.176.198/p/uploads/0123081004-00.3gp.flv");
					swf.addVariable("image","http://64.124.176.198/p/uploads/0123081004-00.3gp.jpg");
					swf.addVariable("backcolor","0x000000");
					swf.addVariable("frontcolor","0xCCCCCC");
					swf.addVariable("lightcolor","0xddffff");
					swf.addVariable("overstretch","true");
					swf.addParam('allowscriptaccess','always');
					swf.addVariable('javascriptid','photoblast_swf');
					swf.addVariable('enablejs','true');
					swf.write("photoblast_player");
					$('#photoblast_close_button').show()
					$('#photoblast_player').show()
				}else {
					//we should be using the existing player instead of inserting a new one
				}
			}
		}
	}, function() { //mouseout
		// put something here to handle closing video player
		if (!$(this).find('div.player').is('*')) {;}
			$(this).stop()
			lefts = [16, 165, 314, 463, 612]
			$(this).css({
				width: '142px',
				height: '189px',
				top: '0px',
				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
	}, function() { //mouseout
		if (!$(this).find('div.player').is('*')) {
			$(this).stop()
			lefts = [16, 165, 314, 463, 612]
			$(this).css({
				width: '142px',
				height: '215px',
				top: '5px',
				left: lefts[this.id.substring(4)]
			})
			$(this).removeClass('active')
		}
	})

	$('#photoblast_close_button').click(function() {
		$('#photoblast_player_button').hide()
		$('#photoblast_player').hide()
		active_post = $('.active')
		console.log(active_post)
		active_post.stop()
		lefts = [16, 165, 314, 463, 612]
			active_post.css({
				width: '142px',
				height: '215px',
				top: '5px',
				left: lefts[active_post[0].id.substring(4)]
			})
		active_post.removeClass('active')
		active_post.find(' .video').hide()
		active_post.find(' .image').show()
		active_post.find(' .text').show()
		$('#photoblast_player').empty()
	})


	//menu
	$('#author_filter_flyout li a').click(function() {
		setAuthor(this.innerHTML)
		$('#author_filter_flyout ul').hide()
	})

	//click handler for paging
	$('#photoblast_paging #previous').click(function() {
		if(globalOptions.pageNumber > 0) {
			globalOptions.pageNumber--
			getAll()
		}
	})

	$('#photoblast_paging #next').click(function() {
		if(globalOptions.pageCount > globalOptions.pageNumber + 1) {
			globalOptions.pageNumber++;
			getAll()
		}
	})

	$('#photoblast .poweredby').hover(function() {
		$('.poweredby img').css('margin-right', '0')
	}, function() {
		$('.poweredby img').css('margin-right', '-64px')
	})

	getAll();
}

globalOptions = new Object()
globalOptions.blast = 'zomba.dares'
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 = 'photoblast.php?pageNumber='+globalOptions.pageNumber+'&r='+Math.random();
	
	$.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
			$('#photoblast_paging').hide()
			$('#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) {
			$('#post' + i).hide()
			continue
		}

		resetCell(i)
		$('#post' + i).show()

		imageURL = '';
		postText = '';
		postInfo = '';

		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("authorFirstName")[0].firstChild.nodeValue
		postDateTime = posts[i].getElementsByTagName("date")[0].firstChild.nodeValue

		if (imageURL.length > 0) {	//post has image
			image_url = imageURL;
		}

		if (postText.length > 0 && imageURL.length == 0) { //text-only post
			$('#post' + i + ' .content').addClass(text_only_alternate++ % 2 == 0 ? 'text_only' : 'text_only_alternate')
		}

		if(imageURL.length > 0) { //post has image
			$('#post' + i + ' .image').empty().show().append('<img src="' + image_url + '"/>')
		}

		$('#post' + i + ' .text')[0].innerHTML = postText
		$('#post' + i + ' .user')[0].innerHTML = postAuthor
		$('#post' + i + ' .timestamp')[0].innerHTML = simpleDate(postDateTime)
	}
}

function resetCell(post) {
	$('#post' + i + ' .content').removeClass('text_only').removeClass('text_only_alternate')
	$('#post' + i + ' .image').hide()
	$('#post' + i + ' .text').empty()

	$('#post' + i + ' .user')[0].innerHTML = ''
	$('#post' + i + ' .timestamp')[0].innerHTML = ''
	$('#post' + i).hide()
}

//deal with left and right arrows
function setArrows() {
	$('#photoblast_paging .previous').hide()
	$('#photoblast_paging .next').hide()

	if (globalOptions.pageNumber > 0) {
		$('#photoblast_paging .previous').show()
	}

		if (globalOptions.pageNumber < globalOptions.pageCount - 1) {
		$('#photoblast_paging .next').show()
	}
}

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.getFullYear())
	}

	//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 == 'all') {
		globalOptions.author = ''
	}
	else {
		globalOptions.author = authorName;
	}

	for(i = 0; i < globalOptions.pageSize; i++) {
		resetCell(i);
	}

	globalOptions.pageNumber = 0;
	getAll();
}