
var widgetRuning = 0;
function widget(){
if(widgetRuning==0){
 widgetRuning = 1;
	window.location="#";
/* document.getElementsByTagName('body')[0].style.opacity = "0.5";*/
 Div = document.createElement('div');
	Div.id = "masque";
	Div.style.opacity = "0.7";
	Div.style.position = "absolute";
	Div.style.zIndex = "90";
	Div.style.backgroundColor = "#FFF";
	Div.style.width = "100%";
	Div.style.height = "100%";
	Div.style.top = "0px";
	Div.style.left = "0px";
 Div.setAttribute("onmousedown","endwidget()");	
	document.getElementsByTagName('body')[0].appendChild(Div);
	

	/*Calendrier*/
 calendar.init('');
	document.getElementById('calendar').style.zIndex = 99; 
	document.getElementById('calendar').style.top = '20px'; 
	document.getElementById('calendar').style.cursor = "move";
	document.getElementById('calendar').style.left = '500px'; 
 
	/*Calculatrice*/
 Div = document.createElement('div');
	Div.style.backgroundColor= "#FCF";
	Div.style.border= "solid 2px #F9F";
	Div.style.position = "absolute";
	Div.style.MozBorderRadius = "10px";
	Div.style.zIndex = 91;
	Div.style.padding = "15px";
	Div.style.top = "40px";
	Div.style.left = "20px";
	Div.id = "calcul";
	Div.style.cursor = "move";
 Div.setAttribute("onmousedown","widgetClic('calcul')");	
 Div.setAttribute("onmouseup","widgetClic(0)");	
	Div.innerHTML = '<h1 align="center" >Calculatrice</h1><br /><iframe id="iframecalcul" onmousedown=widgetClic("iframecalcul"); onmouseup="widgetClic(0);" width="260px" height="410px" style="overflow:hidden;border:none" src="'+ makeUrl('include/widget/calcul.php')+'"></iframe>';
	document.getElementsByTagName('body')[0].appendChild(Div);

 /*Calepin*/
 Div = document.createElement('div');
	Div.style.backgroundColor= "#CCF";
	Div.style.border= "solid 2px #99F";
	Div.style.position = "absolute";
	Div.style.MozBorderRadius = "10px";
	Div.style.zIndex = 91;
	Div.style.padding = "15px";
	Div.style.cursor = "move";
	Div.style.top = "5px";
	Div.style.left = "800px";
	Div.id = "calepin";
 Div.setAttribute("onmousedown","widgetClic('calepin')");	
 Div.setAttribute("onmouseup","widgetClic(0)");	
	Div.innerHTML = '<h1 align="center" >Calepin</h1><br /><iframe id="iframeCalepin" width="200px" height="200px" style="overflow:hidden;border:none" src="'+makeUrl('include/widget/calepin.php')+'"></iframe>';
	document.getElementsByTagName('body')[0].appendChild(Div);


	/*meteo*/
 Div = document.createElement('div');
	Div.style.backgroundColor= "#CFC";
	Div.style.border= "solid 2px #9F9";
	Div.style.position = "absolute";
	Div.style.MozBorderRadius = "10px";
	Div.style.zIndex = 91;
	Div.style.padding = "15px";
	Div.style.top = "230px";
	Div.style.cursor = "move";
	Div.style.left = "350px";
	Div.id = "meteo";
 Div.setAttribute("onmousedown","widgetClic('meteo')");	
 Div.setAttribute("onmouseup","widgetClic(0)");	
	Div.innerHTML = '<h1 align="center" >Meteo</h1><br /><iframe width="450px" height="210px" style="overflow:hidden;border:none" src="'+makeUrl('include/widget/meteo.php')+'"></iframe>';
	document.getElementsByTagName('body')[0].appendChild(Div);

 /*PileOuFace*/
 Div = document.createElement('div');
	Div.style.backgroundColor= "#CCC";
	Div.style.border= "solid 2px #999";
	Div.style.position = "absolute";
	Div.style.MozBorderRadius = "10px";
	Div.style.zIndex = 91;
	Div.style.padding = "15px";
	Div.style.top = "360px";
	Div.style.cursor = "move";
	Div.style.left = "840px";
	Div.id = "hasard";
 Div.setAttribute("onmousedown","widgetClic('hasard')");	
 Div.setAttribute("onmouseup","widgetClic(0)");	
	Div.innerHTML = '<h1 align="center" >Pileouface</h1><br /><div style="width:100%;align:center" align="center"><div id="pileouface" style="background:#ccc url('+makeUrl('include/widget/images/pileouface.png')+') no-repeat;font-size:90px;color:#ccc;height:135px;width:135px;" onmouseover="changeface(5)">?</div></div>';
	document.getElementsByTagName('body')[0].appendChild(Div);






}else{
endwidget();
}

}

var moveWidget=0;
var moveWidgetObj=null;
var Xrel = 0;
var Yrel = 0;

function widgetClic(id){
 moveWidget = id;
	if(id!=0){
  moveWidgetObj = document.getElementById(id);
  Xrel = cursor.x - parseInt(moveWidgetObj.style.left);
  Yrel = cursor.y - parseInt(moveWidgetObj.style.top);	
	}
}

function MOUSEwidget(x,y){
 if(moveWidget!=0){
  moveWidgetObj.style.left = parseInt(x - Xrel ) +'px';
  moveWidgetObj.style.top = parseInt(y - Yrel ) +'px';
 }
}

function endwidget(){
 removeId('masque');
 removeId('calendar');
 removeId('calcul');
 removeId('calepin');
 removeId('meteo');
 removeId('hasard');
	widgetRuning = 0;
}


function changeSizeY(id,y){
 document.getElementById(id).style.height = y+'px';
}




function changeface(nbr){
 document.getElementById("pileouface").style.background = "#ccc url('"+makeUrl("include/widget/images/pileouface.png")+"') no-repeat";
 if(nbr==0){
  changepile();
 }else{
  document.getElementById("pileouface").innerHTML = nbr;
  nbr--;
  setTimeout("changeface("+nbr+");",500);
 }
}

function changepile(){
 if(Math.random(10)<(5/10)){
  document.getElementById("pileouface").style.background = "#ccc url('"+makeUrl("include/widget/images/face.png")+"') no-repeat";
  document.getElementById("pileouface").innerHTML = "F";
 }else{
  document.getElementById("pileouface").style.background = "#ccc url('"+makeUrl("include/widget/images/pile.png")+"') no-repeat";
  document.getElementById("pileouface").innerHTML = "P";
 }
}

