/*******************
Menu
*******************/
function ShowMenu(oElement)
{
  var sOpenMenu = "";
  oEle = oElement.parentNode;
  for(var i = 0; i < oEle.childNodes.length; i++)
  {
    if((oEle.childNodes[i].nodeName == "LI" && oEle.childNodes[i].className == "part0" || oEle.childNodes[i].className == "part1"))
    {
      oEle.childNodes[i].style.display = oEle.childNodes[i].style.display == "none"? "block":"none";
    }
    else if((oEle.childNodes[i].nodeName == "LI" && oEle.childNodes[i].className == "section"))
    {

      for(var j = 0; j < oEle.childNodes[i].childNodes.length; j++)
        if(oEle.childNodes[i].childNodes[j].nodeName == "SPAN")
          oEle.childNodes[i].childNodes[j].className = (oEle.childNodes[i].childNodes[j].className == "open"?"close":"open");
    }
  }
  /*var sValue = "";
  var oElementLeft = document.getElementById("left");
  for(var i = 0; i < oElementLeft.childNodes.length; i++)
  {
    if(oElementLeft.childNodes[i].nodeName == "UL")
      if(oElementLeft.childNodes[i].childNodes[3].style.display == "none")
        sValue += oElementLeft.childNodes[i].id + ";";
  }*/
  //SetCookie("menu", sValue);
}

function CreateCharacter(sLang, sName, iBreedId, sSex, iColor1, iColor2)
{
  aSplit = document.location.host.split('.');
  sDomain = aSplit[aSplit.length-1]

  var oForm = document.createElement('form');
  oForm.method = "post";
  oForm.style.display = "none";
  switch(sLang)
  {
    case 'fr':
      oForm.action = "https://secure.wakfu." + sDomain + "/fr/creer-un-compte";
    break;
    case 'en':
      oForm.action = "https://secure.wakfu." + sDomain + "/en/account-creation";
    break;
    case 'de':
      oForm.action = "https://secure.wakfu." + sDomain + "/de/account-erstellen";
    break;
    case 'es':
      oForm.action = "https://secure.wakfu." + sDomain + "/es/creacion-de-cuenta";
    break;
  }
 
  var oInput = document.createElement("input");
  oInput.name = "ch_name";
  oInput.type = "hidden"; 
  oInput.value = sName;
  oForm.appendChild(oInput);
 
  var oInput = document.createElement("input");
  oInput.name = "ch_breed";
  oInput.type = "hidden"; 
  oInput.value = iBreedId;  
  oForm.appendChild(oInput);

  var oInput = document.createElement("input");
  oInput.name = "ch_sex";
  oInput.type = "hidden"; 
  oInput.value = sSex;  
  oForm.appendChild(oInput);
 
  var oInput = document.createElement("input");
  oInput.name = "ch_color1";
  oInput.type = "hidden"; 
  oInput.value = iColor1;  
  oForm.appendChild(oInput);
  
  var oInput = document.createElement("input");
  oInput.name = "ch_color2";
  oInput.type = "hidden"; 
  oInput.value = iColor2;  
  oForm.appendChild(oInput);

  document.body.insertBefore(oForm, document.body.firstChild);
  
  oForm.submit();
}

/********************
News
********************/

function SeeNewsHome(iId, sCat)
{
  if (typeof(iCurrentNews) == "undefined" || iCurrentNews !== iId)
  {
    var sHeight = 0;
    var attributes =  {height: { to: 0, unit:'px' } };  
    aDiv = YAHOO.util.Dom.getElementsByClassName("content_news", 'div');
    var iSumHeight = 0;
    for(i = 0; i < aDiv.length; i++)
    {
    
      if(aDiv[i].id != ("news_" + sCat + "_" + iId) && (aDiv[i].id.substr(0,7) == "news_" + sCat + "_") && aDiv[i].style.height != "0px")
      {
        
        var anim = new YAHOO.util.Anim(aDiv[i].id, attributes,  0.2, YAHOO.util.Easing.easeOut);
        anim.animate();
      }
      else if(aDiv[i].id == "news_" + sCat + "_" + iId)
      {
        var attributesWiden =  {height: { from: 0, to: aDiv[i].scrollHeight, unit:'px' } }; 
        var anim = new YAHOO.util.Anim(aDiv[i].id, attributesWiden,  0.2, YAHOO.util.Easing.easeOut);
        anim.animate();
        aDiv[i].scrollHeight;
        sHeight += aDiv[i].scrollHeight;
      }
      if((aDiv[i].id == "title_" + sCat +"_" + iId) ) 
      {
        aDiv[i].className = "bg_white_border_grey " + aDiv[i].className ;
        sHeight += aDiv[i].scrollHeight;
      }
      else if((aDiv[i].id != "title_" + sCat + "_" + iId) && (aDiv[i].id.substr(0,8) == "title_" + sCat + "_"))
      {
        aDiv[i].className = "news content_news content_title";
        sHeight += aDiv[i].scrollHeight;
  
      }
    }
    ChangeHeight(sHeight);
    iCurrentNews = iId;
  }
}

function ChangeHeight(sHeight)
{
  var attributesWiden =  {height: { from: parseInt(YAHOO.util.Dom.get("home_right").style.height.substring(0, YAHOO.util.Dom.get("home_right").style.height.indexOf("px", 0))), to: (sHeight + 44), unit:'px' } }; 
  var anim = new YAHOO.util.Anim(YAHOO.util.Dom.get("home_right").id, attributesWiden,  0.2, YAHOO.util.Easing.easeOut);
  anim.animate();
}

function InitializeHeight()
{
  YAHOO.util.Dom.get("home_right").style.height = (YAHOO.util.Dom.get("home_left").offsetHeight - 36) + "px";
}

function SeeNews(iId)
{
  var attributes =  {height: { to: 0, unit:'px' } };  
  aDiv = YAHOO.util.Dom.getElementsByClassName("content_news", 'div');
  var iSumHeight = 0;
  for(i = 0; i < aDiv.length; i++)
  {
    if(aDiv[i].id != "news_" + iId && aDiv[i].id.substr(0,5) == "news_" && aDiv[i].style.height != "0px")
    {
      var anim = new YAHOO.util.Anim(aDiv[i].id, attributes,  0.2, YAHOO.util.Easing.easeOut);
      anim.animate();
    }
    else if(aDiv[i].id == "news_" + iId && aDiv[i].style.height == "0px")
    {
      var attributesWiden =  {height: { from: 0, to: aDiv[i].scrollHeight, unit:'px' } }; 
      var anim = new YAHOO.util.Anim(aDiv[i].id, attributesWiden,  0.2, YAHOO.util.Easing.easeOut);
      anim.animate();
      
      //iSumHeight += aDiv[i].scrollHeight;
    }
    if(aDiv[i].id == "title_" + iId && aDiv[i].className != "bg_white_border_grey news content_news content_title") 
    {
      aDiv[i].className = "bg_white_border_grey " + aDiv[i].className ;
    }
    else if(aDiv[i].id != "title_" + iId && aDiv[i].className == "bg_white_border_grey news content_news content_title")
    {
      aDiv[i].className = "news content_news content_title";

    }
  }
  //alert("g");
 //sleep(1);
 //setTimeout('ChangeHeight()', 200);
  //var iNumber = (YAHOO.util.Dom.get("home_left").scrollHeight);
  //trace(iNumber);
  //YAHOO.util.Dom.get("home_right").style.height = ((iNumber) + "px");
}

function BtnCheckboxwakfu(oElement)
{

  YAHOO.util.Dom.get("checkbox_wakfu").className = 'btncheckbox off'; 
	
	if (document.getElementById("checkbox_wakfutcg"))
		YAHOO.util.Dom.get("checkbox_wakfutcg").className = 'btncheckbox off'; 
		
	if (document.getElementById("checkbox_wakfuiow"))
		YAHOO.util.Dom.get("checkbox_wakfuiow").className = 'btncheckbox off'; 	
	
	if (document.getElementById("checkbox_wakfuserie"))
		YAHOO.util.Dom.get("checkbox_wakfuserie").className = 'btncheckbox off'; 
	
  YAHOO.util.Dom.get("checkbox_ankama").className = 'btncheckbox off'; 
  YAHOO.util.Dom.get("checkbox_all").className = 'btncheckbox off';
  oElement.className = 'btncheckbox'; 
  var aName = oElement.id.split('_');
	
	
  if (document.getElementById("news_wakfutcg"))
		YAHOO.util.Dom.get("news_wakfutcg").style.display = "none";
	if (document.getElementById("news_wakfuserie"))
		YAHOO.util.Dom.get("news_wakfuserie").style.display = "none";
	if (document.getElementById("news_wakfuiow"))
		YAHOO.util.Dom.get("news_wakfuiow").style.display = "none";	
		
	YAHOO.util.Dom.get("news_wakfu").style.display = "none";
  YAHOO.util.Dom.get("news_ankama").style.display = "none";
  YAHOO.util.Dom.get("news_all").style.display = "none";
	
  YAHOO.util.Dom.get("news_" + aName[1]).style.display = "block";
  InitializeHeight();
	
}


function ShowConnect()
{
  YAHOO.util.Dom.addClass('sb-container','shadowLogin');
  Shadowbox.open({
    content:    YAHOO.util.Dom.get('connect_html').innerHTML,
    player:     "html",
    height:     340,
    width:      452,
    options :
      {
        animate: false,
        displayNav: false,
        enableKeys : false,
        onClose : function() {YAHOO.util.Dom.removeClass('sb-container', 'shadowLogin')}
      }

  });
}




















function ChangeLang(iVar)
{
  aLi = YAHOO.util.Dom.getElementsByClassName("content_menu_lang", 'li');
  //trace(aLi);
  var iLangNone = 0;
  for(i = 0; i < aLi.length; i++)
  {
    if(aLi[i].style.display == "none")
      iLangNone = i;
    aLi[i].style.display = "none";
  }
  var iSomme = iLangNone + 3;
  for(i = iLangNone; i < iSomme; i++)
  {
    if(i >= aLi.length)
      aLi[i - 3].style.display = "block";
    else
      aLi[i].style.display = "block";
  }

}

