/* [INCLUDE FILE] league/lib/prototype */
/* [FILE NOT FOUND] league/lib/prototype */
/* [INCLUDE FILE] league/src/effects */
/* [FILE NOT FOUND] league/src/effects */
/* [INCLUDE FILE] league/Classes/LeaguePanel */
var LeaguePanel ={

// web service url
WS_URL:'/php/services/players-league/',

/**
 * Initialize league panel
 */
initialize:function(level)
{
// set default for level
if (typeof(level) == "undefined"){
var level = 0;
}

// set the level
this.level = level;

// set the params
this.game_id = gid;

// ini league data
this._league_data = null;

// load the league data
this.loadLeagueData();
},

/**
 * load league data from webservice
 */
loadLeagueData:function()
{
// make the query string
var qs = '?gid=' + this.game_id + '&lv=' + this.level;

var ajax = GetXmlHttpObject();

if (ajax != null){
ajax.onreadystatechange = function(r){
if (ajax.readyState==4){
// console.log(LeaguePanel);
LeaguePanel._league_data = eval('(' + ajax.responseText + ')');
LeaguePanel.build();
}
};

ajax.open("POST",this.WS_URL + qs,true);
ajax.send(null);
}

},

/**
 *
 */
build:function()
{

// grab the result
var result = this._league_data.result;

if (this._league_data.success == true){

// set award block style and add the friends html to the panel
if (result.game_awards != false){
var row_count = Math.floor((result.game_awards.length - 1) / 3) + 1;
}else{
var row_count = 0;
}

$('leagueFriends').className = 'leagueFriends awardsRow' + row_count;
$('leagueHeader').innerHTML = result.header_html;
$('leagueFriends').innerHTML = result.friends_html;

$('leagueContain').style.display = 'block';

}else{
// update the award block
//$('awardHolder').set.display = 'block';
//$('awardActivate').set.display = 'block';

if (result == 1){
$('leagueContain').style.display = 'block';
}else{
$('leagueContain').style.display = 'none';
}

}

}

};

var LeaguePanelInvite ={

/**
 * Toggle the panel visibililty
 */
toggle:function()
{
switch ($('leagueInvite').style.display == 'block'){
case false:
this.show();
break;
case true:
this.hide();
break;
}
},

 /**
  * Show the panel
  */
 show:function(challenge_id)
{
$('inviteToggle').className = "retract";
if (challenge_id){
$('invite_link_text').innerHTML = 'Send link to friend to challenge your score:';
$('friend_challenge').innerHTML = 'Or challenge your friend\'s high score now:<a href="?challenge=' + challenge_id + '">Click here!</a>';
$('friend_challenge').style.display = 'block';
$('invite_link_input').style.width = '360px';
}else{
$('invite_link_text').innerHTML = 'Send link to friends to join your league:';
$('friend_challenge').style.display = 'none';
$('friend_challenge').innerHTML = '';
$('invite_link_input').style.width = '376px';
}

$('leagueInvite').style.display = 'block';
$('invite_link_input').select();
},

 /**
  * Hide the panel
  */
 hide:function()
{
$('inviteToggle').className = "expand";
$('leagueInvite').style.display = 'none';
}
};

/**
 * This function is for the flash external interface access
 */
LeaguePanel_initialize = function(game_id)
{
LeaguePanel.initialize(game_id);
}/* [INCLUDE FILE] league/gamePage_load */
function init_league()
{
if ($('leagueContain').style.display != 'block'){
LeaguePanel.initialize(level);
}
}

function LeaguePanel_initialize(level)
{
LeaguePanel.initialize(level);
}

function loadLoginbox302 (screen){

loginBoxDiv = $("leagueInfo");

if (loginBoxDiv){

loginBoxDiv.style.width = '323px';
$('friend_end').style.display = 'none';


if ($('leagueLanding').className == 'login'){
return false;
}

$('leagueLanding').className = 'login';

loginboxDetails = AC_FL_GetContent(
'id','loginbox',
'classid','clsid:D27CDB6E-AE6D-11cf-96B8-444553540000',
'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
'width','324',
'height','200',
'src','/players/swf/components/loginbox',
'flashvars','sessid=neh770vepohqmn6ejskg3clpq3&loggedin=0&ua=7224b4f&screen=player&cfg=stop&screen=' + screen,
'menu','true',
'wmode','window'
);

loginBoxDiv.innerHTML = loginboxDetails;

}

return false;

}

function GetXmlHttpObject()
{

if (window.XMLHttpRequest){
// code for IE7+,Firefox,Chrome,Opera,Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject){
// code for IE6,IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}

// workaround for when init fails
document.initTimer = setTimeout(function(){
if ($('leagueContain').style.display != 'block'){
LeaguePanel.initialize(level);
}
clearTimeout(document.initTimer);
},5000);

addLoadEvent(init_league);