


var AGIMO = { "isIE": false,"isIElt7": false,"isScreen": true,
              "globalLinksMarginLeft": "0px",
			  "wResize": 0,"minWidth" : 975, "maxWidth" : 1170,
			  "pageId": ""
			} ; //pseudo namespace to avoid clashes

AGIMO.isIE = ($.browser.msie);  // alert this property will be deprecated in jQuery 1.3 

if (AGIMO.isIE ) {   // this footwork instead of using $.browser.version is due to IE 7.0 sometimes reporting in jQuery as version  6.0
 	AGIMO.isIElt7 =  (   /MSIE 6\.0/i.test(window.navigator.userAgent)
    				   && !/MSIE 7\.0/i.test(window.navigator.userAgent)
    				 );
    				 
   // if (!jQuery.fn.corners) { //dynamic load of sliding doors stylesheets
   // 	$('head').append('<link rel="stylesheet" href="css/ie_roundedTabs.css" media="screen" type="text/css" />'); 
   //	};	 				 
}

// AGIMO.addPageToolsToFooterLinkGroups = function(){
//
//	var careers = $('#careersGlobalLinkGroup');
//	if (careers.length > 0 ){
//	   var title = escape(document.title);
//	   var url = escape(document.location);
//       careers.before('<h2 class="footerLinkHeading">Page Tools</h2><ul class="listFooterLink">' +
//                       '<li><a href="#" class="printPage" title="Print this page" >Print this Page</a></li>' +
//                       '<li><a href="mailto:?subject=' + title + '&body=' + url + '"  class="emailPage" title="Email this page">Email this Page</a></li>' +
//                       '</ul>');	
//       
//       $('a.printPage').bind('click keypress', function(e) {
//   			 var code=e.charCode || e.keyCode;
//    		if(!code || (code && code == 13)) {
//       			 window.print(); 
//       			
//       		 	e.preventDefault(); 
//    		}
//		 }); 
//    
//    }
//};

var FaqPage = {};
FaqPage.toggleQuestionsAndAnswers = function(){ 
	var answers = $(".questionTitle");
	if(answers && answers.length > 0){
		jQuery.each(answers, function() {
			  $(this).click(function(){
				$(this).toggleClass("closedAnswer");
				($("#answer-"+this.name)).toggle();
			});	  		          
		 });
	}
};

FaqPage.autoExpandAnwerOnClickingAnchoredQuestion = function(){
	var questions = $(".question");
	if(questions && questions.length > 0){
		jQuery.each(questions, function() {
			  $(this).click(function(){
				  var href = $(this).attr("href");
				  $("#answer-"+href.replace("#", "")).show();
				  $(href).removeClass("closedAnswer");
			  });	  		          
		 });
	}
};

FaqPage.hideAnswers = function() {
	var answers = $(".questionTitle");
	if(answers && answers.length > 0){
		jQuery.each(answers, function() {
			$("#answer-"+this.name).css('display', 'none');
			$(this).addClass("closedAnswer");
		});
	}
};

FaqPage.goToAnchoredAnswer = function() {
	var faqUrl = document.location.toString();
	if (faqUrl.match('#')) {
		var myAnchor = '#' + faqUrl.split('#')[1];
		$('div#questions ul li a[href="' + myAnchor + '"]').click();
	}
};

function create_footnotes(){			
			
		$("#contentWrapper").append("<div id=\"footnotes\"></div>");
	    $("#footnotes").append("<h2 id=\"footNoteHeader\">Notes</h2>");
	    $("#footnotes").append("<ol></ol>");
	    $("#footnotes").append("<p id=\"au_current_url\">"+document.location.href+"</p>");
	    
	    // Add footnote class to links, citations, etc. from relevant page components (generic)
		$("div#contentWrapper q[cite],div#contentWrapper q[title],div#contentWrapper blockquote[cite] ,div#contentWrapper blockquote[title],div#contentWrapper a[href]").addClass("footnote");
		$("div#crumbsAndPreferences a[href]").removeClass("footnote");
		$("div#pageNav a[href]").removeClass("footnote");
		$("div.azlist a[href]").removeClass("footnote");
		$("div#agospThemeContent a[href^='#']").removeClass("footnote");
		 
	    footnote = 1;
		$(".footnote").each(function() {
		    $(this).after("<sup class=\"footnote\">"+footnote+"</sup>");
		    cite="<li>";
		    url=$(this).attr("cite");
		    title=$(this).attr("title");
		    href=$(this).attr("href");
		  
		    // Revise relative links to absolute links
		    href=href.replace(/^\//,"http://australia.gov.au/");
		      
		    if(href) {
		        cite+="<a href=\""+href+"\">"+href+"</a>";
		    } else if(url) {
		        cite+="<a href=\""+url+"\">"+url+"</a>";
		    } else if(title) {
		        cite+=title;
			}
		    cite+="</li>";
		    $("#footnotes ol").append(cite);
		    footnote++;
		});
	
	}

$(document)
		.ready(function() {
			var elemWrapper = $('#pageContentWrapper');
			var agimo = AGIMO;

			agimo.minWidth = parseInt(elemWrapper.css('min-width'));
			agimo.maxWidth = parseInt(elemWrapper.css('max-width'));
			agimo.pageId = $('body').attr("id");
			agimo.isScreen = (agimo.minWidth != agimo.maxWidth); // screen has differen min and max wdths
				// in handheld and print min and max the same 
				agimo.globalLinksMarginLeft = $("#globalLinks").css(
						"margin-left");

				if (agimo.isIE) { // for IE effect the after pseudo class to print the link href value
					if (jQuery.browser.version != 8.0) {


						//apply rounded tabs to primaryNavigatiion and logInOut button if via jQuery plug-in
						if (jQuery.fn.corners) {
							$("#primaryNavigation li a").corners(
									"6px transparent top");
							$("#logInOut").corners("6px transparent bottom");
						}

					}

				}
				; // end of IE related script

				/*
				// only diagnostic not for inclusion in release
				if ($('#browserId').length > 0){
				  
				   	$('#browserId').html("<p>" + window.navigator.userAgent + "</p>"
				   	      + "<p>jQuery $.browser.version: " + $.browser.version + "</p>"
				   	     + "<p>isIE: " + AGIMO.isIE + "</p>"
				   	     + "<p>isIElt7: " + AGIMO.isIElt7 + "</p>"
						 + "<p>Render Mode: " + document.compatMode + "</p>"
				
				   	);
				
				};
				 */

				if (window.location.pathname != "/search"){
					create_footnotes();
				}
				 
				if (agimo.isScreen) {

					//agimo.addPageToolsToFooterLinkGroups();

					// Your code here
					// apply hover labels to input filel  aka. watermark input fields 
					// Routine from John Resig's "Pro Javascript Techniques"
					$("label.hover+input")

					// Wrap a div (with a class of hover-wrap) around the input element,
							// resulting in HTML that looks like:
							// <div class='hover-wrap'><input type="text" …/></div>
							.wrap("<div class='hover-wrap'></div>")

							// Whenever the input element is focused upon (either through a click
							// or by keyboard), hide the label
							.focus(function() {
								$(this).prev().hide();
							})

							// Whenever the user has left the input element (and no text has been
							//  entered into it) reveal the label again.
							.blur(function() {
								if (!this.value)
									$(this).prev().show()
							})

							// Go through each of the input elements individually
							.each(function() {
								// Move the label to go inside of the <div class='hover-wrap'></div>
									$(this).before($(this).parent().prev());

									// Make sure that if a value is already in the form, that the label is
									//  automatically hidden
									if (this.value)
										$(this).prev().hide();
								});

					// skipLinks OffScreen initially
					if (parseInt(agimo.globalLinksMarginLeft) > 0) { // handheld.css will set this to 0

						$("#skipLinksNav").css("marginLeft", "-5000px");

						// if keyboard navigation is used bring the skipLinks Navigation into view 
						// add a fire only once,  onFocus keyBoard handler
						$("#skipLinksNav li a").one("focus", function(event) {
							var ul = $("#skipLinksNav");
							var left = parseInt(ul.css("marginLeft"));

							if (left < 0) {
								ul.css("marginLeft", "0"); //restore to view

							}
						});
					}
				}
				var faqPage = FaqPage;
				faqPage.hideAnswers();
				faqPage.toggleQuestionsAndAnswers();
				faqPage.autoExpandAnwerOnClickingAnchoredQuestion();
				faqPage.goToAnchoredAnswer();
			});
			
			

