google.load("feeds", "1"); 

function initialize() { 
var feed = new google.feeds.Feed("http://2mm.typepad.com/usa/atom.xml");
feed.load(function(result) {
  if (!result.error) {
    var container = document.getElementById("feed");
    for (var i = 0; i < 6; i++) {
      	var entry = result.feed.entries[i];
      	var attributes = ["title", "link", "publishedDate", "content"];
		var theString = entry.content;
		var theGoods = removeHTMLTags(theString);
		theGoods = theGoods.substr(0,240);
		var div2 = document.createElement("div");
		div2.innerHTML = "<br /><br /><a style='font-weight:bold; font-size:15px;' href='" + entry.link + "' target='_blank'>" + entry.title + "</a><br />" + "<br /><div style='line-height:15px;'>" + theGoods  + "... <a href='" + entry.link + "' target='_blank'>more</a></div><br /><span style='font-size:10px; color:#999;'>" + entry.publishedDate + "</span>";
		container.appendChild(div2);
	}
  }
});
}


/*function initialize() {
        var feedControl = new google.feeds.FeedControl();
		var container = document.getElementById("feed");
        feedControl.addFeed("http://2mm.typepad.com/usa/atom.xml");
		var div = document.createElement("div");
		feedControl.draw(div);
       	var theString = div.innerHTML;
		var theGoods = removeHTMLTags(theString);
		theGoods = theGoods.substr(0,240);
		var div2 = document.createElement("div");
		div2.innerHTML = "<br /><br /><a style='font-weight:bold; font-size:15px;' href='" + entry.link + "' target='_blank'>" + entry.title + "</a><br />" + "<br /><div style='line-height:15px;'>" + theGoods  + "... <a href='" + entry.link + "' target='_blank'>more</a></div><br /><span style='font-size:10px; color:#999;'>" + entry.publishedDate + "</span>";
		container.appendChild(div2);
      }*/



function loadNews(){
	 $.ajax({
	  type: "GET",
	  url: "news/service.php?numPosts=10",
	  dataType: "xml",
	  cache: false,
	  success: parseXml,
	  error: function(XMLHttpRequest, textStatus, errorThrown){
			handleError(XMLHttpRequest, textStatus, errorThrown);
		}
	});
}

function parseXml(xml){
	$(xml).find("article").each(function(){
		var desc= $(this).find("desc").text();
		var url= $(this).find("url").text();
		var date= $(this).find("date").text();
		var article = "<div><p>"+desc+" - <a href=\""+url+"\" target=\"_blank\">more</a></p><span>"+date+"</span></div>";		
		$('#newsFeed').append(article);
	});
}

function handleError(XMLHttpRequest, textStatus, errorThrown){
	//Provide error message
	var errorText = '<h3>There was a problem loading the page</h3>';
	errorText += '<p>XMLHttpRequest: '+XMLHttpRequest+'</p>';
	errorText += '<p>textStatus: '+textStatus+'</p>';
	errorText += '<p>errorThrown: '+errorThrown+'</p>';
	$('#newsFeed').append((errorText));
}

function removeHTMLTags(htmlString){
	if(htmlString){
	var div = document.createElement("div");
	div.innerHTML = htmlString;
	if (document.all) // IE Stuff
            {
                return div.innerText;
               
            }   
            else // Mozilla does not work with innerText
            {
                return div.textContent;
            } 
	}
}  

$(document).ready(function() {
   initialize();
   loadNews();
   theHeight = document.getElementById('thumbContainer').offsetHeight;
   numPages = Math.floor((theHeight/360)+1);	
 });

var scrollCount = 1;
var scrollDistance = 361;
var theHeight = 0;
var numPages = 0;

function scrollUp(){

var scrollAmount = -1*(scrollCount * scrollDistance);
$("#thumbContainer").animate({marginTop: scrollAmount}, 500);
scrollCount++;
	if (scrollCount > 1){
		document.getElementById('theDown').style.display = 'block';
	}else{
		document.getElementById('theDown').style.display = 'none';
	}
	if (scrollCount <= numPages){
		document.getElementById('theUp').style.display = 'none';
	}else{
		document.getElementById('theUp').style.display = 'block';
	}
}

function scrollDown(){
scrollCount--;
var scrollAmount = -1*((scrollCount - 1)*scrollDistance);
$("#thumbContainer").animate({marginTop: scrollAmount}, 500);
	if (scrollCount == 1){
		document.getElementById('theDown').style.display = 'none';
	}else{
		document.getElementById('theDown').style.display = 'block';
	}
	if (scrollCount < numPages){
		document.getElementById('theUp').style.display = 'block';
	}else{
		document.getElementById('theUp').style.display = 'none';
	}
}

function onYouTubePlayerReady(playerId) {
	ytplayer = document.getElementById("myytplayer");
}



 // functions for the api calls
function loadNewVideo(id, startSeconds) {
	if (ytplayer) {
		ytplayer.loadVideoById(id, startSeconds);
	}
}
	
