/* player.js */

function SelectEpisode(elm, media, duration, poster)
{
	var Obj = jQuery(elm);
	jQuery('#mediacontent h3').html( Obj.attr('title') );
	jQuery('#rvg_player_1').rvplayerSet( media, duration, poster );
	jQuery('#mediacontent .nowplaying_download a').attr('href', media);
	jQuery('#mediacontent .nowplaying_share a').attr('href', Obj.attr('href'));
	jQuery('#mediacontent .nowplaying_share a').attr('title', Obj.attr('title'));
	//alert(Obj.attr('title'));
	jQuery('#mediacontent .nowplaying_more a').attr('href', Obj.attr('href'));
	jQuery('#mediacontent .nowplaying_more a').attr('title', Obj.attr('title'));
	jQuery('#mediacontent .nowplaying_mycast a').attr('href', Obj.attr('href'));
	jQuery('#mediacontent .nowplaying_mycast a').attr('title', Obj.attr('title'));
	if( SelectEpisode.arguments.length > 4 && SelectEpisode.arguments[4] ) // Auto play
	{
		jQuery('#rvg_player_1').rvplayerPlay();
		jQuery('html').animate({scrollTop:0}, 2000); // Scroll to top where player is located
	}
}

var g_GooglePlus = false;
function SetShareOptions(url, title)
{
	var msg = encodeURIComponent( title + ' ' + url );
	var siteTitle = document.title.substring(0, document.title.indexOf(' -'));
	// jQuery('#log').prepend('<div>'+ url +' '+ title +'</div>');
	var html = '<h2>Share This Podcast</h2>';
	html += '<ul>';
		html += '<li><a href="http://twitter.com/home?status='+ msg +'" class="twitter" title="Twitter" target="_blank">Twitter</a></li>';
		html += '<li><a href="http://www.facebook.com/share.php?u='+ encodeURIComponent(url) +'&amp;t='+ encodeURIComponent(title) +'" class="facebook" title="Facebook" target="_blank">Facebook</a></li>';
		html += '<li style="margin-left: 6px;"><g:plusone size="small" annotation="none" href="'+ encodeURIComponent(url) +'"> </g:plusone> Google+</li>';
		
		html += '<li><a href="http://digg.com/submit?phase=2&url='+ encodeURIComponent(url) +'" class="digg" title="Digg" target="_blank">Digg</a></li>';
		html += '<li><a href="http://del.icio.us/post?url='+ encodeURIComponent(url) +'" class="delicious" title="Delicious" target="_blank">Delicious</a></li>';
		html += '<li><a href="http://www.linkedin.com/shareArticle?mini=true&url='+ encodeURIComponent(url) +'&amp;title='+ encodeURIComponent(title) +'&amp;source='+ encodeURIComponent(siteTitle) +'" class="linkedin" title="LinkedIn" target="_blank">LinkedIn</a></li>';
		html += '<li><a href="http://www.myspace.com/Modules/PostTo/Pages/?u='+ encodeURIComponent(url) +'" class="myspace" title="MySpace" target="_blank">MySpace</a></li>';
		// message=Here's%20Buzz!&url=http://www.google.com/buzz

		//html += '<li><a href="http://www.google.com/buzz/post?url='+ encodeURIComponent(url) +'&amp;message='+ encodeURIComponent(title) +'" class="google_buzz" title="Google Buzz" target="_blank">Google Buzz</a></li>';
		
		html += '<li><a href="mailto:?subject='+ encodeURIComponent(title) +'&amp;body='+ encodeURIComponent('Link: '+url) +'" class="email" title="Email" target="_blank">Email</a></li>';
		
	html += '</ul>';
	jQuery('#mediacontent .nowplaying_share .nowplaying_share_popup').html(html);
	
	//if( !g_GooglePlus )
	{
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
		g_GooglePlus = true;
  }
	gapi.plusone.go();

	
}

function SetMyCastOptions(url)
{
	var html = '<h2>Your Personal MyCast &reg;</h2>';
  if (document.cookie.indexOf("RVSESSID=")==-1) {
		html += '<p>You must be signed in to add this podcast to your MyCast&reg; subscription.</p>';
		html += '<p><a href="/signin.php" title="Sign In">Sign In</a> | <a href="/createaccount.php" title="Create Account">Create Account</a> | <a href="/about_mycast/" title="What is MyCast">What is MyCast?</a></p>';
		//html += '<p><a href="/mycast.php" title="MyCast">Go to MyCast</a></p>';
	} else {
	
		jQuery.get(url, { ajax: "1", mycast: "1" },
		 function(data){
			 jQuery('#mediacontent .nowplaying_mycast .nowplaying_mycast_popup').html( data );
			 jQuery('#mediacontent .mycast_add_button').click(function(e) {
				jQuery.get(url, { ajax: "1", mycast: "1", add: "1" },
					function(data){
						jQuery('#mediacontent .nowplaying_mycast .nowplaying_mycast_popup').html( data );
					});
			});
			jQuery('#mediacontent .mycast_remove_button').click(function(e) {
				jQuery.get(url, { ajax: "1", mycast: "1", remove: "1" },
					function(data){
						jQuery('#mediacontent .nowplaying_mycast .nowplaying_mycast_popup').html( data );
					});
			});
		 });
		html += '<p>Loading...</p>';
		jQuery('#log').prepend('<div>Signed in</div>');
	}
	// alert('MyCast check URL: '+url);
	jQuery('#mediacontent .nowplaying_mycast .nowplaying_mycast_popup').html(html);
}

function AddMyCast(url)
{
	jQuery.get(url, { ajax: "1", mycast: "1", add: "1" },
	 function(data){
		 jQuery('#mediacontent .nowplaying_mycast .nowplaying_mycast_popup').html( data );
	 });
}

function RemoveMyCast(url)
{
	jQuery.get(url, { ajax: "1", mycast: "1", remove: "1" },
	 function(data){
		 jQuery('#mediacontent .nowplaying_mycast .nowplaying_mycast_popup').html( data );
	 });
}

