


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(){
				($("#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("#", "")).toggle();
			  });	  		          
		 });
	}
};

FaqPage.hideAnswers = function() {
	var answers = $(".questionTitle");
	if(answers && answers.length > 0){
		jQuery.each(answers, function() {
		  var url = $(this).attr("name");
		  $("span").filter(function () {
              return $(this).attr("id") == url}).css('display', 'none');
		});
	}
};

FaqPage.goToAnchoredAnswer = function() {
	var faqUrl = document.location.toString();
	if (faqUrl.match('#')) {
		var myAnchor = '#' + faqUrl.split('#')[1];
		$('div#questions ul li a[href="' + myAnchor + '"]').click();
	}
};


$(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) {
						window.onbeforeprint = function() {
							$("a").each(
									function() {
										var that = $(this);
										that.after("<span name='checkIE8'>("
												+ that.attr("href")
												+ ")</span>");
									});
						};

						window.onafterprint = function() { // simpler way of clearing the after pseudo class additions

							if (jQuery.browser.version == 7.0) {
								$("span").each(function() {
									var that = $(this);
									if (that.attr('name') == 'checkIE8') {
										that.replaceWith("");
									}
								});
							} else {
								window.history.go(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 (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();
			});

