$(document).ready(function(){$('.arrangebutton, .arrangeagame').click(function(){($(this).hasClass('arrangeagame'))?width=500:width=665;$.get($(this).attr('href'),function(data){modal(data,width);ajaxedLink(width);ajaxedSubmit(width);});return false;});$('.ajaxprofile').live("click",function(){width=500;$.get($(this).attr('href'),function(data){modal(data,width);ajaxedLink(520);ajaxedSubmit(width);});return false;});$('.welcome-panel .button_ltarating, .welcome-panel .findoutmore, .no_lta').click(function(){$.get($(this).attr('href'),function(data){modal(data,700);});return false;});$('.side_mini').live('click',function(){if(!$(this).parent().next('.hidePanel').length&&!$(this).parent().next().find('.hidePanel').length){if($(this).hasClass('friends_mini')&&$('#friendRequests').length){$('#friendRequests').nextAll('div').slideUp();$('.friend-search').slideUp('normal',hideDetect);}else{$(this).parent().next('.panel_border, .panel_columns').slideUp('normal',hideDetect);}
$(this).attr({src:"/static/images/community/welcome_plus.gif"});}else{if($(this).hasClass('friends_mini')&&$('#friendRequests').length){$('#friendRequests').nextAll('div').slideDown();$('.friend-search').slideDown('normal',hideDetect);}else{$(this).parent().next('.panel_border, .panel_columns').slideDown('normal',hideDetect);}
$(this).parent().parent().find('div').removeClass('hidePanel');$(this).attr({src:"/static/images/community/welcome_minus.gif"});}});$('body').ajaxStart(function(){$('body').append('<div id="click_prevent"></div>');});$('body').ajaxStop(function(){$('#click_prevent').remove();});$('body').ajaxError(function(){$('#click_prevent').remove();});});function hideDetect(){var ids=[];$('.panel_border:hidden, .panel_columns:hidden, .friend-list:hidden').each(function(i){var id=$(this).attr('id');if(id=='friends_hide'&&$('#friendRequests').length)id='friend_hide';ids[i]=id;$(this).addClass('hidePanel');});var hidden='hidden='+ids.join(',');$.get('/home/memberslounge/communities/tennis/panelhide',hidden)}
function createCookie(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString();}
else var expires="";document.cookie=name+"="+value+expires+"; path=/";}
function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);}
return null;}
function eraseCookie(name){createCookie(name,"",-1);}
function isIE()
{if(navigator.userAgent.match(/MSIE \d\.\d+/))
return true;return false;}
function tabReload(){var selected=$('#communityTabs li.selected').attr('id');$.get('/home/memberslounge/communities/tennis/tabs/'+selected,function(data){$('#communityTabs').html(data);});}
function divReload(which,url,postData,callback){var type=(postData)?'POST':'GET';if(undefined===postData)postData='';if(undefined===callback)callback='';$.ajax({type:type,data:postData,url:url,success:function(data){if(data==="logged_out"){document.location="/home/memberslounge";}else if(data==="none"){$('#no_results').show();}else{$(which).fadeOut("fast",function(){$(which).html(data);$(which).fadeIn();if($('#hover_screen').length){$('#hover_screen').remove();}
if(which=='#matchesInner')hideDetect();if(callback!=''){callback();}});}}});}
function courtAdd(id){tabReload();if($('#matches_wrap').length){divReload('#matches_wrap','/home/memberslounge/communities/tennis/games/update');}else if($('.notices_wrap').length){divReload('.notices_wrap','/home/memberslounge/communities/tennis');}
if($('#gameSide'+id).length){divReload('#matchesInner','/home/memberslounge/communities/tennis/games/panel-update');}}
function matchInvite(){if($('#matches_wrap').length){divReload('#matches_wrap','/home/memberslounge/communities/tennis/games/update');}}
function matchAccept(hover){if($('#matches_wrap').length){divReload('#matches_wrap','/home/memberslounge/communities/tennis/games/update');}else if($('.box-league').length){divReload('.box-league','/home/memberslounge/communities/tennis/competitions');}
if(!hover){if($('#sideMatches').length){var count=$(".sideMatch").length;if(count<3){divReload('#matchesInner','/home/memberslounge/communities/tennis/games/panel-update');$('.matches_mini').attr({src:"/static/images/community/welcome_minus.gif"});$('#matchesInner').removeClass('hidePanel');}}}}
function friendAdd(friend,url){if($('#friendsWrap').length){divReload('#friendsWrap','/home/memberslounge/communities/tennis/friends');}
friends=parseInt($('#friendInt').html());if(friends<6){if(friends==0)$('#noFriends').fadeOut();var clearClass='';if(friends==2||friends==5)clearClass=' clearfix';$('.friend-list').append('<div class="friend-item'+clearClass+'" id="friendPanel'+friend.id+'"><a href="/'+url+'/profiles/'+friend.id+'" class="image ajaxprofile"><img src="/static/avatars/54_'+friend.avatar+'" width="54" height="54"/><a href="/'+url+'/profiles/'+friend.id+'" class="name ajaxprofile">'+friend.forename+' '+friend.surname+'</a></div>');}
$('#totalFriends').html('<span id="friendInt">'+(friends+1)+'</span> friends');if($('#totalFriendRequests').length){var count=parseInt($('#totalFriendRequests').html());count--;if(count){if(count==1){$('#totalFriendRequests').html(count+' request');}else{$('#totalFriendRequests').html(count+' requests');}}else{$('#friendRequests').slideUp(function(){$(this).next().hide();});}}
if($('#side_arrange').hasClass('hide')){$('#side_arrange').fadeIn('normal',function(){$('#side_arrange').removeClass('hide');});}}
function friendDecline(){var count=parseInt($('#totalFriendRequests').html());count--;if(count){if(count==1){$('#totalFriendRequests').html(count+' request');}else{$('#totalFriendRequests').html(count+' requests');}}else{$('#friendRequests').slideUp(function(){$(this).next().hide();});$('.friend-requests').slideUp();}}
function friendDelete(friend,url){if($('#friendsWrap').length){divReload('#friendsWrap','/'+url+'/friends');}
var count=parseInt($('#friendInt').html());count--;if(count==1){$('#totalFriends, .number-container .count').html(count+' friend');}else{$('#totalFriends, .number-container .count').html(count+' friends');}
if(count==0){$('#friendsInner').prepend('<p id="noFriends">You have not added any friends. <br /><a href="/'+url+'/friends">Search for friends.</a></p>');$('#side_arrange').fadeOut();}
if($('#friendPanel'+friend)){$('#friendPanel'+friend).fadeOut();}}
function partnerAdd(id,url){if($('#partner'+id).length){$('#partner'+id).removeClass('addasdoublespartner');$('#partner'+id).addClass('removaasdoublespartner');$('#partner'+id).attr('href','/'+url+'/actions/partner/delete/'+id);}}
function partnerDelete(id,url){if($('#partner'+id).length){$('#partner'+id).removeClass('removaasdoublespartner');$('#partner'+id).addClass('addasdoublespartner');$('#partner'+id).attr('href','/'+url+'/actions/partner/add/'+id);}}
function partnerDecline(url){if($('#friendsWrap').length){divReload('#friendsWrap','/'+url+'/friends');}}
