/**
 *
 *   General F1 Fast Scripts 
 *
 */   
jQuery(document).ready(function(){

    jQuery('table.tabular tr:odd').css({ background: '#eeeeee', color: '#333333' });

    // Handle horizontal menu dropdowns
    jQuery('#menu li').hover(
        function(){ jQuery('ul', this).css('display', 'block'); 
                    jQuery(this).addClass('current'); },
        function(){ jQuery('ul', this).css('display', 'none'); 
                    jQuery(this).removeClass('current'); 
    });
    
    //Menu Highlighting!
    var body = jQuery("body").attr("id");
    jQuery("#menu li#tab_"+body).addClass("selected");
	

    if(typeof document.body.style.maxHeight == "undefined") {
        DD_belatedPNG.fix('#pitchdiv #players ul li a img');
    } 
	
    jQuery('.icons').css({backgroundColor: '#cccccc'});

    if( feedUrl != null ) {
        if(jQuery.jGFeed){
            jQuery.jGFeed(feedUrl,
            function(feeds){
                if(!feeds){
                    return false;
                }
             
                for(var i=0; i<3; i++){
                    var entry = feeds.entries[i];
                    jQuery("#rss ul").append("<li><a href="+entry.link+">"+entry.title+"</a><br />"+entry.contentSnippet+"<br /><small>"+entry.publishedDate+"</small></li>");
                }
            }, 10);

            jQuery('.bottom a').attr('href', feedUrl);
        }

    }
     


    //team screen points box events

    //load the points
    jQuery('.total').text(jQuery('.total_pts').text())

    //hide the points on hover over a driver
    jQuery('.player').hover(function() {

        jQuery('.total').hide();
    	
    }, function() {

        jQuery('.total').show();

    });
       
     
}); //end doc ready


function fbooksend() {
	var weekPoints = $('#team_screen_week .total span').text();
	
			FB.getLoginStatus(function(response) {
					  if (response.session) {
							FB.ui({
								  method: 'stream.publish',
								  message: 'This week I scored ' + weekPoints + ' points this week',
								  display: 'iframe',
								  attachment: {
													name: 'Fantasy League Demo 2011/2012',
											href: '' + document.location ,
											media: [
												  {
													type: 'image',
													href: 'http://premcorpdemo.uat.fantasyleague.com',
													src: 'http://imageseasynet.fantasyleague.com/fast/prem.1112/images/fbook_icon.jpg'
												  }
												]
								  },
								  action_links: [
									{ text: 'Fantasy League Demo 2011/2012', href: 'http://premcorpdemo.uat.fantasyleague.com' }
								  ],
								  user_message_prompt: 'come take a look at my team'
								});
								
													  return false 
					  }
					  else {
						  
						  FB.login(function(response) {
							    if (response.session) {
							    // user successfully logged in
							return fbooksend()
							  } else {
								// user cancelled login
							alert("User cancelled Login")
					  			} // end login if statment
	
				  }); // end FB.login()
								
			  }//end if

		})// End FB getlogin
}// end fbooksend function


/************************************************************************************/


        // Facebook Connect Show Team
        function fbooksendteam() {
            var team = "";

            $("#team_screen_container #team_screen_status li a").each(function() {
                team += $(this).text().replace(/\s+$/, '');
                team += ", ";
            });


			FB.getLoginStatus(function(response) {
					  if (response.session) {
							FB.ui({
								  method: 'stream.publish',
								  message: "My Fantasy Football team is: " + team + "what's yours?" ,
								  display: 'iframe',
								  attachment: {
													name: 'Fantasy League Demo 2011/2012',
											href: '' + document.location ,
											media: [
												  {
													type: 'image',
													href: 'http://premcorpdemo.uat.fantasyleague.com',
													src: 'http://imageseasynet.fantasyleague.com/fast/prem.1112/images/fbook_icon.jpg'
												  }
												]
								  },
								  action_links: [
									{ text: 'Fantasy League Demo 2011/2012', href: 'http://premcorpdemo.uat.fantasyleague.com' }
								  ],
								  user_message_prompt: 'come take a look at my team'
								});
					  return false 

					  }
					  else {
						  
						  FB.login(function(response) {
							    if (response.session) {
										// user successfully logged in

							return fbooksendteam()
									  } else {

										// user cancelled login
									  }

						  });

					  return false 
								
					  }//end if
					  return false 
			})// End FB getlogin
			
        };// End fbooksendteam function


/*******************************************************************************************************************/

// send an invite to specific friends on facebook

function inviteFbook() {
	
			
FB.getLoginStatus(function(response) {
		  if (response.session) {
	
	         FB.ui({ method: 'apprequests', 
			 		display: 'iframe',

            message: 'Hi I\'ve set up a team on Fantasy League come and join me!'});
		  } else {
			   FB.login(function(response) {
				   return inviteFbook() 
			   })
		  }
})
	
	
} //end inviteFbook()

/*****************************************************************************************************************/



