/*
This Javascript file manages the rotation of the vacancies on the right side.
It is called by "common.php".
*/


var vacancies_speed = 10000// the vacancies' rotation speed
var k; // "k" will be equal to the number of vacancies.
var c; // "c" will be between 0 and "k-1"
var id_vacancies = new Array(); // to stock the vacancies' ids
var ref_vacancies = new Array(); // to stock the vacancies' reference codes
var title_vacancies = new Array(); // to stock the vacancies' titles
var location_vacancies = new Array(); // to stock the vacancies' locations
var technology_vacancies = new Array(); // to stock the vacancies' technologies
var version_vacancies = navigator.appVersion.substring(0,1);


// The function opens the page "vacancy_selected.php" with "$_SESSION['ref']" as a reference
function pop_description() {
	window.open("vacancy_selected.php", "popup1", "width=1150,top=40,left=40,scrollbars=yes,resizable=yes");
}	
	
	
function randomInt_vacancies(mini, maxi)
	{
		var nb = mini + (maxi+1-mini)*Math.random();
		return Math.floor(nb);
	}
	
	
function StartAnim_vacancies(c, k)
	{
		if (version_vacancies >= 3)	{ // If the version of the browser is recent, we will lauch the turns
			sessionStorage["id"] = id_vacancies[c]; // We keep the id of the vacancy in "sessionStorage['id']"
			// The id "vac" is very important. It will allow to change the content of the <div> tag.
			document.write(			
			"<div onclick=pop_description()>" + 
				"<div id='vac'>" + 
					"<table>" + 
						"<tr>" + 	
							"<td>Job Title:</td><td><strong>" + title_vacancies[c] + "</strong></td>" +  
						"</tr>" + 
						"<tr>" + 	
							"<td>Location:</td><td><strong>" + location_vacancies[c] + "</strong></td>" +  
						"</tr>" + 
						"<tr>" + 	
							"<td>Technology:</td><td><strong>" + technology_vacancies[c] + "</strong></td>" +  
						"</tr>" + 	
						"<tr>" + 
							"<td>Ref Code:</td><td><strong>" + ref_vacancies[c] + "</strong></td>" + 
						"</tr>" + 
					"</table>" +		
				"</div>" + 		
			"</div>"			
			);
			defil_vacancies(k); // We lauch the turns.
		}
		else {
			sessionStorage["id"] = id_vacancies[c];
			document.write(			
			"<div onclick=pop_description()>" + 
				"<div id='vac'>" + 
					"<table>" + 
						"<tr>" + 	
							"<td>Job Title:</td><td><strong>" + title_vacancies[c] + "</strong></td>" +  
						"</tr>" + 
						"<tr>" + 	
							"<td>Location:</td><td><strong>" + location_vacancies[c] + "</strong></td>" +  
						"</tr>" + 
						"<tr>" + 	
							"<td>Technology:</td><td><strong>" + technology_vacancies[c] + "</strong></td>" +  
						"</tr>" + 	
						"<tr>" + 
							"<td>Ref Code:</td><td><strong>" + ref_vacancies[c] + "</strong></td>" + 
						"</tr>" + 	
					"</table>" +		
				"</div>" + 		
			"</div>"
			);
		}
	}
	
	
function defil_vacancies(k)
	{
		if (c == k)	{
			c = 0;
		}
		// We change the content of the tag whose id is "vac".
		// Automatically, it will change the vacancy...
		sessionStorage["id"] = id_vacancies[c];
		document.getElementById('vac').innerHTML = 
		"<div onclick=pop_description()>" + 
			"<div>" + 
				"<table id='vacs'>" + 
					"<tr>" + 	
						"<td>Job Title:</td><td><strong>" + title_vacancies[c] + "</strong></td>" +  
					"</tr>" + 
					"<tr>" + 	
						"<td>Location:</td><td><strong>" + location_vacancies[c] + "</strong></td>" +  
					"</tr>" + 
					"<tr>" + 	
						"<td>Technology:</td><td><strong>" + technology_vacancies[c] + "</strong></td>" +  
					"</tr>" + 	
					"<tr>" + 
						"<td>Ref Code:</td><td><strong>" + ref_vacancies[c] + "</strong></td>" + 
					"</tr>" + 
				"</table>" +		
			"</div>" + 		
		"</div>"
		;						
		tempo3_vacancies = setTimeout("defil_vacancies(k)", vacancies_speed);
		c = c+1;
	}
