try {
 document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

$(document).ready(Init);

function Init()
{

TextResize();

SelectLanguage();

}

function TextResize()
{
// Display the three text size buttons.
$("#text-small").show();
$("#text-medium").show();
$("#text-large").show();

// Small
$("#text-small a").click(function(e){
setActiveStyleSheet("small");
return false;
});

// Medium
$("#text-medium a").click(function(e){
setActiveStyleSheet("medium");
return false;
});

// Large
$("#text-large a").click(function(e){
setActiveStyleSheet("large");
return false;
});
}


var LangHelp = {

	_currLang : '',


	init : function(e) {this._langStrings('previous');

		// Retrieve the language, set in the link.
		this._currLang = $(e).attr('id');

		PopupOverlay.init('LangHelp');
		PopupOverlay.loadContent(this._buildTemplate());

		/*
		Setup events for closing the help box.
		*/
		$('#LangHelp_Banner a').click(function(e){
			return PopupOverlay.close();
		});
		$(document).bind('keydown', function ClosePopup(e){
			var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
			(key == 27) ? PopupOverlay.close(ClosePopup) : false;
		});

	},

	/*
	Creates static HTML template that will be used for displaying the content
	*/

	_buildTemplate : function() {
		return '<div id="LangHelp_Wrapper" class="' + this._langStrings('dir') + '">' +
					'<h1 id="LangHelp_Banner" title="Title">' +
					'<a href="#" title="' + this._langStrings('close') + '" class="' + this._langStrings('lang') + '">' + this._langStrings('close') + '</a>' +
					this._langStrings('title') +
					'</h1>' +
					'<div id="LangHelp_Content"><iframe frameborder="0" src="/html/popups/' + this._langStrings('source') + '" class="language"></iframe></div>' +
					'</div>';
	},


	_langStrings : function(tag) {
		var lang_es = {
			lang : 'es',
			title : 'Spanish content',
			close : 'Close',
			source : 'spanish.html',
			dir : 'ltr'
		}

		var lang_pl = {
			lang : 'pl',
			title : 'Polish Content',
			close : 'Close',
			source : 'polish.html',
			dir : 'ltr'
		}

		var lang_ar = {
			lang : 'ar',
			title : 'Arabic content',
			close : 'Close',
			source : 'arabic.html',
			dir : 'rtl'
		}
		var lang_ku = {
			lang : 'ku',
			title : 'Kurdish content',
			close : 'Close',
			source : 'kurdish.html',
			dir : 'rtl'
		}
		var lang_vi = {
			lang : 'vi',
			title : 'Vietnamese content',
			close : 'Close',
			source : 'vietnamese.html',
			dir : 'ltr'
		}

		var lang_fa = {
			lang : 'fa',
			title : 'Farsi content',
			close : 'Close',
			source : 'farsi.html',
			dir : 'rtl'
		}
		var lang_da = {
			lang : 'da',
			title : 'Dari content',
			close : 'Close',
			source : 'dari.html',
			dir : 'rtl'
		}

		var lang_de = {
			lang : 'de',
			title : 'German content',
			close : 'Close',
			source : 'german.html',
			dir : 'ltr'
		}

		var lang_it = {
			lang : 'it',
			title : 'Italian content',
			close : 'Close',
			source : 'italian.html',
			dir : 'ltr'
		}
		var lang_hi = {
			lang : 'hi',
			title : 'Hindi content',
			close : 'Close',
			source : 'hindi.html',
			dir : 'rtl'
		}
		var lang_sr = {
			lang : 'sr',
			title : 'Serbian content',
			close : 'Close',
			source : 'serbian.html',
			dir : 'ltr'
		}

		var lang_bs = {
			lang : 'bs',
			title : 'Bosnian content',
			close : 'Close',
			source : 'bosnian.html',
			dir : 'ltr'
		}
		
		var lang_hr = {
			lang : 'hr',
			title : 'Croatian content',
			close : 'Close',
			source : 'croatian.html',
			dir : 'ltr'
		}
		
		var lang_ur = {
			lang : 'ur',
			title : 'Urdu content',
			close : 'Close',
			source : 'urdu.html',
			dir : 'rtl'
		}

		var lang_pa = {
			lang : 'pa',
			title : 'Punjabi content',
			close : 'Close',
			source : 'punjabi.html',
			dir : 'rtl'
		}
		
		var lang_zh = {
			lang : 'zh',
			title : 'Mandarin content',
			close : 'Close',
			source : 'mandarin.html',
			dir : 'rtl'
		}
		
		var lang_ch = {
			lang : 'ch',
			title : 'Cantonese content',
			close : 'Close',
			source : 'cantonese.html',
			dir : 'rtl'
		}

		var lang_wpl = {
			lang : 'wpl',
			title : 'Waterloo Public Library',
			close : 'Close',
			source : 'wpl.html',
			dir : 'map'
		}

		var lang_wpm = {
			lang : 'wpm',
			title : 'WPL - McCormick Branch',
			close : 'Close',
			source : 'wpm.html',
			dir : 'map'
		}

		var lang_kpl = {
			lang : 'kpl',
			title : 'Kitchener Public Library',
			close : 'Close',
			source : 'kpl.html',
			dir : 'map'
		}

		var lang_fhl = {
			lang : 'fhl',
			title : 'Forest Heights Community Library',
			close : 'Close',
			source : 'fhl.html',
			dir : 'map'
		}

		return (this._currLang == 'es') ? lang_es[tag] : (this._currLang == 'pl') ? lang_pl[tag] : (this._currLang == 'ar') ? lang_ar[tag] : (this._currLang == 'ku') ? lang_ku[tag] : (this._currLang == 'vi') ? lang_vi[tag] : (this._currLang == 'fa') ? lang_fa[tag] : (this._currLang == 'da') ? lang_da[tag] : (this._currLang == 'de') ? lang_de[tag] : (this._currLang == 'it') ? lang_it[tag] : (this._currLang == 'hi') ? lang_hi[tag] : (this._currLang == 'sr') ? lang_sr[tag] : (this._currLang == 'bs') ? lang_bs[tag] : (this._currLang == 'hr') ? lang_hr[tag] : (this._currLang == 'ur') ? lang_ur[tag] : (this._currLang == 'pa') ? lang_pa[tag] : (this._currLang == 'zh') ? lang_zh[tag] : (this._currLang == 'ch') ? lang_ch[tag] : (this._currLang == 'wpl') ? lang_wpl[tag] : (this._currLang == 'wpm') ? lang_wpm[tag] : (this._currLang == 'kpl') ? lang_kpl[tag] : lang_fhl[tag];
	}

};


/**
 * Popup Overlay
 *
 * Grabs URL within anchor tag and loads the page, filtering out all
 * content except what has been provided as an anchor target.
 *
 * i.e. <a href="popuppage.html#targetID"> ... </a>
 *
 */
var PopupOverlay = {
	offsetToTop : 0,
	offsetOfElement : 0,
	popupID : '',
	status : false,

	init: function(id) {
		var obj = this;

		$('<div id="overlay"></div>').appendTo('body');
		$('#overlay').css({
			height: $(document).height() + 'px',
			width: $(window).width() + 'px'
		});

		this.popupID = (id !== '') ? id : 'PopupDefault';

		//$(window).scroll(this._offset);
		$(window).resize(function(){
			$('#overlay').css({
				height: $(document).height() + 'px',
				width: $(window).width() + 'px'
			});

			obj._offset();
		});

		this.status = true;

		if($('div.popup').size() < 1)
		{
			$('<div class="popup"></div>').attr('id', this.popupID).appendTo('body');
		}

		/*
		"Anywhere" click closing function.
		*/
		$('#overlay').click(function(){
			obj.close('obj.init');
		});
	},

	loadContent: function(e) {
		$('div.popup').html(e).show();
		this._offset();
	},

	close: function(evtfunc) {
		$('div.popup').remove();
		$("#overlay").remove();

		this.status = false;

		$(document).unbind('keydown', evtfunc);

		return false;
	},

	loadMessage: function() {
		$('div.popup').html('<p class="tcenter"><strong>Loading... please wait.</strong></p>')
		$('div.popup').show();

		this._offset();
	},

	_offset: function() {
		this.offsetToTop = $(window).scrollTop();
		this.offsetOfElement = parseInt(($(window).height() - $('div.popup').height()) / 2);
		$('div.popup').css('top', parseInt(this.offsetToTop + this.offsetOfElement) + 'px');
	}
};


/*
Language Selection
*/
function SelectLanguage()
{
	$("#language-select").hover(
		function(){
			if($("#language-select-content:visible").size() < 1)
			{
				$("#language-select-content").show();
			}
		},
		function() {
			$("#language-select-content").hide();
		}
	);

	$("#language-select-content").hover(
		function() {
			$("#language-select-content").show();
		},
		function(){
			$("#language-select-content").hide();
		}
	);
}


/**
 * Image swapper functions for Contact us page
 */

function MM_preloadImages() { //v3.0
  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_swapImgRestore() { //v3.0
  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_findObj(n, d) { //v4.01
  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() { //v3.0
  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];}
}