// CSS SWICH
var CurrentFontSize = 0;
function Zoom() {
	if (CurrentFontSize == 0) {
		document.styleSheets[1].disabled=true;
		document.styleSheets[2].disabled=false;
		document.styleSheets[3].disabled=true;
		CookieSet('zoom',  '0', '', '/', '', '' );
		CurrentFontSize = 1;
	} else if (CurrentFontSize == 1) {
	document.styleSheets[1].disabled=false;
	document.styleSheets[2].disabled=true;
	document.styleSheets[3].disabled=true;	
	CookieSet('zoom',  '1', '', '/', '', '' );
	CurrentFontSize = 2;
	} else {
	document.styleSheets[1].disabled=true;
	document.styleSheets[2].disabled=true;
	document.styleSheets[3].disabled=false;
	CookieSet('zoom',  '2', '', '/', '', '' );
	CurrentFontSize = 0;
	}
	Cufon.replace('#nav li a, #nav li.donate a, #nav li.home a', {hover: true}, { fontFamily: 'Century Gothic' });
}
// CSS SWICH

var visionCss = true;
function Vision() {
if (visionCss) {
CookieSet('vision',  '1', '', '/', '', '' );		
document.styleSheets[4].disabled=true;
visionCss = false;
} else {
CookieSet('vision',  '0', '', '/', '', '' );	
document.styleSheets[4].disabled=false;
visionCss =  true;
}
}

function CheckCookies() {
if (CookieGet('zoom')) {	
CurrentFontSize = parseInt(CookieGet('zoom'));
} else {
CurrentFontSize = 2;	
}
if (CookieGet('vision') == '1') {
visionCss = true;
} else if (CookieGet('vision') == '0') {
visionCss = false;
}
Zoom();
Vision();
}


var SoundPlaying = false;
function Sound() 
{
	var soundFile = 'main';	
	var audioObject = document.getElementById('audioplayer');
	
	if(location.href.match('/get-help-now/we-can-help'))
		soundFile = 'wecanhelp';	
		
	else if(location.href.match('/get-help-now/sign-of-abuse'))
		soundFile = 'signofabuse';	
		
	else if(location.href.match('/get-help-now/shelter-faqs'))
		soundFile = 'shelterfaqs';	
		
	else if(location.href.match( '/get-help-now/shelter-life'))
		soundFile = 'shelterlife';	
	
	if(!SoundPlaying) 
	{	
		var type = 'ogg';	
		if(audioObject.canPlayType('audio/mpeg'))
			type = 'mp3';
		
		audioObject.src = '/audio/'+type+'/'+soundFile+'.'+type;
		audioObject.play();
		SoundPlaying = true;
	} 
	
	else 
	{
		audioObject.pause();
		SoundPlaying = false;
	}
}

////////////////////////////////////////////////////////// DETECT KEY

// VERIABLES
window.document.onkeydown = BodyGetKeyEvents;
window.document.onkeyup = BodyGetKeyEvents;

// Key events
var useShorKeys = true;
function BodyGetKeyEvents (evt) 
{
	if(useShorKeys)
	{
		var evt = (evt) ? evt : ((window.event) ? event : null);
	
		if (evt.type == 'keydown') {
			var charCode = (evt.charCode) ? evt.charCode : evt.keyCode;
			
			// P 
			if (charCode == 80) 
				location.href = '/our-programs/child-and-youth-rights';	
			
			// C
			if (charCode == 67)
				location.href = '/contact';	
			
			// N 
			if (charCode == 78) 
				location.href = '/ews-news/newsletters';		
			
			// G 
			if (charCode == 71)
				location.href = '/get-help-now/we-can-help';
				
			// D 
			if (charCode == 68)
				location.href = 'http://www.canadahelps.org/CharityProfilePage.aspx?CharityID=d329';			
			
			// X HOME 
			if (charCode == 88) 
				location.href = '/';	
			
			// SPACE H HELP
			if (charCode == 72 || charCode == 32)
				location.href = '/help';	
			
			
			// V VISION
			if (charCode == 86)
				Vision();	
			
			
			// Z ZOOM
			if (charCode == 90)
				Zoom();
			
			
			// S SOUND
			if (charCode == 83)
				Sound();	
		
		} 
	}
}
////////////////////////////////////////////////////////// DETECT KEY

////////////////////////////////////////////////////////// COOKIES

// COOKIES GET
function CookieGet(name) {	
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
// COOKIES GET

// COOKIES SET
function CookieSet(name, value, expires, path, domain, secure) {
	var NowDate = new Date();
	NowDate.setTime(NowDate.getTime());
	if (expires) {
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date(NowDate.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}
// COOKIES SET

////////////////////////////////////////////////////////// COOKIES
CheckCookies();
