/*
 * Functions for Cellstream pagination
 */

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,75,164];
var csActiveTopCoor = -35;
var csActiveHeight = 248;
var csActiveWidth = 225;
//Variables to set the co-ordinates for a normal cellstream cell. 
var csNormalTopCoor = 0;
var csNormalHeight = 180;
var csNormalWidth = 123;
var csNormalLeftCoor = [0,133,266];

//Cellstream-detail page URL prefix
var csDetailUrlPrefix = '/cellstream?id=';
/***** Tour Dates *****/
/* 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="/shows/"; 

/* 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");

renderRSSModule = function(data,format, div) {

	/* Home page: Div id of Cellstream section */	
	if($(div).attr("id") == "rss_content-367007") {
		initCellstream(div, data);
	}
	/* Concerts page: Div id of Tour dates module */
	else if (div.attr("id") == "rss_content-327532") {
		
		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-490497" ||
		 div.attr("id") == "rss_content-497798" ||
		 div.attr("id") == "rss_content-497806" ||
		 div.attr("id") == "rss_content-497814" ||
		 div.attr("id") == "rss_content-497802" ||
		 div.attr("id") == "rss_content-545846" ||
		 div.attr("id") == "rss_content-497810" ||
		 div.attr("id") == "rss_content-562739" ||
 		 div.attr("id") == "rss_content-561322") {
		 
		 var feed = new InternationalFeed(div.attr("id"), div, data, 5);
		 feed.showNextPage();
		
	}
	/* Default RSS Ingester module functionality */
	else { //if this isn't the cellstream RSS module then use the EOS default copied and pasted below
		renderRSSModuleEOS(data, format, div);
		/* Make links in twitter feed open in a new window */
		$("#rss_content-340498 h3 a").text("Follow [Artist Name]");
		$("#rss_content-340498 a").attr("target", "_new");
	}
}


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 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;	
}


/* Generate the HTML content required for the individual cells */

function generateBlastMobCellStreamCell(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>');
	}
	
	/* 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+'</div>');
	} else {
		$(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;
	
}


/* 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 events for 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();
			});
		}
	);
}


/* Make the current page visible and hide the remaining pages */
function showCSPage(pageNumber){
	$("#cellStreamSlider").children().each(function (){
		if ( $(this).attr("id") == "csPage"+pageNumber){
			$(this).fadeIn();
		}else{
			$(this).hide();
		}
	});
	setArrows();
}

/* Create the pagination buttons */
function setPreviousNextButtons(div){
	buttonWrap=document.createElement('div');
	$(buttonWrap).attr("id","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).parent(".body").siblings(".head").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+'px',
					left: csActiveLeftCoor[index] + '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 resetActiveToNormal(cell){
	className = cell.attr("class");
	index = className.substring(13); 
	cell.css({
		width: csNormalWidth+'px',
		height: csNormalHeight+'px',
		top: csNormalTopCoor+'px',
		left: csNormalLeftCoor[index]+'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')
   	}
	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('csPrevious');
	} else {
		$('#csPrevious').removeClass('csPrevious');
		$('#csPrevious').addClass('csPreviousDisabled');
	}
	if (cellStreamOptions.pageNumber < cellStreamOptions.pageCount) {
		$('#csNext').removeClass('csNextDisabled');
		$('#csNext').addClass('csNext');
	} else {
		$('#csNext').removeClass('csNext');
		$('#csNext').addClass('csNextDisabled');
	}
}

$.urlParam = function(name){
	var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
	if (results == null) {
		return 0;
	}
	else {
		return results[1];
	}
}

function createTourDateUnit(title, venueName,venueCountry,venueState, venueCity,venueLocation,buyLink, appearingWith){
		
	tourDatesUnit = document.createElement('div');
	$(tourDatesUnit).attr("class","tourDatesUnit");
	
	//create tour date unit
	tdDateUnit = document.createElement('div');
	$(tdDateUnit).attr("class","tdDateField");
	var dateInTitle = "" + title.match(/\d{1,2}\/\d{1,2}/);
	var dateString = "";
	var monthString = "";
	if(dateInTitle != null ) {
		var dateArray = dateInTitle.split("\/");
		monthString = monthNames[dateArray[0]-1];
		dateString = dateArray[1];		
	}
	
	$(tdDateUnit).append('<div class="tdMonth">'+ monthString +'</div><div class="tdDD">'+ dateString +'</div>');
	$(tourDatesUnit).append(tdDateUnit);
	
	//create tourVenueBuyWrapper	
	tourVenueBuyWrapper = document.createElement('div');
	$(tourVenueBuyWrapper).attr("class","tourVenueBuyWrapper");

	//create tour venue unit
	
	var venueInfo = "";
	if($.trim(venueCity)) {
		venueInfo = venueInfo + $.trim(venueCity) + ", ";
	}
	if($.trim(venueState)) {
		venueInfo = venueInfo + $.trim(venueState);
	} else {
		venueInfo = venueInfo + $.trim(venueCountry);
	}
	
	tdVenueField = document.createElement('div');
	$(tdVenueField).attr("class","tdVenueField");
	$(tdVenueField).append('<div class="tdVenue">' + venueInfo + ', ' + venueName + '</div>');
	if (appearingWith.replace(/\s/g,"") != ""){
		$(tdVenueField).append('<div class="tdArtistName">'+ appearingWith +'</div>');
	}
	$(tourVenueBuyWrapper).append(tdVenueField);

	//create purchase tickets unit
	if (buyLink != "" && !$.trim(appearingWith).match(/SOLD OUT$/) ){
		tdBuyLinksField = document.createElement('div');
		$(tdBuyLinksField).attr("class","tdBuyLinksField");
		$(tdBuyLinksField).append('<div class="tdBuyLinks"><a target="_blank" href="'+ buyLink +'">Purchase Tickets</a></div>');
		//$(tourVenueBuyWrapper).append(tdBuyLinksField);
		//$(tourVenueBuyWrapper).append('<div class="clear"></div>');		
		$(tourDatesUnit).append(tdBuyLinksField);
	}
	
	$(tourDatesUnit).append(tourVenueBuyWrapper);
	$(tourDatesUnit).append('<div class="clear"></div>');
	return tourDatesUnit;
}

function tourDatesBuildStructure(tdAllFlag,data){
	tourDateCount = 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 id="tdViewAll" class="tour_head"><a href="' + tdViewAllLink + '">VIEW MORE</a></div');
		}		
	}

	$(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();
		venueLocation = $(this).children("venueLocation").text();
		venueState = $(this).children("venueState").text();
		buyLink = $(this).children("buylink").text();
		appearingWith = $(this).children("appearingWith").text();
		tourDatesUnit = createTourDateUnit(title, venueName, venueCountry,venueState, venueCity,venueLocation,buyLink,appearingWith);
		$(tourDatesWrapper).append(tourDatesUnit);
		tourDateCount++;
		if (tourDateCount == tourDateLimit){
			return false;
		}
	})

	if ($(xmlDom).find('item').length <= 0){

	}else {
		if(!tdAllFlag && totalTourItems > tourDateLimit) {
			$(tourDatesWrapper).append('<div id="tdViewAll"><a href="' + tdViewAllLink + '">VIEW MORE</a></div');
		}
		if(tdAllFlag) {
			$(tourDatesUnit).addClass("lastUnit");
		}
	}
	return tourDatesWrapper;
}

/* This function is used to build CellStream module */
function cellstreamBuildStructure(data){	
		
		/* Create Wrapper and Slider */
		cellStreamWrapper = document.createElement('div');
		$(cellStreamWrapper).attr("id", "cellStreamWrapper");
		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();
			if (image != ""){
			    tmp = image.substring(image.indexOf("_open") + 5);
				image = 'http://blastmob.com/warner/paramore_open/netothumbs/198x149' + tmp;
			}
			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 = generateBlastMobCellStreamCell(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);
		sigElement = document.createElement('div');
		$(sigElement).attr("id", "csLogoElement");
		$(sigElement).text("powered by blastmob");
		$(cellStreamWrapper).append(sigElement);
		
		return cellStreamWrapper;
		
}

/* 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();
			if (image != ""){
			    tmp = image.substring(image.indexOf("_open") + 5);
				image = 'http://blastmob.com/warner/paramore_open/netothumbs/600x450' + tmp;
			}
			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;							
}

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;
		}
	}
};
