var _div_1;
var _div_2;
var _div_3;
var _div_contain_height = 0;
var _div_height = 0;
var _page = 0;
var _nb_page = 0;
var _fontSize = 12;
var _line_height = 15;
var _img_height = 0;
var _contain_height;
var _nb_cols = 3;

/** prechargement des images **/
detpic1= new Image(12,12);
detpic1.src="im/detail_1_colonne.gif";
detpic2= new Image(12,12);
detpic2.src="im/detail_3_colonne.gif";

function detail_news_to_one_col()
{
  _nb_cols = 1;
  _page = 0;

  var widt = document.getElementById('detail_news_container').offsetWidth;
  document.getElementById('detail_news_contain_2').style.display = "none";
  document.getElementById('detail_news_contain_3').style.display = "none";
  document.getElementById('detail_news_contain_1').style.width = widt+"px";


  detail_news_reinit_all();
}

function detail_news_to_three_col()
{
  _nb_cols = 3;
  _page = 0;

  document.getElementById('detail_news_contain_2').style.display = "";
  var widt = document.getElementById('detail_news_contain_2').offsetWidth;
  document.getElementById('detail_news_contain_3').style.display = "";
  document.getElementById('detail_news_contain_1').style.width = widt+"px";

  if (document.getElementById('detail_news_img'))
  {
	document.getElementById('detail_news_img').style.cssFloat = "";
	document.getElementById('detail_news_img').style.styleFloat = "";
	/*
    _div_1.getElementsByTagName("DIV")[0].style.cssFloat = "";
    _div_1.getElementsByTagName("DIV")[0].style.styleFloat = "";
	*/
  }
  detail_news_reinit_all();
}


function detail_news_reinit_all()
{
  _page = 0;
  /* remise a la taille des div d'images */

  _div_height = _div_1.offsetHeight;

  /* remise a la taille des div de contenu */
  d_height = _contain_height;
  _div_contain_height = d_height;

  _nb_page = parseInt(_div_height / _div_contain_height / _nb_cols, 10);
  alert("div_height = "+_div_height);
  alert("div_contain_height = "+_div_contain_height);
  alert("nb_page = "+_nb_page);
  var page_txt = "<div style='text-align:left; width:3000px;' id='detailFooterMiddleContain'>";
  for (var i = 0; i <= _nb_page; i++)
  {
    page_txt = page_txt+"<div style='float:left; width:23px;'><a href='javascript:detail_news_goto_page("+i+")' class='detailToolBarLink'>"+(i + 1)+"</a>";
    if (i < _nb_page)
       page_txt = page_txt+"&nbsp;:&nbsp;";
    page_txt = page_txt+"</div>";
  }
  page_txt += "</div>";

  document.getElementById('detailFooterMiddle').innerHTML = page_txt;

  detail_news_goto_page(_page);
}

function detail_news_init()
{
  _div_contain_height = 0;
  _div_height = 0;
  _page = 0;
  _nb_page = 0;
  _fontSize = 12;
  _line_height = 15;
  _contain_height = 0;
  _nb_cols = 1;

  _div_1 = document.getElementById('detail_news_1');
  _div_2 = document.getElementById('detail_news_2');
  _div_3 = document.getElementById('detail_news_3');

  _div_2.style.display = "none";
  _div_3.style.display = "none";

  _div_1.innerHTML = content;
  _div_2.innerHTML = content;
  _div_3.innerHTML = content;

/*
  if (document.getElementById('detail_news_img'))
  {
     _img_height = document.getElementById('detail_news_img_src').offsetHeight + 6;
  }
*/

  _contain_height = document.getElementById('detail_news_contain_1').offsetHeight;
      alert('taille = '+_contain_height);
  /** par default en une colonne **/
  detail_news_to_one_col();

  /*
  if ((_div_1.offsetHeight / 3) <= document.getElementById('detail_news_container').offsetHeight)
     detail_news_to_one_col();
  else
      detail_news_to_three_col();
  */
}

function detail_news_change_page(to)
{
  if (to == 'next' && _page < _nb_page)
     detail_news_goto_page(_page + 1);
  if (to == 'prev' && _page > 0)
     detail_news_goto_page(_page - 1);
}

function detail_news_goto_page(page)
{
  _page = page;
  page = page * _nb_cols;
  var cont_height = (_div_contain_height * 1) - 2;

  var height1 = page * (_div_contain_height) - (page * 2);



//alert("_div_contain_height : "+_div_contain_height+" --- height1 : "+height1);

  _div_1.style.marginTop = "-"+height1+"px";
  _div_2.style.marginTop = "-"+(height1 + cont_height)+"px";
  _div_3.style.marginTop = "-"+(height1 + (2*cont_height))+"px";

  _div_2.style.display = "";
  _div_3.style.display = "";

  var page_left = ((_page - 1) * 23) - 60;
  if (page_left < 0)
	page_left = 0;
  document.getElementById('detailFooterMiddleContain').style.marginLeft = "-"+page_left+"px";
}

function detail_news_text_small()
{
  if (_fontSize >= 10)
  {
     _fontSize--;
     //_line_height = _fontSize + 2;
     _div_1.style.fontSize = _fontSize+"px";
     _div_2.style.fontSize = _fontSize+"px";
     _div_3.style.fontSize = _fontSize+"px";
     detail_news_reinit_all();
  }
}

function detail_news_text_big()
{
  if (_fontSize < 15)
  {
     _fontSize++;
     //_line_height = _fontSize + 2;
     _div_1.style.fontSize = _fontSize+"px";
     _div_2.style.fontSize = _fontSize+"px";
     _div_3.style.fontSize = _fontSize+"px";
     detail_news_reinit_all();
  }
}

function detail_news_set_img_height(hei)
{
  _img_height = (hei * 1);
}

function preloadImages() {
var d=document; if(d.images){ if(!d.p) d.p=new Array();
var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

/*************** affichage des images ***************/
function detail_load_image_in_container(img, type, width, height, texte)
{
  var cont = document.getElementById('detail_img_full_container');
  if (type == 'picture')
  	var str = "<img src='"+img+"' class='detailImgFull' />";
  if (type == 'video')
  {
    var str = "<object type='application/x-shockwave-flash' data='/class/player_flv.swf' width='"+width+"' height='"+height+"'>";
    str += "<param name='movie' value='/class/player_flv.swf' />";
    str += "<param name='FlashVars' value='flv="+img+"&showvolume=1&showtime=1&showstop=1&buttonovercolor=FF0000&autoplay=1&margin=0&loadingcolor=FF0000&sliderovercolor=990000&width="+width+"&height="+height+"&buffer=10' />";
    str += "<param name='wmode' value='transparent' /></object>";
    var mpg = img.substring(0, (img.length - 4));
    str += "<br/><div style='text-align:center;'><a href='"+mpg+"' class='detailImgLink'>T&eacute;l&eacute;charger la vid&eacute;o</a></div>";
  }

  if (type == 'son')
  	var str = "<img src='"+img+"' class='detailImgFull' />";

  if (texte)
  str += "<div style='font:12px verdana; text-align:center; padding:5px;'>"+texte+"</div>";

  document.getElementById('detail_img_full_content').innerHTML = str;
  cont.style.display = "block";
}

function detail_close_div_image()
{
  var cont = document.getElementById('detail_img_full_container');

  cont.style.display = "none";
}

function change_lang(id)
{
  var to = document.getElementById('current_ajax_page').innerHTML;
  document.location = "index.php?"+decodeURIComponent(to)+"&id_lang="+id;
}
