﻿var url;
var nbArticles ;
var rubCur;
var listUrl = new Array ();
var reg=new RegExp("[&]+", "g");
var roots = new Array();
var pos;
var urlArtCur;
var nomRub;
//var img= new RegExp ("[]","g");

$(document).ready(function(){

//placer au centre
var _global= document.body.clientHeight;
var _ie= document.body.offsetHeight;
//alert (_ie);

var _table = $("#myTable").height();

var _newTop = (_global - _table) / 2;
if ((_global > _table) &&  (_global > window.screen.availHeight) )
{
$("#myTable").css({'margin-top':_newTop });
var _goodiesTop =  $("#goodies").offset();
var tmpStr = _goodiesTop.top + _newTop;
//$("#goodies").css({'top': tmpStr  });

}

//alert(_global+";"+ _table +";"+ window.screen.availHeight);
//console.log(_global+";"+ _table +";"+ window.screen.availHeight);

//console.log(_global.toString() +";");
//console.log(";"+_table.toString());
//console.log(";"+_newTop.toString());

//fin placer au centre

url=window .location.search;
urlArtCur=$("#urlArticle").val();
roots = url.split(reg);
nbArticles = $("#total").val();
rubCur=$("#rub").val();
   
     getArticles();
     
//Assigner l'image rouge pour le lien de la rubrique en cours
//le nom de l'image doit absolument être le même que celui de la rubrique
//expl : rubrique = poupees ; <img src="xxx/poupees.jpg" id="poupees" /> ; nom de l'image survol : poupee_over.jpg
nomRub = roots[0].substring(roots[0].indexOf("-")+1,roots[0].lastIndexOf("-"));
$("#"+nomRub).attr({src : "images/"+nomRub+"_over.jpg"});

 var x=0;
 while(x< listUrl.length )
 {
	/* console.log(listUrl[x].value +";"+urlArtCur);*/
  if (listUrl[x].value==urlArtCur)
  {
	  pos=x;
	 
	  }
 x++;
 }
 giveUrl();
 });
function getArticles()
{
listUrl  =$(".compteur");
///console.log("NB articles : "+listUrl);
}
///
///recupere les id articles + url à donner aux boutons "main"
///
function giveUrl()
{
	 ///console.log("nb articles : position : "+nbArticles +";"+pos); 
$("#droite").attr({href:roots[0]+"&debut_articles="+(pos+1).toString()+"#pagination_articles"});
$("#gauche").attr({href:roots[0]+"&debut_articles="+(pos-1).toString()+"#pagination_articles"});
if (pos<=0)$("#gauche").css({'enabled':'false' ,'display':'none'});
if (pos+1>=nbArticles)$("#droite").css({'enabled':'false' ,'display':'none'});
}

function mouse_over(val)
{
if(val=="goodies"){
$("#"+val).attr({src : "images/goodies-rouge.png"});
}
else if (val==nomRub){/*console.log(val +";"+nomRub)*/}
else {$("#"+val).attr({src : "images/"+val+"_over.jpg"});}

}
function mouse_out(val)
{
if(val=="goodies"){
$("#"+val).attr({src : "images/goodies.png"});
}
else if (val==nomRub){/*console.log(val +";"+nomRub)*/}
else 
 {$("#"+val).attr({src : "images/"+val+".jpg"}
 );}

}
