/**
* Tommy Brière
* Javascript du navigateur d'oeuvres
**/
ressourcesTextes.add([["pvp.oeuvrenav_msg_attente","Terminez une action avant d'en entreprendre une autre."],["pvp.oeuvrenav_precedente","Œuvre précédente"],["pvp.oeuvrenav_suivante","Œuvre suivante"],["pvp.oeuvrenav_erreur_interne","Une erreur interne s'est produite."]]);

YAHOO.namespace("webtitan.oeuvre");
var infooeuvre;
var artisteId= 0;
YAHOO.webtitan.oeuvre.InfoOeuvre= function(curlangue){
this.INC_VISITE_DELAY= 5000; 
this.oeuvre=0;
this.working=false;
this.curlangue=curlangue;
this.timeIncVisite= null;
this.nbResultat= 0;
this.skipNextSet= false;}
YAHOO.webtitan.oeuvre.InfoOeuvre.prototype.setOeuvre= function(oeuvre){
if(this.checkWork()){
if(this.skipNextSet){
this.skipNextSet= false;
return;}
if(this.timeIncVisite!=null){

clearTimeout(this.timeIncVisite);
this.timeIncVisite= null;}
this.oeuvre=oeuvre;
this.actualiser();
if(this.onChangeOeuvre){
this.onChangeOeuvre();}}}
YAHOO.webtitan.oeuvre.InfoOeuvre.prototype.acheterOeuvre= function(){}

YAHOO.webtitan.oeuvre.InfoOeuvre.prototype.checkWork= function(){
if(this.working){
alert(_TR("pvp.oeuvrenav_msg_attente" ,"Attendez que l'action actuelle se termine avant d'en commencer une autre..."));
return false;} else{
return true;}}

YAHOO.webtitan.oeuvre.InfoOeuvre.prototype.actualiser= function(){
if(this.checkWork()){
if(this.oeuvre>0){
working=true;
var sUrl= "/plugin.php";
var callback={
success: this.oeuvreReceived,
failure: this.echecAction,
argument:[this]};
var postData= "&plugin=oeuvre&action=getInfo&oeuvreid="+this.oeuvre+"&langue="+this.curlangue;
if(this.supInfoParams){
postData+=this.supInfoParams;}
YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);} else{
var html='';
html+= '<div id="oeuvre">';
html+= '  <div class="wrapper">';
html+= '    <table cellspacing="0">';
html+= '  <thead class="top"><td colspan="4"></td></thead>';
html+= '  <tr>';
html+= '    <td colspan="3" class="oeuvre">';
html+= '</td>';
html+= '<td class="infos">';
html+= '    <tr class="nav">';
html+= '    <td><a id="btnOeuvrePrecedente" class="precedent">'+ _TR("pvp.oeuvrenav_precedente" ,"Oeuvre précédente")+ '</a></td>';

html+= '<td><a id="btnOeuvreSuivante" class="suivant">'+ _TR("pvp.oeuvrenav_suivante" ,"Oeuvre suivante")+ '</a></td>';
html+= '<td></td>';
html+= '  </tr>';
html+= '</table>';
html+= '  </div>';
html+= '</div>';
html+= this.actionsBoutons();
html+='</p>'
$("oeuvreInfo").innerHTML= html;
if(this.onApresActualise){
this.onApresActualise();}}}}
YAHOO.webtitan.oeuvre.InfoOeuvre.prototype.actionsBoutons= function(edit){
return "";}

YAHOO.webtitan.oeuvre.InfoOeuvre.prototype.echecAction= function(o){
var io= o.argument[0];
io.working=false;
$("oeuvreInfo").innerHTML= _TR("pvp.oeuvrenav_erreur_interne" ,"Erreur interne ou requète interrompue...");
this.oeuvre=0;}

YAHOO.webtitan.oeuvre.InfoOeuvre.prototype.oeuvreReceived= function(o){
var io= o.argument[0];
io.working=false;
var html= o.responseText;
$("oeuvreInfo").innerHTML= html;

io.timeIncVisite= setTimeout(io.incVisite, io.INC_VISITE_DELAY);
if(io.onApresActualise){
io.onApresActualise();}
if(myLightbox){
myLightbox.updateImageList();}
io.updatePrecSuivBtn();
io.updateNavCurOeuvre();
var iurl= $("i_url_oeuvre");
bfTracker._trackPageview('/oeuvre/'+ encodeURIComponent(iurl.value));
}

YAHOO.webtitan.oeuvre.InfoOeuvre.prototype.updateNavCurOeuvre= function(){
var nav= getFlashMovie("nav_oeuvre_galerie_c");
if(nav){
if(nav.setCurOeuvre){
nav.setCurOeuvre(this.oeuvre);}}}

YAHOO.webtitan.oeuvre.InfoOeuvre.prototype.incVisite= function(){
var io= infooeuvre;
io.timeIncVisite= null;
var sUrl= "/plugin.php";
var callback={


};
var postData= "&plugin=oeuvre&action=incVisite&oeuvreid="+io.oeuvre+"&langue="+io.curlangue;
YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);}

YAHOO.webtitan.oeuvre.InfoOeuvre.prototype.updatePrecSuivBtn= function(){
var pre= $("btnOeuvrePrecedente");
var suiv= $("btnOeuvreSuivante");
var nb= this.nbResultat;
if(nb>1){

pre.style.cursor="pointer";
suiv.style.cursor="pointer";
pre.onclick=oeuvrePrecedente;
suiv.onclick=oeuvreSuivante;
pre.style.color= "#FFF";
suiv.style.color= "#FFF";
pre.style.textDecoration="underline";
suiv.style.textDecoration="underline";

} else{

pre.style.cursor="normal";
suiv.style.curosr="normal";
pre.onclick=null;
suiv.onclick=null;
pre.style.color= "#999";
suiv.style.color= "#999";
pre.style.textDecoration="";
suiv.style.textDecoration="";

}}


function updateAndSetCollections(cid){
var sUrl= "/plugin.php";
var postData= "&plugin=artiste&action=get_collections";
if(artisteId>0){
postData+= "&visiteurid="+artisteId;}
var callback={
success: collectionRecv,
failure: collectionFail,
argument:[cid]};
var input= $("collections");
while(input.options.length>0){
input.remove(0);}
YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);}

function collectionRecv(o){
var cid= o.argument[0];
var sel=-1;
if(o.responseXML){
var input= $("collections");
while(input.options.length>0){
input.remove(0);}
var root= o.responseXML.documentElement;
for(var i=0; i< root.childNodes.length; i++){
var op= document.createElement("option");
var c= root.childNodes[i];
op.value=c.getAttribute("id");
if(op.value==cid){
sel=i;}
var nbitem= c.getAttribute("nbitem");
op.text=c.firstChild.nodeValue+" ("+nbitem+")";
if(YAHOO.env.ua.ie){
input.add(op);} else{
input.add(op, null);}}
if(sel>=0){
input.selectedIndex=sel;}} else{
alert(o.responseText);}
saveCSel(cid);
updateAbtn();}

function saveCSel(cid){
var date= new Date();
date.setTime(date.getTime()+(30*24*60*60*1000));
var cur_collection= "cur_collection="+cid+"; expires="+date.toGMTString()+"; path=/";
document.cookie= cur_collection;}
function collectionFail(o){
}

function oeuvreSuivante(){
naviguer(1);
return false;}

function oeuvrePrecedente(){
naviguer(-1);
return false;}

function naviguer(qt){
var nav= getFlashMovie("nav_oeuvre_galerie_c");
nav.precedentSuivant(infooeuvre.oeuvre,qt);}

function setNbResultat(nb){
infooeuvre.nbResultat= nb;
infooeuvre.updatePrecSuivBtn();}