// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
/**
 * Javascript for spip tuning
 *
 * @author     Bertrand Gugger <bertrand@toggg.com>
 * @copyright  2006 bertrand Gugger / toggg
 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
 * @version    CVS: $Id: Exp $
 * @link       http://toggg.com/
 */
function popup(url, titre, hauteur, largeur) {
	var fenetre = open(url, titre,
	   "top=" + Math.round((screen.availHeight-hauteur)/2) +
	   ",left=" + Math.round((screen.availWidth-largeur)/2) +
	   ",width=" + largeur + ",height=" + hauteur +
       ",toolbar=0,location=0,directories=0,status=0,\
        scrollbars=0,copyhistory=0,menuBar=0"); 
    if (fenetre.innerWidth) {
    	fenetre.innerWidth=largeur;
    	fenetre.innerHeight=hauteur;
    } else {
        fenetre.resizeTo(largeur,hauteur);
    }   
    fenetre.focus();
    return fenetre;
}
function jukebox(id, hauteur, largeur) {
    if (!id) {
        id = window.location.search.match(/id_article=(\d+)/);
        if (!id) {
            return;
        }
        id = parseInt(id[1]);
    }
    if (!largeur) {
        largeur = 360;
    }
    if (!hauteur) {
        hauteur = 240;
    }
	var fenjuk = popup('jukebox.php3?id_article=' + id + '&largeur=' + largeur,
	   "jukebox", hauteur, largeur); 
}
/**
 * Diaporama handler
 */
var diaporamas = new Array();
function Diaporama(options)
{
    this.courante = new Object;
    this.target = new Object;
    this.id = diaporamas.length;
    this.timeOut = 3000;
    this.maxH = 0;
    this.maxL = 0;
    for (opt in options) {//alert(opt+':'+options[opt]);
        this[opt] = options[opt];
    }
    diaporamas[this.id] = this;
    this.tabimg = new Array();
    this.length = arguments.length - 1;
    this.maxH = 0;
    this.maxL = 0;
    for (var i = 0; i < this.length; ++i) {
        this.tabimg[i] = new Object;
        this.tabimg[i].src    = arguments[i + 1].src;
        this.tabimg[i].heigth = arguments[i + 1].heigth;
        if (this.tabimg[i].heigth > this.maxH) {
            this.maxH = this.tabimg[i].heigth;
        }
        this.tabimg[i].width  = arguments[i + 1].width;
        if (this.tabimg[i].width > this.maxL) {
            this.maxL = this.tabimg[i].width;
        }
    }
}
Diaporama.prototype.prochaine = function(img, timeOut)
{
    if (!img.id) {
        return;
    }
    if (!timeOut) {
        timeOut = this.timeOut;
    }
    if (typeof(this.courante[img.id]) == 'undefined') {
        this.courante[img.id] = 1;
        this.target[img.id] = img;
    } else {
        this.courante[img.id] = (this.courante[img.id] + 1) % this.length;
    }
    if (!this.tabimg[this.courante[img.id]].loaded) {
        this.tabimg[this.courante[img.id]].loaded = new Image();
        this.tabimg[this.courante[img.id]].loaded.src = this.tabimg[this.courante[img.id]].src;
    }
    this.delai(img.id, timeOut);
}
Diaporama.prototype.delai = function(imgId, timeOut)
{
if (window.location.search.match(/debug=ie6/)) {
    setTimeout(
        new Function('diaporamas[' + this.id + '].putImage("' + imgId + '");'),
        timeOut);
} else {
    setTimeout('diaporamas[' + this.id + '].putImage("' + imgId + '");', timeOut);
}
}
Diaporama.prototype.putImage = function(imgId)
{
    if (!this.tabimg[this.courante[imgId]].loaded.complete) {
if (window.location.search.match(/debug=complete/)) {
    alert('image pas complete');
}
        this.delai(imgId, 100);
        return;
    }
    with (this.target[imgId]) {
        src = this.tabimg[this.courante[imgId]].loaded.src;
        heigth = this.tabimg[this.courante[imgId]].heigth;
        width = this.tabimg[this.courante[imgId]].width;
        style.marginLeft = ((this.maxL - width ) >> 1) + 'px';
        style.marginTop  = ((this.maxH - heigth) >> 1) + 'px';
    }
    this.prochaine(this.target[imgId]);
}
function retour(href)
{
    if (href) {
        self.opener.location = href;
    }
    self.opener.focus();
    if (!href || href.substring(0, 7) != 'article') {
        self.close();
    }
}

function pixpopup(photo,largeur,hauteur,titre,descriptif)
{
    largeur = largeur + 10;
    hauteur = hauteur + 10;
 	var top=Math.round((screen.availHeight-hauteur)/2);
  	var left=Math.round((screen.availWidth-largeur)/2);
	var deja=open("","fenetre","top="+top+",left="+left+",width="+largeur+",height="+hauteur+
	",toolbar=0,location=0,directories=0,status=0,scrollbars=0,copyhistory=0,menuBar=0"); 
	deja.document.write(
"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html><head><title>"+titre+" (clic pour fermer)</title></he"+"ad><bo"+"dy style='padding:0; border:0; margin:0; background:white;'><div style='width: 100%; height:100%;'><a href='javascript:self.close()'><img src='"+photo+"' style='display:block; margin:auto; border:0; padding:0;' title='clic pour fermer' alt='"+titre+"' /></a></div></b"+"ody></h"+"tml>"
);
	deja.resizeTo(largeur,hauteur);
	deja.innerWidth=largeur;
	deja.innerHeight=hauteur;
	deja.document.close();
    deja.focus();	
}

function popimage(image, titre, largeur, hauteur)
{
//    largeur += 20;
//    hauteur += 20;
	var popimage = popup('', 'popimage', hauteur, largeur);
    popimage.document.open();
    popimage.document.write(
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head>\
<title>' + titre + ' (clic pour fermer)</title></head>\
<body style="cursor:pointer; padding:0; border:none 0; margin:0; background:white;" \
onclick="javascript:self.close();">\
<img src="' + image + '" style="display:block; margin:0; border:none 0; padding:0;" \
width="' + largeur + '" height="' + hauteur + '" title="clic pour fermer" alt="' + titre + '" />\
</body></html>');
    popimage.document.close();
}   

function diapopup(url, largeur, hauteur)
{
	popup(url,"diaporama", hauteur, largeur); 
}   

function coucou(win) {
    win.alert('coucou');
}
