/********************************************************************
* Script will allow user to visually change font size. Font size 
* will persist thru page change using a cookie.
********************************************************************
* Directions: Change fontElementId var to the element id you wish to
* allow users to change font sizes. 
********************************************************************
* Next span element inside normal div to inherit parent style
* but enable use to change font size.
*******************************************************************/

var fontElementId = "main-content"; 
//DO NOT MODIFY BELOW

function setUp(){
	addJavaScriptLinks();
	addKeywordLabel();
	randomImage();
	setDefaultFontSize();
}
function setUpEvent(){
	setUp();
	addEventJavaScriptLink();
}
function setUpEvents(){
	setUp();
	addEventsJavaScriptLink();
}

function randomImage(){
	var generic = document.getElementById('generic-image');
	if (generic) {
		var rnumb = Math.floor(Math.random() * 4) + 1;
		generic.src = "/images/generic" + rnumb + ".jpg";
		switch (rnumb) {
		case 1:
			generic.alt = "OPHA and its partners are working toward a healthier Ontario.";
			break;
		case 2:
			generic.alt = "OPHA and public health professionals across Ontario are working to strengthen our health system.";
			break;
		case 3:
			generic.alt = "OPHA and communities across Ontario are cooperating to bring healthy change to our province.";
			break;
		case 4:
			generic.alt = "OPHA is working with all levels of government to lead the way to a healthier Ontario.";
			break;
		default:
			generic.alt = "";
		}
	}

	var twenty = document.getElementById('random-20');
	if (twenty) {
		var rnumb = Math.floor(Math.random() * 19) + 1;
		switch (rnumb) {
		case 1:
  			twenty.src = "/images/apn.jpg";
			twenty.alt = "OPHA partners with many organizations and individuals in promoting healthy public alcohol policies.";
			twenty.title = "OPHA partners with many organizations and individuals in promoting healthy public alcohol policies";
			break;
		case 2:
  			twenty.src = "/images/arapo.jpg";
			twenty.alt = "OPHA collaborates with public health professionals and community leaders to help Ontarians make responsible choices.";
			twenty.title = "OPHA collaborates with public health professionals and community leaders to help Ontarians make responsible choices";
			break;
		case 3:
  			twenty.src = "/images/awg.jpg";
			twenty.alt = "OPHA and its partners consistently advocate for public health on alcohol-related issues.";
			twenty.title = "OPHA and its partners consistently advocate for public health on alcohol-related issues";
			break;
		case 4:
  			twenty.src = "/images/bfwg.jpg";
			twenty.alt = "OPHA and its partners advocate for public health policies that give Ontario's children a healthy start.";
			twenty.title = "OPHA and its partners advocate for public health policies that give Ontario's children a healthy start";
			break;
		case 5:
  			twenty.src = "/images/cyhwg.jpg";
			twenty.alt = "OPHA and its partners advocate on a wide range of issues related to child and youth health.";
			twenty.title = "OPHA and its partners advocate on a wide range of issues related to child and youth health";
			break;
		case 6:
  			twenty.src = "/images/ehwg.jpg";
			twenty.alt = "OPHA partners with health inspectors, care providers and parents to raise awareness of the impact of environment on children.";
			twenty.title = "OPHA partners with health inspectors, care providers and parents to raise awareness of the impact of environment on children";
			break;
		case 7:
  			twenty.src = "/images/fswg.jpg";
			twenty.alt = "OPHA and its partners are leading programs, and advocating for policies, that promote food security for all Ontarians.";
			twenty.title = "OPHA and its partners are leading programs, and advocating for policies, that promote food security for all Ontarians";
			break;
		case 8:
	  		twenty.src = "/images/generic1.jpg";
			twenty.alt = "OPHA and its partners are working toward a healthier Ontario.";
			twenty.title = "OPHA and its partners are working toward a healthier Ontario";
			break;
		case 9:
  			twenty.src = "/images/generic3.jpg";
			twenty.alt = "OPHA and communities across Ontario are cooperating to bring healthy change to our province.";
			twenty.title = "OPHA and communities across Ontario are cooperating to bring healthy change to our province";
			break;
		case 10:
  			twenty.src = "/images/generic4.jpg";
			twenty.alt = "OPHA is working with all levels of government to lead the way to a healthier Ontario.";
			twenty.title = "OPHA is working with all levels of government to lead the way to a healthier Ontario";
			break;
		case 11:
  			twenty.src = "/images/hflmp.jpg";
			twenty.alt = "OPHA strengthens Ontario's public health workforce by promoting membership.";
			twenty.title = "OPHA strengthens Ontario's public health workforce by promoting membership";
			break;
		case 12:
  			twenty.src = "/images/hhrc.jpg";
			twenty.alt = "OPHA supports Ontario's health professionals, volunteers and community agencies with the skills and knowledge to help prevent cardiovascular disease.";
			twenty.title = "OPHA supports Ontario's health professionals, volunteers and community agencies with the skills and knowledge to help prevent cardiovascular disease";
			break;
		case 13:
  			twenty.src = "/images/keepcontrol.jpg";
			twenty.alt = "OPHA, Health Canada, media and marketing partners and sponsors are promoting safer drinking strategies for Ontario's youth.";
			twenty.title = "OPHA, Health Canada, media and marketing partners and sponsors are promoting safer drinking strategies for Ontario's youth";
			break;
		case 14:
  			twenty.src = "/images/lcche.jpg";
			twenty.alt = "OPHA partners with health inspectors, care providers and parents to raise awareness of the impact of the environment on children.";
			twenty.title = "OPHA partners with health inspectors, care providers and parents to raise awareness of the impact of the environment on children";
			break;
		case 15:
  			twenty.src = "/images/lgbtt12qq.jpg";
			twenty.alt = "OPHA supports programs to ensure sex- and gender-equitable access to public health services.";
			twenty.title = "OPHA supports programs to ensure sex- and gender-equitable access to public health services";
			break;
		case 16:
  			twenty.src = "/images/nrc.jpg";
			twenty.alt = "OPHA develops and promotes nutrition programs and resources to support healthy eating.";
			twenty.title = "OPHA develops and promotes nutrition programs and resources to support healthy eating";
			break;
		case 17:
  			twenty.src = "/images/ocdpa.jpg";
			twenty.alt = "OPHA partners with a network of organizations across Ontario to fight chronic disease.";
			twenty.title = "OPHA partners with a network of organizations across Ontario to fight chronic disease";
			break;
    // case 18:
    //        twenty.src = "/images/board2010.gif";
    //  twenty.alt = "OPHA celebrates 61 years as the Voice of Public Health in Ontario.";
    //  twenty.title = "The OPHA Board of Directors for 2010";
    //  break;
		case 18:
  			twenty.src = "/images/teip.jpg";
			twenty.alt = "OPHA provides tools and training for evidence-informed practice to help prevent chronic disease.";
			twenty.title = "OPHA provides tools and training for evidence-informed practice to help prevent chronic disease";
			break;
		case 19:
	  		twenty.src = "/images/vpwg.jpg";
			twenty.alt = "OPHA partners with communities across the province to make Ontario a safer place to grow up.";
			twenty.title = "OPHA partners with communities across the province to make Ontario a safer place to grow up";
	  		break;
		}
	}

	var eight = document.getElementById('random-8');
	if (eight) {
		var rnumb = Math.floor(Math.random() * 8) + 1;
		switch (rnumb) {
		case 1:
  			eight.src = "/images/generic3.jpg";
			eight.alt = "OPHA and communities across Ontario are cooperating to bring healthy change to our province.";
			eight.title = "OPHA and communities across Ontario are cooperating to bring healthy change to our province";
			break;
		case 2:
  			eight.src = "/images/awg.jpg";
			eight.alt = "OPHA and its partners consistently advocate for public health on alcohol-related issues.";
			eight.title = "OPHA and its partners consistently advocate for public health on alcohol-related issues";
			break;
		case 3:
  			eight.src = "/images/bfwg.jpg";
			eight.alt = "OPHA and its partners advocate for public health policies that give Ontario's children a healthy start.";
			eight.title = "OPHA and its partners advocate for public health policies that give Ontario's children a healthy start";
			break;
		case 4:
  			eight.src = "/images/cyhwg.jpg";
			eight.alt = "OPHA and its partners advocate on a wide range of issues related to child and youth health.";
			eight.title = "OPHA and its partners advocate on a wide range of issues related to child and youth health";
			break;
		case 5:
  			eight.src = "/images/generic4.jpg";
			eight.alt = "OPHA is working with all levels of government to lead the way to a healthier Ontario.";
			eight.title = "OPHA is working with all levels of government to lead the way to a healthier Ontario";
			break;
		case 6:
  			eight.src = "/images/fswg.jpg";
			eight.alt = "OPHA and its partners are leading programs, and advocating for policies, that promote food security for all Ontarians.";
			eight.title = "OPHA and its partners are leading programs, and advocating for policies, that promote food security for all Ontarians";
			break;
		case 7:
  			eight.src = "/images/lgbtt12qq.jpg";
			eight.alt = "OPHA supports programs to ensure sex- and gender-equitable access to public health services.";
			eight.title = "OPHA supports programs to ensure sex- and gender-equitable access to public health services";
			break;
		case 8:
  			eight.src = "/images/vpwg.jpg";
			eight.alt = "OPHA partners with communities across the province to make Ontario a safer place to grow up.";
			eight.title = "OPHA partners with communities across the province to make Ontario a safer place to grow up";
  			break;
		}
	}


	var ten = document.getElementById('random-10');
	if (ten) {
		var rnumb = Math.floor(Math.random() * 10) + 1;
		switch (rnumb) {
		case 1:
  			ten.src = "/images/apn.jpg";
			ten.alt = "OPHA partners with many organizations and individuals in promoting healthy public alcohol policies.";
			ten.title = "OPHA partners with many organizations and individuals in promoting healthy public alcohol policies";
			break;
		case 2:
  			ten.src = "/images/arapo.jpg";
			ten.alt = "OPHA collaborates with public health professionals and community leaders to help Ontarians make responsible choices.";
			ten.title = "OPHA collaborates with public health professionals and community leaders to help Ontarians make responsible choices";
			break;
		case 3:
  			ten.src = "/images/ocdpa.jpg";
			ten.alt = "OPHA partners with a network of organizations across Ontario to fight chronic disease.";
			ten.title = "OPHA partners with a network of organizations across Ontario to fight chronic disease";
			break;
		case 4:
  			ten.src = "/images/hflmp.jpg";
			ten.alt = "OPHA strengthens Ontario's public health workforce by promoting membership.";
			ten.title = "OPHA strengthens Ontario's public health workforce by promoting membership";
			break;
		case 5:
  			ten.src = "/images/hhrc.jpg";
			ten.alt = "OPHA supports Ontario's health professionals, volunteers and community agencies with the skills and knowledge to help prevent cardiovascular disease.";
			ten.title = "OPHA supports Ontario's health professionals, volunteers and community agencies with the skills and knowledge to help prevent cardiovascular disease";
			break;
		case 6:
  			ten.src = "/images/oiprc.jpg";
			ten.alt = "OPHA equips Ontario's injury prevention practitioners with knowledge, skills and confidence in implementing injury prevention initiatives.";
			ten.title = "OPHA equips Ontario's injury prevention practitioners with knowledge, skills and confidence in implementing injury prevention initiatives";
			break;
		case 7:
  			ten.src = "/images/keepcontrol.jpg";
			ten.alt = "OPHA, Health Canada, media and marketing partners and sponsors are promoting safer drinking strategies for Ontario's youth.";
			ten.title = "OPHA, Health Canada, media and marketing partners and sponsors are promoting safer drinking strategies for Ontario's youth";
			break;
		case 8:
  			ten.src = "/images/lcche.jpg";
			ten.alt = "OPHA partners with health inspectors, care providers and parents to raise awareness of the impact of the environment on children.";
			ten.title = "OPHA partners with health inspectors, care providers and parents to raise awareness of the impact of the environment on children";
			break;
		case 9:
  			ten.src = "/images/nrc.jpg";
			ten.alt = "OPHA develops and promotes nutrition programs and resources to support healthy eating.";
			ten.title = "OPHA develops and promotes nutrition programs and resources to support healthy eating";
			break;
		case 10:
  			ten.src = "/images/teip.jpg";
			ten.alt = "OPHA provides tools and training for evidence-informed practice to help prevent chronic disease.";
			ten.title = "OPHA provides tools and training for evidence-informed practice to help prevent chronic disease";
			break;
		}
	}
}


function addKeywordLabel(){
	var keyLabel = document.getElementById('keywords-label');
	var key = document.getElementById('keywords');
	if(keyLabel && key){
		/* Move form label off to the left */
		keyLabel.style.position = 'absolute';
		keyLabel.style.left = '-9999px';
		/* Insert label text in input value if input is empty */
		if(key.value == ''){
			key.value = 'enter keywords';
		}
	}
}

function addJavaScriptLinks(){
	var footerList = document.getElementById('footer-nav');
	var printLink = document.createElement('a');
	printLink.setAttribute('href','#');
	printLink.onclick = function(){ window.print(); return false; };
	printLink.appendChild(document.createTextNode('Print this page'));
	var printLi = document.createElement('li');
	printLi.appendChild(printLink);
	footerList.appendChild(printLi);

	var sizeSpan = document.createElement('span');
	sizeSpan.appendChild(document.createTextNode('TextSize'));
	var sizeLi = document.createElement('li');
	sizeLi.setAttribute('id','text-size-links');
	var sizesUl = document.createElement('ul');
	sizesUl.setAttribute('id','text-resize');

	var spanLi = document.createElement('li');
	spanLi.appendChild(sizeSpan);
	spanLi.setAttribute('class','first');
	sizesUl.appendChild(spanLi);


	var smallLink = document.createElement('a');
	smallLink.onclick = function(){ changeFont('small_font'); return false; };
	smallLink.appendChild(document.createTextNode('S'));
	smallLink.setAttribute('href','#');
	smallLink.setAttribute('title','use small font');
	var smallLi = document.createElement('li');
	smallLi.appendChild(smallLink);
	sizesUl.appendChild(smallLi);

	var medLink = document.createElement('a');
	medLink.onclick = function(){ changeFont('medium_font'); return false; };
	medLink.appendChild(document.createTextNode('M'));
	medLink.setAttribute('href','#');
	medLink.setAttribute('title','use medium font');
	var mediumLi = document.createElement('li');
	mediumLi.appendChild(medLink);
	sizesUl.appendChild(mediumLi);

	var largeLink = document.createElement('a');
	largeLink.onclick = function(){ changeFont('large_font'); return false; };
	largeLink.appendChild(document.createTextNode('L'));
	largeLink.setAttribute('href','#');
	largeLink.setAttribute('title','use large font');
	var largeLi = document.createElement('li');
	largeLi.appendChild(largeLink);
	sizesUl.appendChild(largeLi);

	var xlargeLink = document.createElement('a');
	xlargeLink.onclick = function(){ changeFont('x_large_font'); return false; };
	xlargeLink.appendChild(document.createTextNode('XL'));
	xlargeLink.setAttribute('href','#');
	xlargeLink.setAttribute('title','use extra large font');
	var xlargeLi = document.createElement('li');
	xlargeLi.appendChild(xlargeLink);
	sizesUl.appendChild(xlargeLi);
	
	sizeLi.appendChild(sizesUl);
	footerList.appendChild(sizeLi);
}

function addEventJavaScriptLink(){
	var eventList = document.getElementById('subnav');
	var printLink = document.createElement('a');
	printLink.setAttribute('href','#');
	printLink.onclick = function(){ window.print(); return false; };
	printLink.appendChild(document.createTextNode('Print this event'));
	var printLi = document.createElement('li');
	printLi.appendChild(printLink);
	eventList.appendChild(printLi);
}

function addEventsJavaScriptLink(){
	var eventList = document.getElementById('subnav');
	var printLink = document.createElement('a');
	printLink.setAttribute('href','#');
	printLink.onclick = function(){ window.print(); return false; };
	printLink.appendChild(document.createTextNode('Print this page'));
	var printLi = document.createElement('li');
	printLi.appendChild(printLink);
	eventList.appendChild(printLi);
}

/* Module Change Font (string) */
function changeFont(fontClass){
	var element = document.getElementById(fontElementId);
	element.className = fontClass;
	setCookie("fontSize", fontClass, 5);
}		

/* Module Set Default Font Size (void) */
function setDefaultFontSize(){
	var fontSize = getCookie("fontSize")
	if(fontSize){
		var element = document.getElementById(fontElementId);
		element.className = fontSize;
	}
}

/* Module Set Cookie (string, string, int) -- http://www.w3schools.com/js/js_cookies.asp */
function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "; path=/" : ";expires="+exdate.toGMTString()+"; path=/");
}
/* Module Get Cookie (string) -- http://www.w3schools.com/js/js_cookies.asp */
function getCookie(c_name){
	if(document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1){ 
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return false;
}
