	// global variables	
	var language = "en";
	var default_sitemap = "sitemap.html";	
	var default_filename = "index.html";	
	var default_footer = "footer.html";
	var default_banner = "banner.html"
	var default_leftcta = "left_cta.html";
	var arr_swf = ["header-index.swf","header-how-gambling-works.swf","header-myths-about-gambling.swf","header-setting-limits.swf","header-getting-help.swf","header-about-this-site.swf","header-about-this-site.swf","header-index.swf"];
	var arr_cta_swf = ["OLG_Parents_188x104.swf"];
	var active_node = 0;
	var default_swf = arr_swf[active_node];
	var active_cta = 0;
	var default_cta_swf = arr_cta_swf[active_cta];
	var sitemapObjectArray = [];
	
	// force no-cache on ajax requests
	$.ajaxSetup ({
	    // Disable caching of AJAX responses */
	    cache: false
	});
	
	// get the filename from the URL
	var default_pagename = function(){
		var arr_pathname = location.pathname.split("/");		
		// make sure the pathname has an extension if not default to index.html
		if(arr_pathname[(arr_pathname.length-1)].indexOf(".") != -1 ){
			default_filename = arr_pathname[(arr_pathname.length-1)];
		}	
		
		// set the default swf as well
		// default_swffilename();
						
		return default_filename;
	}
	
	var set_activeNode = function(theNode){
		active_node = theNode; 			
		// replace the contents footer,leftnav, and contentarea contents with sitemap and pagename contents
		pageLoad();
	};	
	
	var setHeaderSwf = function(){
		default_swf = arr_swf[active_node];
		
		if(language == "fr"){
			default_swf = arr_swf[active_node];
			default_swf = default_swf.replace(/.swf/,"-fr.swf");
		}	
	};
	
	var setCTAswf = function() {
		default_cta_swf = arr_cta_swf[active_cta];
		
		if(language == "fr"){
			default_cta_swf = arr_cta_swf[active_cta];
			default_cta_swf = default_cta_swf.replace(/.swf/,"-fr.swf");
		}	
	}
	
	// test to see if person allows cookies
	var accepts_cookies = $.cookies.test();

	// set the navigation element contents
	var setNavContents = function(){
		/*
		$("#footermessage").load(""+language+"/"+default_sitemap+" #footermsg");
		$("#footernav").load(""+language+"/"+default_sitemap+" #footer");	
		$("#copyright").load(""+language+"/"+default_sitemap+" #copyright");
		*/
		$("#leftside_cta").load(language+"/"+default_leftcta);
		$("#banner").load(language+"/"+default_banner);
		$("#footercontent").load(language+"/"+default_footer);
		$("#leftside").load(""+language+"/"+default_sitemap+" #leftnav", function(){				
			$("#leftnav").accordion({
				header: ".head",
				event:"click",								
				active: active_node,
				navigation: true,
				autoHeight: false
			});	

			$("#leftnav .head").click(function(event){
				  window.location.href = $(this).attr("href");
			 });														
		 });	
	};	

	// set the page contents
	var setPageContents = function(){		
		$("#contentarea").load(language+"/"+default_filename);	
	};	

	// page load function that calls the content loaders
	var pageLoad = function(){
		setCTAswf();
		setHeaderSwf();
		setNavContents();
		setPageContents();	
	}

	// language switch
	var toggleLanguage = function (language_key){
		language = language_key;
		
		if(accepts_cookies){	
			// check if a cookie exists
			if($.cookies.get('olgLanguage') == null){
				// set a cookie to the default language, by default will expire at the end of browser session
				$.cookies.set('olgLanguage',language_key);
				//$.cookies.set('olgActiveNode',active_node);
			}
			else{
				// check if changing language
				if($.cookies.get('olgLanguage') != language_key){
					// reset the cookie
					$.cookies.set('olgLanguage',language_key);
					//$.cookies.set('olgActiveNode',active_node);
				}
				
			}		
		}		
		
		// reload the contents
		pageLoad();
		// reload the page to make sure the page is actually ready.
		// I know, I know...why. Well, I'd explain but you'd be bored.
		// i replaced this with an absolute no-cache attribute on the aJaxSetup, does this stop the need for the line below ??
		// seems to work in testing locally using apache. I'll test on IE/6/7 and if (and only if) 
		// we need to we can switch the reloader back on... belt and suspenders... belt and suspenders.
		//window.location.href = document.location.href;
	}
		
	
	// initial settings for load
	if(accepts_cookies){
		// check for cookie
		if($.cookies.get('olgLanguage') == null){
			// set cookie based on default language
			$.cookies.set('olgLanguage',language);
			//$.cookies.set('olgActiveNode',active_node);
		}
		else{
			// cookie exists and its the same session so load it
			language = $.cookies.get('olgLanguage');
			//active_node = $.cookies.get('olgActiveNode');
		}
		
	}	
	


	/* modal*/
	var closeModal = function(hash)
	{
		var $modalWindow = $(hash.w);
		$modalWindow.fadeOut('2000', function()
		{
			hash.o.remove();
			//refresh parent
			/*if (hash.refreshAfterClose == true)
			{
			*/
				window.location.href = document.location.href;
			/*}*/
		});
	};
	
	var openInFrame = function(hash)
	{
		var $trigger = $(hash.t);
		var $modalWindow = $(hash.w);
		var $modalContainer = $('iframe', $modalWindow);
		var myUrl = $trigger.attr('href');
		var myTitle = $trigger.attr('title');
		var newWidth = 0, newHeight = 0, newLeft = 0, newTop = 0;
		$modalContainer.html('').attr('src', myUrl);
		$('#jqmTitleText').text(myTitle);
		//myUrl = (myUrl.lastIndexOf("#")> -1) ? myUrl.slice(0, myUrl.lastIndexOf("#")) : myUrl;
		//var queryString = (myUrl.indexOf("?")> -1) ? myUrl.substr(myUrl.indexOf("?") + 1) : null;
		$modalWindow.css({opacity: 1}).jqmShow().fadeIn('3000');
		
	}

	
	$(document).ready(function(){
		// load the sitemap file
		count_node = 0;
		
		$.get(""+language+"/"+default_sitemap+"", function(data){		  
		 node_set = false;
		 parent_node = -1;
		 
		  // get all the links from the site map to determine the parent node id
		  
		  
		  $(data).find("a").each(function(index)
		  {
			
			// clean href for IE			
			var arr_pathname = $(this).attr("href").split("/");
			var current_link = "";
			// make sure the pathname has an extension if not default to index.html
			if(arr_pathname[(arr_pathname.length-1)].indexOf(".") != -1 ){
				current_link = arr_pathname[(arr_pathname.length-1)];
			}			
			
			if($(this).hasClass("head")){
			parent_node++;
			}
						
			// catch the current href
			if(current_link == default_pagename()){				
				node_set = true;
				return false;								
			}			

			
		  });
		  
		  if(node_set == true){
		  	// trigger the page node setting on successful load of the sitemap
		  	set_activeNode(parent_node);
		  }
		  	  
		});									
	}); 