/*
-----------------------------------
Footer
-----------------------------------
*/
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;
}

function setFooter() {
if (document.getElementById) {
var windowHeight=getWindowHeight();
if (windowHeight>0) {
var contentHeight=document.getElementById('frameCenter').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';
}
}
}
}



/* ---------------------------------- */
/* 3.. Visibility switch              */
/* Switch Div or Tr visible/invisible */

function switchDivAdv(div_id, div_id_off) {
	
	var style_sheet;
	var div_id_array = div_id_off.split(",");
  
	for (var i=0; i<div_id_array.length; i++) {

		style_sheet = getStyleObject(div_id_array[i]);
		
	  if (!style_sheet){
			alert("Sorry, this only works in browsers that do Dynamic HTML");
		} 
		else {
			changeObjectVisibility(div_id_array[i], "none");
			changeObjectVisibility(div_id, "block");
	  	}
	  	  	
	  } 
	}
	  	
 	































/*
-----------------------------------
Menu List page change
-----------------------------------
*/

function LoadComm(page){

	if (page != ""){

		window.location.replace("http://www.ffic.ca/" +page);
	
	}

}




/*
-----------------------------------
Menu List page change with no nav break
-----------------------------------
*/
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}


/*
-----------------------------------
Left pannel Perfect As banniere Image Randomisator Class
-----------------------------------
*/
function ImgRand ( albumPath, imgs_path, imgs_title, imgTagBaseID )
{
	this.albumPath =albumPath;				//le root des images
	this.imgs_path =imgs_path;				//la liste des images
	this.imgs_title = imgs_title;			//la liste des titres des images
	this.imgTagBaseID =imgTagBaseID;
	this.divTagBaseID = "div_"+imgTagBaseID;
	this.imgHTML_list =new Array();			//la liste des img HTML
	this.div_list =new Array();
	this.usedImgs_list =new Array();		//la liste des images déjà utilisé pour chaque img HTML
	nbUsedImgs =0;

	//alert(this.imgs_title[0]);


	/*
		Fonction qui ajoute un objet HTML img dans la liste imgHTML_list
		
		Entrees:	id du img que l'on veut ajouter a l'objet
		Sorties:	void
	*/
	this.setImgsObjListByNb =function( nbImgs )
	{
		for ( var i=0; i<nbImgs; i++ )
		{
			this.addImgObjByID( this.imgTagBaseID+(i+1) );
			this.addDivObjByID( this.divTagBaseID+(i+1) );
		}
	}

	/*
		Fonction qui ajoute un objet HTML img dans la liste imgHTML_list
		
		Entrees:	id du img que l'on veut ajouter a l'objet
		Sorties:	void
	*/
	this.addImgObjByID =function( ID )
	{
		imgHTML =document.getElementById(ID);
		
		if ( imgHTML != null && this.imgHTML_list.indexOf(imgHTML) == -1 )
		{
			this.imgHTML_list[this.imgHTML_list.length] =imgHTML;
			this.usedImgs_list[this.usedImgs_list.length] =new Array();
		}
	}
	this.addDivObjByID =function( ID )
	{
		div =document.getElementById(ID);
		
		if ( div != null && this.div_list.indexOf(div) == -1 )
		{
			this.div_list[this.div_list.length] =div;
		}
	}
	
	/*
		Fonction qui randomise une img HTML
		
		Entrees:	id de l'img HTML qui se trouve dans imgHTML_list (entrez -1 pour randomiser toutes les img HTML de la liste);
		Sorties:	void
	*/
	this.showImage =function( ID )
	{
		ID = typeof(ID) != 'undefined' ? ID : "-2";
		
		var imgIDList =new Array();
		
		if ( ID == "-1" )
		{
			imgIDList.length =this.imgHTML_list.length;
			for ( var i=0; i<imgIDList.length; i++ )
			{
				imgIDList[i] =i;
			}
		} else
		{
			imgHTML =document.getElementById(ID);
			
			if ( imgHTML != null && this.imgHTML_list.indexOf(imgHTML) != -1 )
			{
				imgIDList.length =1;
				imgIDList[0] =this.imgHTML_list.indexOf(imgHTML);
			}
		}
		
		for ( var i=0; i<imgIDList.length; i++ )
		{
			imgPos =this.getRandImgPos( imgIDList[i] );
			img = this.imgs_path[imgPos];
			title = this.imgs_title[imgPos];
			//alert(title);

			if ( img != "" )
			{
				this.imgHTML_list[imgIDList[i]].src =this.albumPath + img;
			}
			this.div_list[imgIDList[i]].innerHTML =title;
		}
	}	
	
	/*
		Fonction qui cherche aleatoirement une image dans imgs_path
		
		Entrees:	imgID de l'img HTML dans imgHTML_list
		Sorties:	void
	*/
	this.getRandImgPos =function( imgID )
	{
		var imgPos =Math.floor(Math.random()*10000) %this.imgs_path.length;
		var usedImgs =("," + this.usedImgs_list.join(",") + ",");
		
		while ( usedImgs.indexOf((","+imgPos+",")) != -1 )
		{
			if( nbUsedImgs >= this.imgs_path.length )
			{
				for ( var i=0; i<this.usedImgs_list.length; i++ )
				{
					this.usedImgs_list[i][0] =this.usedImgs_list[i][this.usedImgs_list[i].length -1];
					this.usedImgs_list[i].length =1;
				}
				nbUsedImgs =this.usedImgs_list.length;
				usedImgs =("," + this.usedImgs_list.join(",") + ",");
			}

			imgPos =Math.floor(Math.random()*10000) %this.imgs_path.length;
		}

		this.usedImgs_list[imgID][this.usedImgs_list[imgID].length] =imgPos;
		nbUsedImgs++;
		return imgPos;
	}
	
	/*this.getRandImgIndx =function( imgID )
	{
		var imgPos =Math.floor(Math.random()*10000) %this.imgs_path.length;
		var usedImgs =("," + this.usedImgs_list.join(",") + ",");
		
		while ( usedImgs.indexOf((","+imgPos+",")) != -1 )
		{
			if( nbUsedImgs >= this.imgs_path.length )
			{
				for ( var i=0; i<this.usedImgs_list.length; i++ )
				{
					this.usedImgs_list[i][0] =this.usedImgs_list[i][this.usedImgs_list[i].length -1];
					this.usedImgs_list[i].length =1;
				}
				nbUsedImgs =this.usedImgs_list.length;
				usedImgs =("," + this.usedImgs_list.join(",") + ",");
			}

			imgPos =Math.floor(Math.random()*10000) %this.imgs_path.length;
		}

		this.usedImgs_list[imgID][this.usedImgs_list[imgID].length] =imgPos;
		nbUsedImgs++;
		return this.imgs_path[imgPos];
	}*/
}





/*
-----------------------------------
Switch divs to visible or invisible
-----------------------------------
*/

function switchDiv(div_id) {
	/*Good for one or a known number of divs*/
	
	
	
	var style_sheet;
	var div_id_array = div_id.split(",");
  
	for (var i=0; i<div_id_array.length; i++) {

		//alert (div_id_array.length);
		//alert (eval("div_id_array[i]"));
		//alert (div_id_array[i]);

		style_sheet = getStyleObject(div_id_array[i]);

		/*
		If the style is defined in the .css file, the first state will always be "". if the style is given in the HTML then js will read the style.dispaly correctly. 
		In this case, if the display is in the .css file, display:none elements will be shown and blocks will be left visible. Then on the second click, JS can read the proper
		property and do it's action properly block to none and none to block. The first click is "" to block.
		Putting display:block in inline css will make them disapear on the first click because js can read that properly instead of reading "" 
		*/
		//alert (style_sheet.display);		
  	

		if (!style_sheet){
			alert("Sorry, this only works in browsers that do Dynamic HTML");
		} else {
			if (style_sheet.display != "block" ){
				changeObjectVisibility(div_id_array[i], "block");
			}else{
				changeObjectVisibility(div_id_array[i], "none");
	  		}
		} 
		
	
	}

}

function changeObjectVisibility(objectId, newDisplay) {
	var styleObject = getStyleObject(objectId);
	if (styleObject) {
		styleObject.display = newDisplay;
		return true;
	} else {
		return false;
	}
}	

function getStyleObject(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	}
	else if (document.all && document.all(objectId)) {  
		return document.all(objectId).style;
	} 
	else if (document.layers && document.layers[objectId]) { 
		return document.layers[objectId];
	} else {
		return false;
	}
}





/*
-------------------------------------------------
CSS change    Web Site: http://www.seniorennet.be
-------------------------------------------------
*/

// These are the variables; you can change these if you want
var expDays = 9999;  // How many days to remember the setting
var standardStyle = '1'; // This is the number of your standard style sheet; this will be used when the user did not do anything.
var nameOfCookie = 'switchstyle'; // This is the name of the cookie that is used.
var urlToCSSDirectory = 'http://www.ffic.ca/css/'; // This is the URL to your directory where your .css files are placed on your site.  For example: http://www.seniorennet.be/URL_TO_STYLESHEET_DIRECTORY_OF_YOUR_SITE/

// These are the names of your different .css files; use the name exactly as on your Web site
var ScreenCSS_1 = 'fontsize1.css';
var ScreenCSS_2 = 'fontsize2.css';
var ScreenCSS_3 = 'fontsize3.css';


// If you use different .css files for printing a document, you can set these.  If you don't even know what this is, name then everything exactly the same as above.
// So: make then PrintCSS_1 the same as ScreenCSS_1, for example "screen_1.css".
var PrintCSS_1 = 'fontsize1.css';
var PrintCSS_2 = 'fontsize2.css';
var PrintCSS_3 = 'fontsize3.css';


/***********************************************************************************************
	DO NOT CHANGE ANYTHING UNDER THIS LINE, UNLESS YOU KNOW WHAT YOU ARE DOING
***********************************************************************************************/

// This is the main function that does all the work
function switchStyleOfUser(){
	var fontSize = GetCookie(nameOfCookie);
	if (fontSize == null) {
		fontSize = standardStyle;
	}

	if (fontSize == "1") { document.write('<link rel="stylesheet" type"text/css" href="' + urlToCSSDirectory + ScreenCSS_1 + '" media="screen">'); }
	if (fontSize == "2") { document.write('<link rel="stylesheet" type"text/css" href="' + urlToCSSDirectory + ScreenCSS_2 + '" media="screen">'); }
	if (fontSize == "3") { document.write('<link rel="stylesheet" type"text/css" href="' + urlToCSSDirectory + ScreenCSS_3 + '" media="screen">'); }
	

	if (fontSize == "1") { document.write('<link rel="stylesheet" type"text/css" href="' + urlToCSSDirectory + PrintCSS_1 + '" media="print">'); }
	if (fontSize == "2") { document.write('<link rel="stylesheet" type"text/css" href="' + urlToCSSDirectory + PrintCSS_2 + '" media="print">'); }
	if (fontSize == "3") { document.write('<link rel="stylesheet" type"text/css" href="' + urlToCSSDirectory + PrintCSS_3 + '" media="print">'); }


	var fontSize = "";
	return fontSize;
}

var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

// Function to get the settings of the user
function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

// Function to get the settings of the user
function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

// Function to remember the settings
function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

// Function to remove the settings
function DeleteCookie (name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

// This function is used when the user gives his selection
function doRefresh(){
	location.reload();
}

// This will call the main function.  Do not remove this, because otherwise this script will do nothing...
document.write(switchStyleOfUser());








/*
-----------------------------------
Pulldown list
-----------------------------------
*/
startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
 
 
 


/* -------- */
window.onload = function() {

 setFooter(); 
 startList();

}
window.onresize = function() {
  setFooter();
}
