// JavaScript Document
var isIE = (navigator.appName == "Microsoft Internet Explorer");
var souris={x:0,y:0};


/* Général */
document.onmousemove = Pos_souris;
function Pos_souris(e)
{
	souris.x=(isIE) ? event.x+document.body.scrollLeft : e.pageX;
	souris.y=(isIE) ? event.y+document.body.scrollTop : e.pageY;
}
function navigateur()
{
	if(isIE)
		return {hauteur: window.innerHeight,
				largeur: window.innerWidth}
	else
		return {hauteur: document.body.clientHeight,
				largeur: document.body.clientWidth}
}
function presentation (tmp, detail)
{
	texte='<span class="page_presentation">';
	if(tmp.Image_src!='non')
		texte+='<img src="../images/'+( (tmp.Image_src && tmp.Image_src!='') ? 'jeux/'+tmp.Id+'.'+tmp.Image_src : 'page/image_absente.gif' )+'">'+'<br />';
	texte+=''+tmp.Nom+'';
	if(tmp.Editeur && tmp.Editeur!='')
		texte+='<br />Editeur : '+tmp.Editeur;
	texte+='<br />Prix : ';
	if(tmp.Prix==tmp.PrixBaseTTC)
		texte+=tmp.Prix+' &euro;';
	else
		texte+='<font class="promo1">'+tmp.Prix+' &euro;</font> <font class="promo2">('+tmp.PrixBaseTTC+'&nbsp;&euro;)</font>';
	texte+='</span>';
	if(detail)
	{
		texte+='<table class="bulle_tbl" align="center"><tr><td nowrap><img src="../images/page/age.gif" width="30" /><br />';
		texte+=(tmp.Agemini>0) ? tmp.Agemini+' ans et +' : '&nbsp;';
		texte+='</td><td><img src="../images/page/nbr.gif" width="30" /><br />';
		texte+=(tmp.Nbrejoueursmini>0 && tmp.Nbrejoueursmini!=tmp.Nbrejoueursmaxi) ? tmp.Nbrejoueursmini+' ' : '&nbsp;';
		texte+=(tmp.Nbrejoueursmaxi>0) ? '&agrave; '+tmp.Nbrejoueursmaxi+' j': '&nbsp;';
		texte+='</td><td><img src="../images/page/duree.gif" width="30" /><br />';
		texte+=(tmp.Duree>0) ? tmp.Duree+' min' : '&nbsp;';
		texte+='</td></tr></table>';
	}
	return texte;
}

/* Nouv / Promo */
listes={jeux:new Array(2),
		actuels:new Array(1,1),
		divs:new Array(2),
		liens:new Array(false,false),
		intervals:new Array(2),
		duree:4000,
		defile: function (type)
		{
			if(listes.jeux[type].length>1)
			{
				listes.intervals[type]=setInterval("listes.masquer("+type+")",60);
				listes.divs[type].style.opacity=1;
			}
		},
		nouveau:function (type)
		{
			id=Math.floor(Math.random() * (listes.jeux[type].length-1))
			id=(id>=listes.actuels[type]) ? id+1 : id;
			listes.actuels[type]= id;
			jeu=listes.jeux[type][id];
			if(listes.liens[type])
				listes.divs[type].href=listes.liens[type].replace('{}',jeu.Id);
			listes.divs[type].innerHTML=presentation(jeu);
		},
		masquer: function (type)
		{
			obj=listes.divs[type];
			if(obj.style.opacity<=0)
			{
				clearInterval(listes.intervals[type]);
				listes.nouveau(type);
				listes.intervals[type]=setInterval("listes.afficher("+type+")",60);
			}
			else
			{
				i=parseFloat(obj.style.opacity);
				obj.style.opacity=(i-0.125);
				obj.style.filter="alpha(opacity="+(i*100-12.5)+")";
			}
		},
		afficher: function (type)
		{
			obj=listes.divs[type];
			if(obj.style.opacity>=1)
			{
				clearInterval(listes.intervals[type]);
				setTimeout("listes.defile("+type+")",listes.duree);
			}
			else
			{
				i=parseFloat(obj.style.opacity);
				obj.style.opacity=(i+0.125);
				obj.style.filter="alpha(opacity="+(i*100+12.5)+")";
			}
		}
	};


/* Catalogue */
bulle={ afficher: function (tmp,so)
		{
			obj=document.getElementById("page_bulle");
			obj.style.display = "block";
			obj.innerHTML = presentation (tmp,true);
			bulle.placer();
			so.onmousemove= bulle.placer;
			so.onmouseout= bulle.masquer;		
		},
		texte: function (texte,so)
		{
			obj=document.getElementById("page_bulle");
			obj.style.display = "block";
			obj.innerHTML = texte;
			bulle.placer();
			so.onmousemove= bulle.placer;
			so.onmouseout= bulle.masquer;
		},
		masquer: function ()
		{
			obj=document.getElementById("page_bulle");
			obj.style.display = "none";
			obj.style.left = '';
			obj.style.top = '';
		},
		placer: function ()
		{
			obj=document.getElementById("page_bulle");
			obj.style.left = (souris.x+10);
			h=obj.offsetHeight;
			e=navigateur().hauteur + document.body.scrollTop - souris.y - obj.offsetHeight - 15;
			obj.style.top = ((e>=0) ? souris.y+15 : souris.y-h-20);
		}
	}

function nbrjoueur (obj) {
	var tmp=obj.parentNode.childNodes;
	for(i=0;i<tmp.length;i++)
	{
		if(tmp[i].name && tmp[i].name=='nbr2')
			var obj2=tmp[i];
	}
	var val=parseFloat(obj.options[obj.selectedIndex].value);
	if(val>0)
	{
		obj2.className='';
		tmp=obj2.options;
		cpt=0;
		for(i=0;i<tmp.length;i++)
		{
			if(parseFloat(tmp[i].value)>val)
				tmp[i].className = '';
			else
			{
				tmp[i].className = 'cacher';
				cpt=i+1;
			}
		}
		if(obj2.selectedIndex<cpt)
			obj2.selectedIndex=cpt;
	}
	else
	{
		obj2.className='cacher';
	}
}

	
/* Boutique */
function change_image(obj)
{
	document.getElementById("photosboutique").src=obj.src.replace('vignettes/','grandes/');
}

function change_defil (id,vitesse,cote) 
{
	document.getElementById("cadre_"+id).scrollAmount=vitesse;
	if(cote)
		document.getElementById("cadre_"+id).direction=cote;
}