//--------------------------------------------
// Gestion des RollOver sur images
//--------------------------------------------

function MM_swapImgRestore()
{
  var i,x,a=document.MM_sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages()
{
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d)
{
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage()
{
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//--------------------------------------------
// Gestion des cookies (11S_lang, 11S_play)
//--------------------------------------------

function setCookieValue(cookieName, value)
{  
  var expires = new Date(2009, 01, 01);

  document.cookie = cookieName + '=' + escape(value) + '; expires=' + expires.toGMTString();
}

function getCookieValue(cookieName)
{
  var cookieValue = "";	
  var cookies= document.cookie.split(/;/);

  for (var i= 0; i < cookies.length; i++)
  {
    cookies[i] = cookies[i].split(/=/);
    
    if (cookies[i][0] == cookieName)
    {
      cookieValue = cookies[i][1];
      break;
    }
  }
  
  return cookieValue;
}

function CookieRedirect()
{
  var value = getCookieValue("11S_lang");
  
  if (value == "fr")
    window.location.href = "http://www.telequebec.tv/11somerset/flashdetect.html";
  else if (value == "en")
    window.location.href = "flashdetect.html";
  else
  	window.location.href = "langue.html";
}

function PlayCookieRedirect(lang, gameFolder)
{
  var value = getCookieValue("11S_play");
  
  if (value != "")
  	window.location.href = "start_" + lang + ".html";
  else
  	window.location.href = "../configuration_" + lang + ".html?folder=" + gameFolder + "&lang=" + lang;
}

//--------------------------------------------
// Accueil (creation du cookie)
//--------------------------------------------

function Entrer()
{
  setCookieValue("11S_lang", "fr");
  
  window.location.href = "http://www.telequebec.tv/11somerset/flashdetect.html";	
}

function Enter()
{
  setCookieValue("11S_lang", "en");
  
  window.location.href = "flashdetect.html";	
}

//--------------------------------------------
// Afficher ou masquer des elements
//--------------------------------------------

var ie4 = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;

function HideLayer(name)
{
  //if (ie4) {document.all[name].style.visibility = "hidden";}
  if (ns4) {document.layers[name].visibility = "hide";}
  if (ie4 || ns6) {document.getElementById([name]).style.display = "none";}
}

function ShowLayer(name)
{
  //if (ie4) {document.all[name].style.visibility = "visible";}
  if (ns4) {document.layers[name].visibility = "show";}
  if (ie4 || ns6) {document.getElementById([name]).style.display = "block";}
}

//--------------------------------------------
// Ouvrir les jeux fullscreen
//--------------------------------------------

var win = null;
function NewWindow(mypage,myname,w,h,scroll)	{
	var width = screen.availWidth-10;
	var height = screen.availHeight-20;
	var specs = "left=0,top=0,screenX=0,screenY=0";  //fullscreen=yes,
	specs += ",width=" + width + ",height=" + height;
	specs += ",scrollbars=no,toolbar=no,menubar=no";
	specs += ",status=no,location=no";
	specs += ",directories=no,resizable=no,alwaysRaised";
	specs += ",innerHeight=" + height+20 + ",innerWidth=" + width;
	var Popup = window.open(mypage, 'popup', specs);
	if (window.focus) {
		Popup.focus()
	}
}

//-----------------------------------------------------------
// Script pour positionner le footer dans Safari et IE/Mac
// http://www.alistapart.com/articles/footers/
//-----------------------------------------------------------
		
// On détermine la hauteur de la fenêtre
function getWindowHeight() {
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number') {
		windowHeight=window.innerHeight;
	}
	else {
		if (document.documentElement&&document.documentElement.clientHeight) {
			windowHeight=document.documentElement.clientHeight;
		}
		else {
			if (document.body&&document.body.clientHeight) {
				windowHeight=document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
		
// On place le footer à la bonne place
function setFooter() {
	if (document.getElementById) {
		var windowHeight=getWindowHeight();
		if (windowHeight>0) {
			var contentHeight=document.getElementById('flash').offsetHeight;
			var footerElement=document.getElementById('footer');
			var footerHeight=footerElement.offsetHeight;
			if (windowHeight-(contentHeight+footerHeight)>=0) {
				footerElement.style.position='relative';
				footerElement.style.top=(windowHeight-(contentHeight+footerHeight))+'px';
			}
			else {
				footerElement.style.position='static';
			}
		}
	}
}

// On place le footer à la bonne place: section Série
function setFooterSerieRel() {
	if (document.getElementById) {
		var windowHeight=getWindowHeight();
		if (windowHeight>0) {
			var contentHeight=document.getElementById('contenuserie').offsetHeight;
			var footerElement=document.getElementById('footer');
			var footerHeight=footerElement.offsetHeight;
			if (windowHeight-(contentHeight+footerHeight)>=0) {
				footerElement.style.position='relative';
				footerElement.style.top=(windowHeight-(contentHeight+footerHeight))+'px';
			}
			else {
				footerElement.style.position='static';
			}
		}
	}
}

// On place le footer à la bonne place: section Série
function setFooterSerie() {
			if (document.getElementById) {
				var windowHeight = getWindowHeight();
				if (windowHeight > 0) {
					var contentHeight = document.getElementById('contenuserie').offsetHeight;
					var footerElement = document.getElementById('footer');
					var footerHeight  = footerElement.offsetHeight;
					if (windowHeight - (contentHeight + footerHeight) >= 0) {
						footerElement.style.position = 'absolute';
						footerElement.style.top = (windowHeight - footerHeight) + 'px';
					}
					else {
						footerElement.style.position = 'static';
					}
				}
			}
		}

// On place le footer à la bonne place: section Jeu
function setFooterJeu(elementName) {
			if (document.getElementById) {
				var windowHeight = getWindowHeight();
				if (windowHeight > 0) {
					var contentHeight = document.getElementById(elementName).offsetHeight;
					var footerElement = document.getElementById('footer');
					var footerHeight  = footerElement.offsetHeight;
					if (windowHeight - (contentHeight + footerHeight) >= 0) {
						footerElement.style.position = 'absolute';
						footerElement.style.top = (windowHeight - footerHeight) + 'px';
					}
					else {
						footerElement.style.position = 'static';
					}
				}
			}
		}

//-----------------------------------------------------------
// Ouverture des fenêtres d'entrvues et d'effets spéciaux
//-----------------------------------------------------------

leftPos=0
if (screen) {
	leftPos=(screen.width-800)/2
}

topPos=0
if (screen) {
	topPos=(screen.height-600)/2
}

function openEntrevue(theURL)	{
	MM_openBrWindow(theURL,'video','width=800,height=600,left='+leftPos+',top='+topPos+'')
}

//-----------------------------------------------------------
// Permet de lire les parametres passes dans le URL
//-----------------------------------------------------------

function getQueryVariable(variable) 
{
   	var query = window.location.search.substring(1);
   	var vars = query.split("&");
    
   	for (var i=0;i < vars.length; i++) 
   	{
       	var pair = vars[i].split("=");
    
       	if (pair[0] == variable) 
       	{
           	return unescape(pair[1]);
       	}
   	}
}

//-----------------------------------------------------------
// Empêche l'inclusion du site dans un IFRAME
//-----------------------------------------------------------

if (self.location != parent.location){
	parent.location.href="http://www.11somerset.com/";
}