// JavaScript Document
function addScriptTag(id, url, callback) {
	var scriptTag = document.createElement("script");
	var noCacheIE = '&noCacheIE=' + (new Date()).getTime();
   
   // Add script object attributes
   scriptTag.setAttribute("type", "text/javascript");
   scriptTag.setAttribute("charset", "utf-8");
   scriptTag.setAttribute("src", url + "&callback=" + callback + noCacheIE);
   scriptTag.setAttribute("id", id);
	
	var head = document.getElementsByTagName("head").item(0);
	head.appendChild(scriptTag);
	
}

function getTopVideosboth() {
	//getTopVideos1();
	getTopVideos2();
}

function getTopVideos1() {
	//addScriptTag("topVideos", "http://api.brightcove.com/services/library?command=find_videos_by_tags&and_tags=fmab,catchuptaiwan&token=uOLiL3HlQh4FeSViKX7vsdOTc8n03mPVX0hvftdnx0E.&sort_by=MODIFIED_DATE&sort_order=DESC&page_size=3", "response");
}

function getTopVideos2() {
	addScriptTag("topVideos", "http://api.brightcove.com/services/library?command=find_videos_by_tags&and_tags=inutfa,catchuptaiwan&token=uOLiL3HlQh4FeSViKX7vsdOTc8n03mPVX0hvftdnx0E.&sort_by=MODIFIED_DATE&sort_order=DESC&page_size=3", "response");
}


function response(jsonData) {
	var resp = document.getElementById("resp");
	
	
	for (var i=0; i<jsonData["items"].length; i++) {
		var str = "";
		var title_link ="";
		var title = jsonData["items"][i];
		var titleRegxp = /(Brotherhood)/;
		
		if (titleRegxp.test(title.name) == true) {
			title_link = "/%E5%BF%AB%E9%BB%9E%E9%80%99%E8%A3%8F%E6%94%B6%E7%9C%8B%E6%9C%80%E6%96%B0%E4%B8%80%E9%9B%86%E7%9A%84%E9%8B%BC%E4%B9%8B%E9%8D%8A%E9%87%91%E8%A1%93%E5%B8%AB";
		}else{
			title_link = "/%E7%8A%AC%E5%A4%9C%E5%8F%89%E5%AE%8C%E7%B5%90%E7%B7%A8%E6%9C%80%E6%96%B0%E4%B8%80%E9%9B%86";
		}	
		str += '<div class="spti-row medium-thumb floater odd" style="float: left; width: 240px; height: 120px; margin: 5px;">';
		str += '<a href="'+ title_link +'">';
		str += '<span style="background: transparent url('+ title.thumbnailURL +') no-repeat scroll 49% 49%; width: 80px; height: 60px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" class="image spti-image-mask">';
		str += title.name+ '</span>';
		str += '</a>';
		str += '<div class="teaser-fields"><div class="views-field-title"><div class="field-content">';
		str += '<a href="'+ title_link +'">'; 
		str += title.name ;
		str += '</a>';
		str += '</a></div></div><div class="views-field-short-description">';
		str += '<div class="field-content">'+ title.shortDescription +'</div>';
		str += '</div></div></div>';

		resp.innerHTML += str;
	}
}

window.onload = getTopVideosboth;