// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

DD_roundies.addRule('#season_selector', '0 0 6px 6px', true); 
DD_roundies.addRule('#menu', '0 0 6px 6px', true); 
DD_roundies.addRule('a.button', '3px', true); 
DD_roundies.addRule('.commish_promo', '6px', true); 

jQuery.fn.idle = function(time){
	var i = $(this);
	i.queue(function(){
		setTimeout(function(){
			i.dequeue();
		}, time);
	});
        return this;
};


function fb_inviteFriends(league, season_id, team_name) {
        FB.Connect.requireSession( 
            function() {
                var uid = FB.Facebook.apiClient.get_session().uid;
                var fbml = fb_getInviteFBML(league, season_id, team_name) ;
                var dialog = new FB.UI.FBMLPopupDialog("Commish - Powering Social Sports Leagues Everywhere!", fbml);
                dialog.setContentWidth(650);
                //dialog.setContentHeight(450);
                dialog.show();
                $('#RES_ID_fb_pop_dialog_table').css("top", "50px");
            },
            function()  {
                //User cancelled the connect
            }
        );
} 

function fb_getInviteFBML(league, season_id, team_name) {
    var uid = FB.Facebook.apiClient.get_session().uid;
    var fbml = "";
    fbml = 
    '<fb:fbml>' +
        '<fb:request-form'+
           //Redirect back to this page
           ' action="'+ document.location +'"'+
           ' method="GET"'+
           ' invite="true"'+
           ' type="Commish Team"' +
           ' content="Hey, want to join my team? It\'s easy using Commish! Just register for the league <b>'+league+'</b> and make sure you select the team <b>'+ team_name + '</b>. That\'s it!' +
           //Callback the server with the appropriate Commish Account URL
           ' <fb:req-choice url=\'http://commi.sh/seasons/'+season_id+'\' label=\'Join my team!\' />"'+
                      '>'+
                       ' <fb:multi-friend-selector'+
                            ' rows="2"'+
                            ' cols="4"'+
                            ' max="20"'+
                            ' bypass="Cancel"'+
                            ' showborder="false"'+
                            ' actiontext="Invite your friends to join '+league+'."/>'+
                ' </fb:request-form>'+
        ' </fb:fbml>';
    return fbml;
}


function animRight(id) { 
  $(id).animate({marginLeft:"30px"}, 1000, 'swing', function(){animLeft(id);});
}

function animLeft(id) { 
  $(id).animate({marginLeft:"0px"}, 1000, 'swing', function(){animRight(id);});
}

