// JavaScript Document
//A CHANGER LORSQU'ON COPIE DE LA VERISON FRANCAISE: LE ID DU GOOGLE ANALYTICS DANS CHAQUE FONCTION OUVRANT UNE CONTENU

var gameWindow = 0;

/*Cette fonction élimine le popup blocker*/
var mywin;
function openGame(id) {
	var heightIFrame = gameList[id][2];
	
    var width = gameList[id][1];
    var height = gameList[id][2] + 83;
	
	//Vérifie la grandeur de l'écran de l'usager et réduit en conséquence la fenêtre de jeu.
	if(height > screen.availHeight){
		//Si la fenêtre est plus longue que l'écran du joueur
		//Réduit la fenêtre
		height = screen.availHeight -40;
		heightIFrame = height -83; //Réduction hauteur du iFrame
		var top = 0;
	}else{		
   		var top = parseInt((screen.availHeight/2) - (height/2));
	}
	
	if(width > screen.width){
		//Si la fenêtre est plus longue que l'écran du joueur
		//Réduit la fenêtre
		width = screen.width - 20;
		var left = 0;
	}else{		
   		var left = parseInt((screen.availWidth/2) - (width/2));
	}
	

    var windowFeatures = "width=" + width + ",height=" + height +
        ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=" + left + ",top=" + top +
        ",screenX=" + left + ",screenY=" + top;
    mywin = window.open('', id, windowFeatures);
	mywin.focus();
	mywin.document.write('<html>');
	mywin.document.write('<head>');
	mywin.document.write('<title>SGAME FOR SCIENCE - Game</title>');
	mywin.document.write('</head>');
	mywin.document.write('<body style="margin: 0; padding: 0;background-color: #000000;background-image:url(images/entete_jeu.jpg);background-repeat:no-repeat;">');
	mywin.document.write('<div style="margin-top:0px;width:100%;height:83px;">');
	if(gameList[id][3]){
		mywin.document.write('<a href="'+gameList[id][4]+'" title="'+gameList[id][5]+'" alt="'+gameList[id][5]+'" target="_blank" onClick=javascript:pageTracker._trackPageview("'+ gameList[id][7] +'") ><img src="images/'+gameList[id][3]+'" border="0" style="float:right;margin-top:5px;margin-right:20px;"/></a>');
	}
	mywin.document.write('<a href="http://www.creo.ca/en" target="_blank"  title="Visit the Creo inc, game for science Website" alt="Visit the Creo inc, game for science Website" onClick=javascript:pageTracker._trackPageview("hits/creo") ><img src="images/pixel.gif" width="104" height="82" border="0"/></a>');
	mywin.document.write('</div>');
	mywin.document.write('<iframe id="iframegame" src="'+gameList[id][0]+'" width='+width+' height='+heightIFrame+' scrolling=auto frameborder=0></iframe>');
	mywin.document.write('<script type="text/javascript">var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));</script>');
	mywin.document.write('<script type="text/javascript">try { var pageTracker = _gat._getTracker("UA-8973460-1"); pageTracker._trackPageview("'+gameList[id][6]+'");} catch(err) {}</script>');
	mywin.document.write('</body>');
	mywin.document.write('</html>');
}

function update_name(value){
	document.getElementById('avatarName').innerHTML = value;
}


function openVideo(){
	/*Ouvre la pub sur YouTube */
	var d = document.getElementById("openOver");
	d.style.display = "block";	
}



function openVideoStandard(src, video, w, h ) {
	
	var height = h;
	var heightWindow = height + 83;
	
    var width = w;
    var widthWindow = width;
	
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + widthWindow + ",height=" + heightWindow +
        ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=" + left + ",top=" + top +
        ",screenX=" + left + ",screenY=" + top;
	
    mywin = window.open('', "Video", windowFeatures);
	mywin.focus();
	mywin.document.write('<html>');
	mywin.document.write('<head>');
	mywin.document.write('<title>Video</title>');
	mywin.document.write('</head>');
	mywin.document.write('<body style="margin: 0; padding: 0;background-color: #000000;background-image:url(images/entete_jeu.jpg);background-repeat:no-repeat;">');
	mywin.document.write('<div style="margin-top:0px;width:100%;height:83px;">');
	mywin.document.write('<a href="http://www.creo.ca/en" target="_blank"  title="Visit the Creo inc, game for science Website" alt="Visit the Creo inc, game for science Website" onClick=javascript:pageTracker._trackPageview("hits/creo") ><img src="http://www.gameforscience.ca/images/pixel.gif" width="104" height="82" border="0"/></a>');
	mywin.document.write('</div>');
	
	mywin.document.write('<iframe id="iframegame" class="float:right;" src="'+src + "?video=" + video +'" width='+width+' height='+height+' scrolling=no frameborder=0></iframe>');

	mywin.document.write('<script type="text/javascript">var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));</script>');
	mywin.document.write('<script type="text/javascript">try { var pageTracker = _gat._getTracker("UA-8973460-1"); pageTracker._trackPageview("' + src + "?video=" + video + '");} catch(err) {}</script>');
	mywin.document.write('</body>');
	mywin.document.write('</html>');
}

function openURL(url ) {
	var height = screen.availHeight-83;
	var heightWindow = 2000 + 83;
	
    var width = 1050;
    var widthWindow = width;
	
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
	  var windowFeatures = "width=" + widthWindow + ",height=" + heightWindow +
        ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=" + left + ",top=" + top +
        ",screenX=" + left + ",screenY=" + top;
  mywin = window.open('', "ScienceenJeu", windowFeatures);
 	mywin.focus();
	mywin.document.write('<html>');
	mywin.document.write('<head>');
	mywin.document.write('<title>Game for Science</title>');
	mywin.document.write('</head>');
	mywin.document.write('<body style="margin: 0; padding: 0;background-color: #000000;background-image:url(images/entete_jeu.jpg);background-repeat:no-repeat;">');
	mywin.document.write('<div style="margin-top:0px;width:100%;height:83px;">');
	mywin.document.write('<a href="http://www.creo.ca/en" target="_blank"  title="Visit the Creo inc, game for science Website" alt="Visit the Creo inc, game for science Website" onClick=javascript:pageTracker._trackPageview("hits/creo") ><img src="http://www.gameforscience.ca/images/pixel.gif" width="104" height="82" border="0"/></a>');
	mywin.document.write('</div>');
	if(url.search(".pdf") == (url.length-4) )
	{//le contenu est un pdf -> prevoir une largeur pour les menu du pdf
		width-=20;
		height-=100;
	}
	mywin.document.write('<iframe id="iframegame" class="float:right;" src="'+url+'" width='+width+' height='+height+' scrolling=no frameborder=0></iframe>');

	mywin.document.write('<script type="text/javascript">var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));</script>');
	mywin.document.write('<script type="text/javascript">try { var pageTracker = _gat._getTracker("UA-8973460-1"); pageTracker._trackPageview("' + url + '");} catch(err) {}</script>');
	mywin.document.write('</body>');
	mywin.document.write('</html>');
}


function openContactForm(sujet, absolutePath){
	clearWindow(mywin)
	if(absolutePath == null) var absolutePath = "";
	var height = 470 ;
    var width = 488;
    var heightWindow = height+83;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height +
        ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=" + left + ",top=" + top +
        ",screenX=" + left + ",screenY=" + top;
    mywin = window.open('', "Contact", windowFeatures);
	mywin.focus();
	mywin.document.write('<html>');
	mywin.document.write('<head>');
	mywin.document.write('<title>Game for Science - Contact form</title>');
	mywin.document.write('</head>');
	mywin.document.write('<body style="margin: 0; padding: 0;background-color: #000000;">')
	/*mywin.document.write('<div style="margin-top:0px;width:100%;height:83px;">');
	mywin.document.write('<a href="http://www.creo.ca/en" target="_blank"  title="Visit the Creo inc, game for science Website" alt="Visit the Creo inc, game for science Website" onClick=javascript:pageTracker._trackPageview("hits/creo") ><img src="'+absolutePath+'images/pixel.gif" width="104" height="82" border="0" style="float:left;margin-top:5px;margin-left:0px;"/></a>');	
	mywin.document.write('</div>');*/
	mywin.document.write('<iframe id="iframegame" src="'+absolutePath+'contact.php?sujet='+sujet+'" width='+width+' height='+height+' scrolling=no frameborder=0></iframe>');
	mywin.document.write('</body>');
	mywin.document.write('</html>');
}

function openShareForm(absolutePath){
	clearWindow(mywin)
	if(absolutePath == null) var absolutePath = "";
    var height = 640;
	var heightWindow = height + 43;
    var width = 659;

    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + heightWindow +
        ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=" + left + ",top=" + top +
        ",screenX=" + left + ",screenY=" + top;
    mywin = window.open('', "Contact", windowFeatures);
	mywin.focus();
	mywin.document.write('<html>');
	mywin.document.write('<head>');
	mywin.document.write('<title>game for science - Spread the word</title>');
	mywin.document.write('</head>');
	mywin.document.write('<body style="margin: 0; padding: 0;background-color: #000000;">')
	/*mywin.document.write('<div style="margin-top:0px;width:100%;height:83px;">');
	mywin.document.write('<a href="http://www.creo.ca" target="_blank"  title="Visitez le site de Creo inc, la science en jeu" alt="Visitez le site de Creo inc, la science en jeu" onClick=javascript:pageTracker._trackPageview("hits/creo") ><img src="'+absolutePath+'images/pixel.gif" width="104" height="82" border="0" style="float:left;margin-top:5px;margin-left:0px;"/></a>');	
	mywin.document.write('</div>');*/
	
	
	mywin.document.write('<iframe id="iframegame" src="'+absolutePath+'spreadtheword.php" width='+width+' height='+height+' scrolling=no frameborder=0></iframe>');
	mywin.document.write('</body>');
	mywin.document.write('</html>');
}

function clearWindow(pWindow){

	if(mywin==null){
		//too bad
	}else{
		//alert("u closed")
		pWindow.close();
	}
}


