/**
@author djjeck
*/

(function($){
	if($ == undefined)
		; //TODO

	if(window.Blacktrend == undefined)
		window.Blacktrend = {};
	
	if(Blacktrend.util == undefined)
		Blacktrend.util = (function() {
			// private
			
			// public
			return {
				replaceFacebookLikes: function() {
					$('a.facebook_like').replaceWith(function() {
						return '<div class="facebook_like"><iframe '+
						'src="http://www.facebook.com/plugins/like.php?href='+
						encodeURIComponent($(this).attr('href'))+
						'&amp;layout=button_count&amp;show_faces=true&amp;width=190&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=21" '+
						'scrolling="no" frameborder="0" allowTransparency="true" '+
						'style="border:none; overflow:hidden; width:190px; height:21px;">'+
						'</iframe></div>';
					});
				},
				
				placeYoutubeEmbed: function(container_id, youtube_id) {
					$('#'+container_id).empty().append(Blacktrend.util.createYoutubeEmbed(youtube_id));
				},
				
				createYoutubeEmbed: function(id) {
					return '<object width="640" height="385">'+
							'<param name="movie" value="http://www.youtube.com/v/'+
							id+
							'?fs=1&amp;hl=en_US&amp;rel=0&amp;hd=1&amp;color1=0x3a3a3a&amp;color2=0x999999"></param>'+
							'<param name="allowFullScreen" value="true"></param>'+
							'<param name="allowscriptaccess" value="always"></param>'+
							'<embed '+
							'src="http://www.youtube.com/v/'+
							id+
							'?fs=1&amp;hl=en_US&amp;rel=0&amp;hd=1&amp;color1=0x3a3a3a&amp;color2=0x999999" '+
							'type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed>'+
						'</object>';
				},
				
				placeCasellaVocaleEmbed: function(filename) {
					$('#casella_vocale__flash_container').empty();
					swfobject.embedSWF(
						'/streams/micAs3.swf',
						'casella_vocale__flash_container',
						330,
						175,
						'9.0.0',
						false,
						{ filename: filename },
						{ wmode: 'transparent' });
				},
				
				refreshCasellaVocaleList: function() {
					$.ajax({
						url: 'actions.php',
						data: 'method=casella_vocale',
						type: 'GET',
						dataType: 'json',
						success: function(response) {
							$('#casella_vocale .clips').empty();
							response.clips.forEach(function(clip, i) {
								var date = new Date(parseInt(clip['timestamp'])*1000);
								
								var item = $('<a href="/streams/'+clip['filename']+'.flv" id="clip_'+i+'" class="clip" />'). //TODO remove / from clip path
									//append('<span class="icon">&gt;</span> ').
									append('<span class="name">'+clip['name']+'</span>, ').
									append('<span class="job">'+clip['iama']+'</span> ').
									append('<span class="date">'+date.getDate()+'-'+(date.getMonth()+1)+'-'+date.getFullYear()+'</span>').
									appendTo('#casella_vocale .clips');								
							});
						}
					});
				}
			};
		})();
})(jQuery);
