

/***************************************************************************************
***********************			bookmark function 			***************************
****************************************************************************************/


function bookmark() {
var title = document.title
var url = window.location
if (window.sidebar) { // firefox

window.sidebar.addPanel(title, url,"");

}
else if (window.chrome) {

alert("Chrmoe dosen't support this please press Ctrl+D to save this page to you favorites.");

}
 else if (window.external) {
	window.external.AddFavorite(url, title);
}



 else {

alert("Sorry, your browser doesn't support this");

}// end else



}// end bookmark()







$(document).ready(function() {

		
    /***
    * General 
    ***/
		
		// hidding stuff function
		$('.hide').toggle( function() {
		var whatToHide = $(this).attr('href')
		$(whatToHide).hide(500)
		$(this).removeClass('open').addClass('closed')
		$(this).text('Show')
		
		}, function() {
		var whatToShow = $(this).attr('href')
		$(whatToShow).show(500)
		$(this).removeClass('closed').addClass('open')
		$(this).text('Hide')
				
		});
 
    //Menu Highlighting!
    var bodyId = $("body").attr("id");
    $("#topMenu li#tab_" + bodyId).addClass("tab-cur bg");
    $("#navigation li#tab_" + bodyId).addClass("on");

    // Table Hover
    // Add tr hover class for ie6+
    $("table.tabbed tbody tr").hover(function() {
        $(this).addClass("hover");
    }, function() {
        $(this).removeClass("hover");
    });

    $("table tbody tr").each(function() {
        $(this).find("td:first:not(.first)").addClass("first");
        $(this).find("td:last:not(.end)").addClass("end");
    });
    $("table thead tr, table tr.head").each(function() {
        $(this).find("th:first:not(.first)").addClass("first");
        $(this).find("th:last:not(.end)").addClass("end");
    });

    // Menu
    $('#topMenu li').hover(function() {
        $('ul', this).slideDown(200);
				if( $(this).attr('id') != "tab_" + bodyId) {
        $(this).not('this ul li').addClass('bg');
				}
    }, function() {

		$('ul', this).slideUp(200);

		if( $(this).attr('id') != "tab_" + bodyId) {
        $('ul', this).slideUp(200);
        $(this).not('this ul li').removeClass('bg');
		} 

		
    });

    // Forms & Labels
    // Hide overlay on focus

		$('input.text').each( function() {
		
		if( $(this).val() != "") {

	$(this).prev('.overlay').hide()

		}
	})
	
	
$('input').focus( function() {
$(this).prev('.overlay').hide()
});

$('input').blur( function() {


if( $(this).val() === "") {

$(this).prev('.overlay').show()

		}



});

	

    // Feeds / Twitter
    $("#newsFeeds ul.tabs a").click(function() {
        $("#newsFeeds ul.tabs li").removeClass("on");
        $(this).parent().addClass("on");
        $("#twitter_div, #news_div").hide();
        $("#" + $(this).attr("id") + "_div").show();
        return false;
    });
	
	
	
    // Countdown Timer
    var today = new Date();
    var offset = (new Date().getTimezoneOffset() / 60) * -1;
	
    var pre = new Date("August 13, 2011 15:00:00 GMT+" + offset );
    var gp1 = new Date("January 05, 2012 00:00:00 GMT+" + offset);// captain opens
    var gp2 = new Date("January 11, 2012 19:45:00 GMT+" + offset);// captain closes
    var gp3 = new Date("January 12, 2012 00:00:00 GMT+" + offset);//captian opens
	var gp4 = new Date("January 14, 2012 15:00:00 GMT+" + offset);// captain closes
	var gp5 = new Date("January 17, 2012 00:00:00 GMT+" + offset);// captain opens
	var gp6 = new Date("January 21, 2012 12:45:00 GMT+" + offset);// captain closes
	var gp7 = new Date("January 24, 2012 00:00:00 GMT+" + offset);// captain opens
	var gp8 = new Date("January 31, 2012 19:45:00 GMT+" + offset);// captain closes
	var gp9 = new Date("February 02, 2012 00:00:00 GMT+" + offset);// captain closes
	var gp10 = new Date("February 04, 2012 13:00:00 GMT+" + offset);// captain opens
	var gp11 = new Date("February 07, 2012 00:00:00 GMT+" + offset);// captain closes
	var gp12 = new Date("February 11, 2012 12:45:00 GMT+" + offset);// captain opens
	var gp13 = new Date("February 14, 2012 00:00:00 GMT+" + offset);// captain closes
	var gp14 = new Date("February 25, 2012 12:45:00 GMT+" + offset);// captain opens
	var gp15 = new Date("February 28, 2012 00:00:00 GMT+" + offset);// captain closes
	var gp16 = new Date("March 03, 2012 15:00:00 GMT+" + offset);// captain opens
	var gp17 = new Date("December 20, 2011 00:00:00 GMT+" + offset);// captain closes
	var gp18 = new Date("December 20, 2011 19:45:00 GMT+" + offset);// captain opens
	var gp19 = new Date("December 23, 2011 00:00:00 GMT+" + offset);// captain closes
	var gp20 = new Date("December 26, 2011 13:00:00 GMT+" + offset);// captain opens
	var gp21 = new Date("December 27, 2011 00:00:00 GMT+" + offset);// captain closes
	var gp22 = new Date("December 27, 2011 15:00:00 GMT+" + offset);// captain opens
	var gp23 = new Date("January 03, 2012 00:00:00 GMT+" + offset);// captain closes
	var gp24 = new Date("January 05, 2012 00:00:00 GMT+" + offset);// captain opens
	
	

    if (pre > today) {
        var header = "Countdown to Kick-off";
        var date = pre;
        var exp = "The season starts in:"
    } else if (gp1 > today) {
        var header = "";
        var date = gp1;
        var exp = "The window for captain changes opens in:";
    } else if (gp2 > today) {
        var header = "Game Phases";
        var date = gp2;
        var exp = "The window for captain changes closes in:";
    } else if (gp3 > today) {
        var header = "Game Phases";
        var date = gp3;
        var exp = "Captain changes available in:";
	} else if (gp4 > today) {
        var header = "Game Phases";
        var date = gp4;
        var exp = "The window for captain changes closes in:";
    } else if (gp5 > today) {
        var header = "Game Phases";
        var date = gp5;
        var exp = "Captain changes available in:";
	} else if (gp6 > today) {
        var header = "Game Phases";
        var date = gp6;
        var exp = "The window for captain changes closes in:";
    } else if (gp7 > today) {
        var header = "Game Phases";
        var date = gp7;
        var exp = "Captain changes available in:";
	} else if (gp8 > today) {
        var header = "Game Phases";
        var date = gp8;
        var exp = "The window for captain changes closes in:";
    } else if (gp9 > today) {
        var header = "Game Phases";
        var date = gp9;
        var exp = "Captain changes available in:";
	} else if (gp10 > today) {
        var header = "Game Phases";
        var date = gp10;
        var exp = "The window for captain changes closes in:";
    } else if (gp11 > today) {
        var header = "Game Phases";
        var date = gp11;
        var exp = "Captain changes available in:";
	} else if (gp12 > today) {
        var header = "Game Phases";
        var date = gp12;
        var exp = "The window for captain changes closes in:";
    } else if (gp13 > today) {
        var header = "Game Phases";
        var date = gp13;
        var exp = "Captain changes available in:";
	} else if (gp14 > today) {
        var header = "Game Phases";
        var date = gp14;
        var exp = "The window for captain changes closes in:";
    } else if (gp15 > today) {
        var header = "Game Phases";
        var date = gp15;
        var exp = "Captain changes available in:";
	} else if (gp16 > today) {
        var header = "Game Phases";
        var date = gp16;
        var exp = "The window for captain changes closes in:";
	} else if (gp17 > today) {
        var header = "Game Phases";
        var date = gp17;
        var exp = "Captain changes available in:";
	} else if (gp18 > today) {
        var header = "Game Phases";
        var date = gp18;
        var exp = "The window for captain changes closes in:";
	} else if (gp19 > today) {
        var header = "Game Phases";
        var date = gp19;
        var exp = "Captain changes available in:";
	} else if (gp20 > today) {
        var header = "Game Phases";
        var date = gp20;
        var exp = "The window for captain changes closes in:";
	} else if (gp21 > today) {
        var header = "Game Phases";
        var date = gp21;
        var exp = "Captain changes available in:";
	} else if (gp22 > today) {
        var header = "Game Phases";
        var date = gp22;
        var exp = "The window for captain changes closes in:";
	} else if (gp23 > today) {
        var header = "Game Phases";
        var date = gp23;
        var exp = "Captain changes available in:";
	} else if (gp24 > today) {
        var header = "Game Phases";
        var date = gp24;
        var exp = "The window for captain changes closes in:";
	} else {
        var header = "Scoring Starts In:";
        var date = end;
        var exp = "Game Phase 10 Open, closes in:";
    }

    $("#counter h2").text(header);
    $("#counter p").html(exp);

    $('#defaultCountdown').countdown({ until: date });
    $('#removeCountdown').toggle(function() {
        $('#defaultCountdown').countdown('destroy');
    }, function() {
        $('#defaultCountdown').countdown({ until: date, compact: true });
    });


    /***
    * Homepage 
    ***/

    if ($("body").attr("id") == "Index") {

		
        $('ul.images-list li.prizes a').click(function() {
            window.location.href= "Playerlist.aspx";
            return true;
        });

        $('ul.images-list li.stats a').click(function() {
            window.location.href = "Article.aspx?id=503";
            return true;
        });

        $('ul.images-list li.teamscreen a').click(function() {
            window.location.href = "Article.aspx?id=201";
            return true;
        });
    }
    else if ($("body").attr("id") == "ResultsAndFixtures") {

        $("#ResultsAndFixtures table.tabbed").each(function() {
            $(this).find("tr:first").addClass("head");
        });

        $("#ResultsAndFixtures table.tabbed tr:nth-child(3)").each(function() {
            $(this).remove();
        });

    }
    
    
    /***
    * Team 
    ***/

    else if ($("body").attr("id") == "Team") {


		$('#share_container a, .total').addClass('bg');



 
		// add team news link to status window
		$('#team_screen_status').append('<a class="news" href="Article.aspx?id=161">Team News</a>') ;
		
		
        // Column Highlighting in 1 function + Sticky Clicking
        $("table.cols tr.head th").hover(function() {
            var _this = $(this).parent().parent();

            $(this).addClass("on");
            // Calculate Column Number
            $(_this).find("tr td:nth-child(" + (this.cellIndex + 1) + ")").addClass("on");

        }, function() {
            // Remove Highlighting
            $("table.cols tr.head th, table.cols tr td").removeClass("on");

        }).click(function() {
            var _this = $(this).parent().parent();
            // Sticky Highlighting
            $(_this).find("tr.head th, tr td").removeClass("sticky");
            $(this).addClass("sticky");
            $(_this).find("tr td:nth-child(" + (this.cellIndex + 1) + ")").addClass("sticky");
        });

        // Points
        var totalpoints = parseInt($("#team_screen_container #team_screen_total .total span").text());
        var roundpoints = parseInt($("#team_screen_container #team_screen_week .total span").text());

        $("table.key tfoot td.total").text(totalpoints);

        // Team breakdown flags & sticky
        $("table.teamsold tr, table.teamlist tr").each(function() {
            $(this).find("td:last, th:last").addClass("sticky");

            var _this = $(this).find("td.club").text();
            $(this).find("td.club").html("<span class='flag flag_" + _this + "'>" + _this + "</span>");

        });
		
		var team = ""
            $("#team_screen_container #team_screen_status li a").each(function() {
                team += $(this).text().replace(/\s+$/, '');
                team += ",";
				if(team.length > 95) {
				return false 
				}
            });
			
			
        // Share to twitter
        $("a.twitter").click( function() {
		
		window.open("http://twitter.com/share?text=This%20week%20I%20scored%20 " + roundpoints + "%20points.%20Come%20take%20a%20look&url=" + location + "&amp\" ", 'name', 'height=350, width=600, titlebar=0, resizable=0, status=0, menu=0, scrollbar=0, location=0, toolbar=0');
			return false
		});
		$("a.twitter.team").click( function() {
		
		window.open("http://twitter.com/share?text=My%20team%20is: " + team + "&url=" + location + "&amp\" ", 'name', 'height=350, width=600, titlebar=0, resizable=0, status=0, menu=0, scrollbar=0, location=0, toolbar=0');
			return false
		});
       
	   
    }
	
	/****************************
		Private Leagues Page
	****************************/
	
	
	    else if ($("body").attr("id") == "FriendsLeague") {
			
				//  Private Leagues positons script
				
				
				if($('.friendsleague tr').length > 3) {
				
				$('#league_podium').show();
				
				for(var i=0; i < 3 ; i++ ){ 
				var places = i
				
				var scores = $('.friendsleague  td.end').get(i); 
				var names = $( $(scores).prevAll()[3]).text()
				
				 $('#place' + ++places + '' ).html('<h4>' + names + '</h4> <p> Current Total:<br />' + $(scores).text() + '</p>' ) 
				
				
				};  
				
				
				var lastplace = $('.friendsleague tr:last  td.end').text(); 
				var loser = $( $('.friendsleague tr:last  td.end').prevAll()[3] ).text()
				$('#woodenspoon').html('<h4>' + loser + '</h4> <p> Gets the wooden spoon, with '  + lastplace + '. Chin up ' + loser + ' maybe next week?' )
				} 
				
		// Share to twitter Private League
        $("a.twitter").click( function() {
		
		window.open("http://twitter.com/share?text=Come%20join%20my%20fantasy%20private%20league.%20My%20PIN%20is:%20 " + $('#pin').text() + "&amp\" ", 'name', 'height=350, width=600, titlebar=0, resizable=0, status=0, menu=0, scrollbar=0, location=0, toolbar=0');
			return false
		});
		}
		else if ($("body").attr("id") == "PlayerList") {
		
		//hide the player Status Tooltip straight away
		$('.status_tooltip').hide();
		//fadein/out the player status Tooltip on hover
		$('td.status').hover(function() {
		$(this).find('.status_tooltip').fadeIn();
		}, function() {
		$(this).find('.status_tooltip').fadeOut();
		})
		}
		
		else if ($('#accordion').length >= 1 ) {
// accordion function on faq and how to play
$('#accordion h1 a').click(function() {

	if(	$(this).parent().next().hasClass('open')) {
	
	
	$('.open').removeClass('open').addClass('hidden').prev().children().css({backgroundPosition: '592px -26px'})
	return false

	} else {

	

	$('.open').removeClass('open').addClass('hidden').prev().children().css({backgroundPosition: '592px -26px'})
	
	$(this).css({backgroundPosition: '592px -88px'})

	$(this).parent().next().removeClass('hidden').addClass('open');
	return false
	}
	})
	}	//end else if 
	


	
	/**********************************************************************************
	******************************  Load Facebook SDK on doc ready ********************
	**********************************************************************************/

		window.fbAsyncInit = function() {
	   FB.init({appId: '162586770468549', status: true, cookie: true, oauth: true, xfbml: true});
	};
	(function() {
	   var e = document.createElement('script');
	   e.type = 'text/javascript';
	   e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
	   e.async = true;
	   document.getElementById('fb-root').appendChild(e);

	}());


/*************************************************************************************/

	
	
	
    // End Doc.Rdy
	
});



/********************************
**********************************
// facebook
*********************************
********************************/

function fbooksend() {
	var weekPoints = $('#team_screen_week .total span').text();
	
			FB.getLoginStatus(function(response) {
					  if (response.authResponse) {
							FB.ui({
								  method: 'feed',
								  description:( 'This week I scored ' + weekPoints + ' points'),
								  display: 'iframe',
								  name: document.title ,
								  link: document.location.href ,
								  picture: fbookIcon ,
								  actions: [
									{ name: document.title, link: document.location.href }
								  ],
								  user_message_prompt: 'come take a look at my team'
								});
								
													  return false 
					  }
					  else {
						  
						  FB.login(function(response) {
							    if (response.authResponse) {
							    // 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.authResponse) {
							FB.ui({
								  method: 'feed',
								  description:( "My Fantasy Football team is: " + team + " - enter yours today!" ),
								  display: 'iframe',
								  name: document.title ,
								  link: document.location.href,
								  picture: fbookIcon ,
								  actions: [
									{ name: document.title, link: document.location.href }
								  ],
								  user_message_prompt: 'come take a look at my team'
								});
					  return false 

					  }
					  else {
						  
						  FB.login(function(response) {
							    if (response.authResponse) {
										// 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.authResponse) {
	console.log("yep")
	         FB.ui({
					method: 'send', 
			 		name: document.title ,
					link: document.location.href ,
					// redirect_uri: document.location.href ,
					picture: fbookIcon ,
					description: ("Hi I've set up a team on Fantasy League come and join me!   " + $('#pin em').text() + "")
					});
		  } else {
						  
						  FB.login(function(response) {
							    if (response.authResponse) {
							    // user successfully logged in
							return inviteFbook()
							  } else {
								// user cancelled login
							alert("User cancelled Login")
					  			} // end login if statment
	
				  }); // end FB.login()
		  }
})
	
	
} //end inviteFbook()

/*****************************************************************************************************************/

function fbookSendPin() {
	var LeaguePIN = $('#pin').text();
	
			FB.getLoginStatus(function(response) {
					  if (response.authResponse) {
							FB.ui({
								  method: 'feed',
								  description:( 'Come join my private league! Click the link and enter my PIN: ' + LeaguePIN + '. See you there!'),
								  display: 'iframe',
								  name: document.title ,
								  link: document.location.href,
								  picture: fbookIcon ,
								  actions: [
									{ name: document.title, link: document.location.href }
								  ],
								  user_message_prompt: 'come take a look at my team'
								});
							  }
					  else {
						  
						  FB.login(function(response) {
							    if (response.authResponse) {
							    // 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


/************************************************************************************/





