// perform JavaScript after the document is scriptable. 
$(function() { 
	
	var fixEmbeddedVideo = function(embedCode) {
					if(embedCode && embedCode.toLowerCase().indexOf('classid') == -1) {
						var objPos = embedCode.toLowerCase().indexOf('object ') + 'object '.length;
						return embedCode.substr(0, objPos) + 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' + embedCode.substr(objPos);
					} else {
						return embedCode;
					}
				}
				
    // setup ul.tabs to work as tabs for each div directly under div.panes 
    $("ul.tabs").tabs("div.panes > div", {effect: 'fade'});

	$("#twitter-feed-goes-here").liveTwitter('608worship', {limit: 3, refresh: false, mode: 'user_timeline'});
	
	$.getFeed({url: 'http://www.southlandchristian.org/proxy/608_youtube.php',
		success: function(feed) {

			var youTubeVideo = '<object width=\"212\" height=\"178\"><param name=\"movie\" value=\"http://www.youtube.com/v/{id}\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/v/{id}\" type=\"application/x-shockwave-flash\" width=\"212\" height=\"178\"></embed></object>';
			for(var j = 0; j < feed.items.length && j < 3; j++) {
				videolink = feed.items[j].link;
				videoid = videolink.match(/v=([-\w]*)$/)[1]; // First mached element is the id
				embedCode = fixEmbeddedVideo(youTubeVideo.replace(/\{id\}/g, videoid));
				$("#youtube-feed-goes-here").append('<div style="width:212px;height:178px;margin-bottom:10px">' + embedCode + '</div>');								
			}

		}
	});
});