function showvideo(id){
	document.getElementById('video1').className = 'button';
	document.getElementById('video2').className = 'button';
	document.getElementById('video3').className = 'button';
	document.getElementById('video4').className = 'button';
	document.getElementById('video5').className = 'button';
	document.getElementById('video6').className = 'button';
	document.getElementById('video'+id).className = 'button-on';
	$('#video').html(videos[id]);
}

function checkbandname(){
	var bandname = document.getElementById('bandname').value;
	if (bandname!=''){ document.getElementById('wizard1').submit(); } else { return false; }
}

function checkvideo(cb){
	if (document.getElementById(cb).checked==true){
		document.getElementById(cb).checked = false;
	} else {
		document.getElementById(cb).checked = true;
	}
}

function getyoutube(bandname){
	$('#videos').html('<center><img src="'+basepath+'images/ajaxloader1.gif" /></center>');
	$.get(basepath+"ajax/getyoutube.php",{   
			band: bandname
		}, function(resp) {   
			if (resp=='0'){
				$('#videos').html('<center><br />Thats odd! No videos found. Possibly you mistyped the bands name</center>');
			} else {
				$('#helptext1').html('Please select the videos you wish to include in your bands profile');
				$('#videos').html(resp);
			}
		}
	); 
}

function getmp3s(bandname){
	$('#mp3s').html('<center><img src="'+basepath+'images/ajaxloader1.gif" /></center>');
	$.get(basepath+"ajax/getvk.php",{   
			search: bandname
		}, function(resp) {   
			if (resp==''){
				$('#mp3s').html('<center><br /><br />Thats odd! No mp3 found. But no worries, you can upload your own music</center>');
			} else {
				$('#helptext2').html('Please select the mp3s you wish to include in your bands profile');
				$('#mp3s').html(resp);
			}
		}
	); 
}

function suggestSong(band_id,artist,song,mp3){
	if (band_id && artist && song && mp3){
		$.post(basepath+"ajax/suggestsong.php",{
			band_id: band_id,
			artist: artist,
			song: song,
			mp3: mp3
		}, function(resp){
			getUpcoming();
			if (resp=='0'){
				$('#suggestdone_text').html("<h1>Error</h1><p>Unexpected error occured</p>");
			} else {
				$('#suggestdone_text').html(resp);
			}
			centerPopup('pop_suggestdone');
			loadPopup('pop_suggestdone');			
		});		
	}
}

function radioVote(radio_id,votes){
	if (radio_id && (votes==1 || votes==-1)){
		$.post(basepath+"ajax/radio_vote.php",{   
				radio_id: radio_id,
				votes: votes
		}, function(resp) {
			if (resp=='1'){
				getUpcoming();
			} else {
				$('#votedone_text').html(resp);
				centerPopup('pop_votedone');
				loadPopup('pop_votedone');	
			}
		}); 
	}
}

function searchSong(){
	var search = $('#songsuggest').val();
	if ((search) && (search!='')){
		$('#suggestions').show();
		$('#suggestions').html('<center><img src="'+basepath+'images/ajaxloader1.gif" /></center>');
		$.get(basepath+"ajax/searchsong.php",{   
		       search: search
		}, function(resp) {   
			if (resp==''){
				$('#suggestions').html('No songs found');
			} else {
				$('#suggestions').html(resp);
				$(".suggest").tipTip({"delay":0, "fadeIn":50, "defaultPoistion":"top"});
			}
		}); 
	}
}

var upcomingTimer = null

function getUpcoming(){
	if (upcomingTimer){
		window.clearTimeout(upcomingTimer);
	}
	$.get(basepath+"ajax/radio_upcoming.php",{   
			
		}, function(resp) {   
			if (resp!=$('#upcoming').html()){
				$('#upcoming').html(resp);
				$(".vote").tipTip({"delay":0, "fadeIn":50, "defaultPoistion":"top"});
				$(".star").tipTip({"delay":0, "fadeIn":50, "defaultPoistion":"top"});
				$(".star-on").tipTip({"delay":0, "fadeIn":50, "defaultPoistion":"top"});
			}
			
			upcomingTimer = window.setTimeout('getUpcoming()',20000);
		}
	); 
}



function getflickr(bandname){
	$('#images').html('<center><img src="'+basepath+'images/ajaxloader1.gif" /></center>');
	$.get(basepath+"ajax/getflickr.php",{   
			bandname: bandname
		}, function(resp) {   
			if (resp==''){
				$('#images').html('<center>Thats odd! No images found. Nevermind, upload your own images</center>');
			} else {
				$('#helptext3').html('Please select the images you wish to include in your bands profile');
				$('#images').html(resp);
			}
		}
	); 
}

function getlastfm(bandname){
	$('#lastfmloader').html('<center><img src="'+basepath+'images/ajaxloader1.gif" /></center>');
	$.get(basepath+"ajax/getlastfm.php",{   
			bandname: bandname
		}, function(resp) {   
			if (resp==''){
				$('#lastfmloader').html('<center>Nothing found on last.fm about your band</center>');
			} else {
				var resp = eval('(' + resp + ')');
				try{
					$('#bio').text(resp.bio);
					if (resp.tags){
						$('#tags').val(resp.tags);
					}
					$('#lastfmloader').html('');
				} catch(err){
					$('#lastfmloader').html('');
				}
			}
		}
	); 
}

function processband(bandid,bandname){
	$('#loader').html('<center><br /><br />Please wait while we are processing your bands details...<br />This may take a while depending on the amount of media you requested to include<br /><br /><img src="'+basepath+'images/ajaxloader1.gif" /></center>');
	$.get(basepath+"ajax/processband.php",{   
			bandname: bandname,
			bandid: bandid
		}, function(resp) {   
			$('#loader').hide();
			$('#successmessage').show();
		}
	); 
}

function popuplogin(prefix){
	$('#'+prefix+'loginloader').html('<img src="'+basepath+'images/ajaxloader2.gif" />');
	$.get(basepath+"ajax/popuplogin.php",{   
			username: $('#'+prefix+'username').val(),
			password: $('#'+prefix+'password').val()
		}, function(resp) {   
			if (resp==1){
				location.reload(true);
			} else {
				$('#'+prefix+'loginloader').html('<font color="darkred">Invalid login details</font>');
			}
		}
	);
}


function savetags(bandid){
	var tags = escape($('#newtags').val());
	$('#tagloader').html('<img src="'+basepath+'images/ajaxloader2.gif" />');
	$.get(basepath+"ajax/savetags.php",{   
			band: bandid,
			tags: tags
		}, function(resp) {
			if (resp){
				$('#tags').hide();
				if ($('#tags').html()=='This band has not tagged yet'){
					$('#tags').html(resp)
				} else {
					$('#tags').html($('#tags').html()+', '+resp);
				}
				$('#tags').fadeIn();		  
			} 
			$('#newtags').val('');
			$('#tagloader').html('');
		}
	);  
}


function befan(bandid){
	$.get(basepath+"ajax/befan.php",{   
			band: bandid
		}, function(resp) {
			if (resp){
				$('#fandiv').hide();
				$('#fandiv').html(resp);
				$('#fandiv').fadeIn();		  
			} 
		}
	); 
}

function showtitleinput(id){
	$('#v_'+id).hide();
	$('#vinput_'+id).show();
}

function savevideotitle(id){
	var newtitle = $('#newtitle_'+id).val();
	if (newtitle){
		$('#v_'+id).html(newtitle);
		$('#vinput_'+id).hide();  
		$('#v_'+id).show();
		$.get(basepath+"ajax/videotitle.php",{   
				title: escape(newtitle),
				video: id
			}, function(resp) {
			
			}
		);	
	} else {
		$('#vinput_'+id).hide();  
		$('#v_'+id).show();
	}
}

function deletevideo(id){
    $.get(basepath+"ajax/deletevideo.php",{   
			video: id
		}, function(resp) {
			if (resp=='1'){
				$('#videobox_'+id).fadeOut('fast');
			}
		}
	);	
}

function deleteimage(id){
	$.get(basepath+"ajax/deleteimage.php",{   
			imageid: id
		}, function(resp) {
			if (resp=='1'){
				$('#imgbox'+id).fadeOut('fast');
			} else { 
				alert(resp); 
			}
		}
	);	
}

function deleteaudio(id){
	$.get(basepath+"ajax/deleteaudio.php",{   
			audioid: id
		}, function(resp) {
			if (resp=='1'){
				$('#audiobox'+id).fadeOut('fast');
			}
		}
	);	
}

function saveaudiotitle(id){
	var newtitle = $('#audiotitle'+id).val();
	if (newtitle){
		$('#updatebutton'+id).val('Saving...');
		$.get(basepath+"ajax/updateaudio.php",{   
				audioid: id,
				newtitle: escape(newtitle)
			}, function(resp) {
				$('#updatebutton'+id).val('Save');
			}
		);		
	}
}

function popupyoutube(bandname){
	$('#videos').html('<center><img src="'+basepath+'images/ajaxloader1.gif" /></center>');
	$.get(basepath+"ajax/getyoutube.php",{   
			band: bandname
		}, function(resp) {   
			if (resp=='0'){
				$('#videos').html('<center><br />Your query returned no results</center>');
			} else {
				$('#videos').html(resp);
			}
		}
	); 
}

function getcomments(bandid){
	$.get(basepath+"ajax/getcomments.php",{   
			band: bandid
		}, function(resp) {   
			$('#comments').hide();
			$('#comments').html(resp);
			$('#comments').fadeIn('fast');
		}
	); 
}

function addcomment(bandid){
	var comment = $('#newcomment').val();
	if (comment){
		$('#commentloader').html('<center><img src="'+basepath+'images/ajaxloader2.gif" /></center>');
		$.get(basepath+"ajax/addcomment.php",{   
				band: bandid,
				comment: escape(comment)
			}, function(resp) {   
				$('#newcomment').val('');
				$('#commentloader').html('');
				getcomments(bandid);
			}
		); 
	}
}

function setStatus(userid){
	var status = $('#newcomment').val();
	if (status){
		$('#commentloader').html('<center><img src="'+basepath+'images/ajaxloader2.gif" /></center>');
		$.get(basepath+"ajax/setstatus.php",{   
				status: escape(status)
			}, function(resp) {   
				$('#newcomment').val('');
				$('#commentloader').html('');
				getUserActivity(userid,0);
			}
		); 
	}
}

function getactivity(bandid){
	$.get(basepath+"ajax/getactivity.php",{  
			band: bandid
		}, function(resp) {   
			$('#activity').hide();
			$('#activity').html(resp);
			$('#activity').fadeIn('fast');
		}
	); 
}

function getbands(page,perpage){
	$('#bands').html('<center><br /><img src="'+basepath+'images/ajaxloader1.gif" /><br /><br /></center>');
	$.get(basepath+"ajax/getbands.php",{  
			page: page,
			perpage: perpage
		}, function(resp) {   
			$('#bands').html(resp);
		}
	); 
}

function getpopular(page,perpage){
	$('#bands').html('<center><br /><img src="'+basepath+'images/ajaxloader1.gif" /><br /><br /></center>');
	$.get(basepath+"ajax/getpopular.php",{  
			page: page,
			perpage: perpage
		}, function(resp) {   
			$('#bands').html(resp);
		}
	); 
}

function library(){
	id = 'add_library';
	centerPopup(id);
	loadPopup(id);
}

function addlibrary(bandid){
	$('#library').hide();
	$('#library_loader').show();
	$('#library_loader').html('<center><br /><img src="'+basepath+'images/ajaxloader3.gif" /><br /><br /></center>');
  
	var toadd = '';
	$('.library_audios').each(function(){
		if ($(this).attr('checked')){
			toadd+=$(this).val()+',';
		}
	});
	$.get(basepath+"ajax/addlibrary.php",{  
			toadd: toadd,
			bandid: bandid
		}, function(resp) {   
			$('#library_loader').html(resp);
		}
	);   
}

function saveesnips(bandid){
	var todownload = '';
	$('.esnipscheckbox').each(function(){
		if ($(this).attr('checked')){
			todownload+=$(this).val()+",";
		}
	});
	todownload = escape(todownload);
	$('#esnips').html('<center><br /><br />Please wait... This may take a while<br /><br /><img src="'+basepath+'images/ajaxloader3.gif" /></center>');
	$.get(basepath+"ajax/saveesnips.php",{   
			band: bandid,
			todownload: todownload
		}, function(resp) {  
			$('#esnips').html(resp);
			window.location = window.location;
		}
	);  
}

function popupesnips(bandname,bandid){
	$('#esnips').html('<center><br /><br /><img src="'+basepath+'images/ajaxloader3.gif" /></center>');
	$.get(basepath+"ajax/getvk.php",{   
			search: bandname,
			popup: 1
		}, function(resp) {   
			if (resp==''){
				$('#esnips').html('<center><br /><br />Your query returned no results.<br /> Please try again with a different search term</center><br /><br />');
			} else {
				$('#esnips').html(resp);
				$('#esnips').html($('#esnips').html()+"<input type='button' class='submit' value='Add selected' onclick='saveesnips("+bandid+")' style='float:right;margin-top: 8px;' />");
				centerPopup('pop_music');
			}
		}
	); 
}

function saveflickr(bandid){
	var todownload = '';
	$('.flickrcheckbox').each(function(){
		if ($(this).attr('checked')){
			todownload+=$(this).val()+",";
		}
	});
	todownload = escape(todownload);
	$('#flickr').html('<center><br /><br />Please wait... This may take a while<br /><br /><img src="'+basepath+'images/ajaxloader3.gif" /></center>');
	$.get(basepath+"ajax/saveflickr.php",{   
			band: bandid,
			todownload: todownload
		}, function(resp) {  
			$('#flickr').html(resp);
			window.location = window.location;
		}
	);  
}

function popupflickr(bandname,bandid){
	$('#flickr').html('<center><br /><br /><img src="'+basepath+'images/ajaxloader3.gif" /></center>');
	$.get(basepath+"ajax/getflickr.php",{   
			bandname: bandname,
			popup: 1
		}, function(resp) {   
			if (resp==''){
				$('#flickr').html('<center><br /><br />Your query returned no results.<br /> Please try again with a different search term</center><br /><br />');
			} else {
				$('#flickr').html(resp);
				$('#flickr').html($('#flickr').html()+"<br style='clear:both;' /><input type='button' class='submit' value='Add selected' onclick='saveflickr("+bandid+")' style='float:right;margin-top: 8px; margin-right: 7px;' />");
				centerPopup('pop_images');
			}
		}
	); 
}


function deleteLibrary(id){
    $.get(basepath+"ajax/deletelibrary.php",{   
			library: id
		}, function(resp) {
			$('#row'+id).fadeOut('fast');
			$('#row'+id).remove();
		}
	);	
	return false;
}

function getUserActivity(userid,loader){
	if (loader){
		$('#useractivity').html('<center><br /><img src="'+basepath+'images/ajaxloader1.gif" /></center>');
	}
	$.get(basepath+"ajax/getuseractivity.php",{   
			user: userid
		}, function(resp) {   
			if (resp!=$('#useractivity').html()){
				$('#useractivity').html(resp);
			} 
		}
	); 
	setTimeout('getUserActivity('+userid+',0)',60000);
}

function friendrequest(userid,send){
	if (!send){
		id = 'friendrequest';
		centerPopup(id);
		loadPopup(id);
	  
		$('#friendrequest_content').html('<center><br /><img src="'+basepath+'images/ajaxloader3.gif" /></center>');
		$.post(basepath+"ajax/friendrequest.php",{   
				userid: userid,
				submit: 0
			}, function(resp) {   
				$('#friendrequest_content').html(resp);
			}
		);  
	} else {
		$('#friendrequest_content').html('<center><br /><img src="'+basepath+'images/ajaxloader3.gif" /></center>');
		$.post(basepath+"ajax/friendrequest.php",{   
			   userid: userid,
			   submit: 1
			}, function(resp) {   
				$('#friendrequest_content').html(resp);
			}
		);  	
	} 
}

function lastfmsearch(lastfmid){
	if (lastfmid){
		$('#lastfmsearch_results').html('<center><br />Please wait...searching for bands<br />This may take a while<br /><br /><img src="'+basepath+'images/ajaxloader3.gif" /></center>');
		$.post(basepath+"ajax/lastfmsearch.php",{   
				lastfmid: lastfmid
			}, function(resp) {   
				$('#lastfmsearch_results').html(resp);
			}
		); 	
	}
}

function challenge(bandid,doit){
	if (bandid){
		if (!doit){
			id = 'war_popup';
			centerPopup(id);
			loadPopup(id);  
			$('#war_content').html('<center><br /><br /><img src="'+basepath+'images/ajaxloader3.gif" /></center>');
			$.post(basepath+"ajax/challenge.php",{   
					bandid: bandid
				}, function(resp) {   
					$('#war_content').html(resp);
				}
			); 
		} else {
			var challenger = document.getElementById('challenger').options[document.getElementById('challenger').selectedIndex].value;
			$('#war_content').html('<center><br /><br /><img src="'+basepath+'images/ajaxloader3.gif" /></center>');
			$.post(basepath+"ajax/challenge.php",{   
					bandid: bandid,
					challenger: challenger
				}, function(resp) {   
					$('#war_content').html(resp);
				}
			);
		}
	}
}

function featureband(bandid,doit){
	if (!doit){
		id = 'pop_deleteband';
		centerPopup(id);
		loadPopup(id);  
		$('#deletecontent').html("<center><br />Are you sure you want to feature this band?<br /><br /><input type='button' class='submit' value='Yeah, sure' onclick='featureband("+bandid+",1);' /></center>");
	} else {
		$('#deletecontent').html('<center><br /><img src="'+basepath+'images/ajaxloader3.gif" /><br /></center>');
		$.post(basepath+"ajax/featureband.php",{   
			bandid: bandid,
		}, function(resp) {   
			$('#deletecontent').html(resp);
		});	  
	}
}


function deleteband(bandid,doit){
	if (!doit){
		id = 'pop_deleteband';
		centerPopup(id);
		loadPopup(id);  
		$('#deletecontent').html("<center><br />Are you sure you want to delete this band?<br /><br /><input type='button' class='submit' value='Yeah, sure' onclick='deleteband("+bandid+",1);' /></center>");
	} else {
		$('#deletecontent').html('<center><br /><img src="'+basepath+'images/ajaxloader3.gif" /><br /></center>');
		$.post(basepath+"ajax/deleteband.php",{   
				bandid: bandid,
			}, function(resp) {   
				$('#deletecontent').html(resp);
			}
		);	  
	}
}

function dologin(){
	$('#twitterbutton').attr("src",basepath+'/images/twitterlogin_loading.png');
	$('#twitter_small').html("<img src='"+basepath+"/images/ajaxloader4.gif' />");
	$.post(basepath+"ajax/twitter_login.php",{  }, 
		function(resp) {   
			window.location = resp;
		}
  );  

}

function inviteTwitterLogin(){
	$('#twitterbutton').attr("src",basepath+'/images/twitterlogin_loading.png');
	$('#twitter_small').html("<img src='"+basepath+"/images/ajaxloader4.gif' />");
	$.post(basepath+"ajax/twitter_login.php",{ redirect:1  }, 
		function(resp) {   
			window.location = resp;
		}
	);  
}

function vote(warid,band){
	$.post(basepath+"ajax/vote.php",{   
		   warid: warid,
		   band: band
		}, function(resp) {
		  if (resp){
			ret = eval('('+resp+')');
			$('#votes1').hide();
			$('#votes2').hide();
			$('#vote1').html(ret.votes1);
			$('#vote2').html(ret.votes2);
			$('#votes1').fadeIn('fast');
			$('#votes2').fadeIn('fast');
			getVotes(warid,1);
			getVotes(warid,2);
		  }
		}
	); 
}

function getVotes(warid,band){
	$.post(basepath+"ajax/getvotes.php",{   
		   warid: warid,
		   band: band
		}, function(resp) {   
			$('#whovoted'+band).html(resp);
		}
	); 
}


function facebookLogin(){
	FB.getLoginStatus(function(response){
		$.post(basepath+"ajax/facebook_login.php",{   
				access_token: response.session.access_token,
				expires: response.session.expires,	
				secret: response.session.secret,
				session_key: response.session.session_key,
				sig: response.session.sig,
				uid: response.session.uid
			}, function(resp) {   
			
				if (resp=='0'){
				  alert("Unexpected error occured during connecting to facebook. Please refresh the page and try again");
				} else if (resp=='1'){
				  window.location = basepath;
				} else if (resp=='2'){
				  window.location = basepath+'facebook_registration.html';
				} else if (resp=='3'){
				  window.location = window.location;
				}
			}
		);
	}); 
}
function getGmail(){
	$('#gmailbutton').val('Loading...');
	$.post(basepath+"ajax/getgmail.php",{   
		   gusername: $('#gusername').val(),
		   gpassword: $('#gpassword').val()
		}, function(resp) {   
			if (resp=='0'){
			  $('#gmailerror').text('Invalid login details');
			  $('#gmailerror').show();
			} else {
			  
			  $('#gmail_results').html(resp);
			  $('#gmail_init').hide();
			  $('#gmail_results').show();
			}
			$('#gmailbutton').val('Get contacts');
		}
	);   
}

function sendGmail(){
	var recipients = '';
	$('.gmailcheckbox').each(function(){
		if ($(this).attr("checked")){
			recipients+=$(this).val()+",";
		}
	}); 
	if (recipients!=''){
		var invitetext = $('#invitetext').val();
		$('#gmail_results').html('<center><br /><br /><br />Sending out invitations<br />This may take a while<br /><br /><img src="'+basepath+'images/ajaxloader3.gif" /></center>');
		$.post(basepath+"ajax/sendgmail.php",{   
			   recipients: recipients,
			   invitetext: escape(invitetext)
			}, function(resp) {   
				if (resp=='0'){
				  alert("Your session timed out. Please log in again");
				  window.location = basepath;
				} else {
				  $('#gmail_results').html(resp);
				}
			}
		);      
	} else {
		alert("Please select at least one recipient");
	}
}

var gselected = 0;
function selectGmail(){
	if (!gselected){
		$('.gmailcheckbox').attr("checked",true);
		$('#gmailselectbutton').val("Deselect all");
		gselected=1;
	} else {
		$('.gmailcheckbox').attr("checked",false);
		$('#gmailselectbutton').val("Select all");  
		gselected=0;
	}
}

var tselected = 0;
function selectTwitter(){
	if (!tselected){
		$('.twittercheckbox').attr("checked",true);
		$('#twitterselectall').val("Deselect all");
		tselected=1;
	} else {
		$('.twittercheckbox').attr("checked",false);
		$('#twitterselectall').val("Select all");  
		tselected=0;
	}
}

function sendTwitterDM(){
	var recipients ='';
	var invitetext = $('#twitter_invitetext').val();
	$('.twittercheckbox').each(function(){
		if ($(this).attr("checked")){
			recipients+=$(this).val()+",";
		}
	});
	
	if (recipients==''){
		alert("Please select at least one recipients");
	} else {
		if (invitetext==''){
			alert("Please enter your message");
		} else {
			$('#twitter_invite').html('<center><br /><br /><br />Sending your invitations<br />It may take a while. Please wait...<br /><br /><img src="'+basepath+'images/ajaxloader3.gif" /></center>');
			$.post(basepath+"ajax/sendtwitterdm.php",{   
					recipients: recipients,
					invitetext: invitetext
				}, function(resp) {   

					  $('#twitter_invite').html(resp);

				}
			); 
		}
	}

}

function getTwitterFriends(){
	$('#twitter_invite').html('<center><br /><br /><br />Getting your Twitter friends<br />It may take a while. Please wait...<br /><br /><img src="'+basepath+'images/ajaxloader3.gif" /></center>');
	$.post(basepath+"ajax/gettwitterfriends.php",{   

		}, function(resp) {   
			if (resp=='0'){
			  alert("Your session timed out. Please log in again");
			  window.location = basepath;
			} else {
			  $('#twitter_invite').html(resp);
			}
		}
	);  
}

function trackAudio(id){
	$.post(basepath+"ajax/trackaudio.php",{   
		   id: id
		}, function(resp) {
		  if (resp){
			//alert(resp);
		  }
		}
	); 
}

function trackVideo(id){
	$.post(basepath+"ajax/trackvideo.php",{   
		   id: id
		}, function(resp) {
		  if (resp){
			//alert(resp);
		  }
		}
	); 
}

var nowplayingTimer = null;

function nowPlaying(){
	if (nowplayingTimer){
		window.clearTimeout(nowplayingTimer);
	}
	$.get(basepath+"ajax/radio_nowplaying.php",{   
		   
		}, function(resp) {
			$('#nowplaying').html(resp);
			nowplayingTimer = setTimeout('nowPlaying()',10000);
		}
	); 
}

function checkFacebook(){
    FB.getLoginStatus(function(r){
        if(r.session){
			facebookLogin();
        } else{
			FB.login(facebookLogin);
		}
    });
}

function facebookDoLogin(){
	if (typeof FB != 'undefined'){
		FB.getLoginStatus(function(response){
			if (response.session){
				
				facebookLogin();
			} else {
				FB.login();
			}
		});
	}
	return false;
}

function librarySong(star_id,artist,track,band_id,mp3){
	$.post(basepath+"ajax/library_song.php",{   
		   	artist:artist,
		   	track:track,
		   	band_id:band_id,
		   	mp3: mp3
		}, function(resp) {
			if ((resp!='1') && (resp!='0')){
				$('#suggestdone_text').html(resp);
				centerPopup('pop_suggestdone');
				loadPopup('pop_suggestdone');
			} else if (resp=='1') {
				$('#star'+star_id).removeClass("star").addClass("star-on");
			} else if (resp=='0') {
				$('#star'+star_id).removeClass("star-on").addClass("star");
			}

			
		}
	); 
}

function statusPoupup(link,band_name,message,image){
	FB.ui({
		 method: 'feed',
		 name: band_name+' on Bandwars.org',
		 link: link,
		 caption: band_name,
		 picture: image,
		 message: message
		},
		function(response) {
			if (response && response.post_id) {
				//alert('Post was published.');
			} else {
				//alert('Post was not published.');
			}
		}
	 );
}
