var TVS = null;
function handlePageLoad() {
        TVS = new TruveoVideoSearch('9a56227cf3f59e6e7');
        TVS.results = 5;
        TVS.attachEvent('onload', 'handleVSLoad();');
        TVS.attachEvent('onupdate', 'handleUpdate();');
        TVS.initialize();
}
function handleVSLoad() {
        TVS.getVideos('motorcycle "motorcycle" -hulu.com -cars.com');
       // TVS.results = 5;
        
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function handleUpdate() {
		var theHTML = '';
        for (var i=0; i < TVS.VideoSet.totalResultsReturned; i++) {
        		theHTML += "<div class='vid clear'>";
                theHTML += "<a class='thumbnail' href='"+TVS.VideoSet.Video[i].videoUrl+"'><img width='75' src='"+TVS.VideoSet.Video[i].thumbnailUrl+"' /></a>";
                theHTML += "<a class='title' href='"+TVS.VideoSet.Video[i].videoUrl+"'>"+TVS.VideoSet.Video[i].title+"</a>";
        		theHTML += "</div>";
                // theHTML += "<div>"+TVS.VideoSet.Video[i].videoUrl+"</div>";
                // theHTML += "<div>"+TVS.VideoSet.Video[i].thumbnailUrl+"</div>";
               //  theHTML += "<img src='"+TVS.VideoSet.Video[i].thumbnailUrl+"' />";
        }
        document.getElementById('results').innerHTML = theHTML;
}

addLoadEvent(handlePageLoad);
