function zIndexWorkaround() { // for IE7 z-index gheyness
	jQuery.each(jQuery.browser, function(i) {
		if($.browser.msie){		
			//alert("IE!");
			var zi = 2000;
			$("#hd div:not(#hotline), #hd ul").each(function(block, i) {
			
				  $(this).css("z-index", zi--);

			});
		}
	});
	//$("#bd, #marketing-box-container, #marketing-box-pics").css("z-index", 0);
}			
				
				
jQuery.preloadImages = function() { for(var i = 0; i<arguments.length; i++)	{ jQuery("<img>").attr("src", arguments[i]); } }

$(document).ready(function() {
	
	
	zIndexWorkaround();
	
	$.preloadImages(
		base_path + theme_path + "/images/submit-app-hover.png",
		base_path + theme_path + "/images/submit-app-active.png",
		base_path + theme_path + "/images/submit-active.png",
		base_path + theme_path + "/images/submit-hover.png"
	);
	// menu hovers
	$("#main-nav ul li").hover(
	    function() {
	        $(this).children().filter("a").addClass("hover");
	    }, 
	    function() {
	        $(this).children().filter("a").removeClass("hover");
	    }
	);

	$('#voices').cycle({ 
		timeout:	6500
	});
	
	$('#pauseButton').click(function(e) { 
	    $('#voices').cycle('pause');
		return false;
	});
	$('#resumeButton').click(function(e) { 
	    $('#voices').cycle('resume');
		return false;
	});
	
	/*$("input[type='text'], textarea").focus(function() {
		$(this).css("border", "1px solid #982123");
	}).blur(function() {
		$(this).css("border", "1px solid #b4b4b4");
	});*/
	$("#edit-submit").hover(
		function() {
			$(this).attr({ src : base_path + theme_path + '/images/submit-hover.png'});
			$(this).mousedown(function(){
				$(this).attr(
					{ 
					src		: base_path + theme_path + '/images/submit-active.png',
					border	: 0,
					padding	: 0
					}
				);
			});

		},
		function() {
			$(this).attr({ src : base_path + theme_path + '/images/submit.png'});
		}
	);
	$('#submit').hover(
		function() {
			$(this).attr({ src : base_path + theme_path + '/images/submit-app-hover.png'});
			$(this).mousedown(function(){
				$(this).attr(
					{ 
					src		: base_path + theme_path + '/images/submit-app-active.png',
					border	: 0,
					padding	: 0
					}
				);
			});

		},
		function() {
			$(this).attr({ src : base_path + theme_path + '/images/submit-app.png'});
		}
	);
	
	// show email address field when at least 1 checkbox is checked
	$("#email_address_container").hide();
	$("input.email_updates").click(function() {
		$("#email_address_container").slideDown("slow");
		if($("input:checked").length == 0) {
			$("#email_address_container").slideUp("slow");
		}
	});
	
	// on page load, if any checkboxes are checked, show the email field
	if($("input:checked").length > 0) {
		$("#email_address_container").show();
	}
	
	

  // $(".marketing-box-message-bg").dropShadow({blur: 0}).css("z-index", "1"); 
   $("a.more-info").click(function(e) {
		$(".agency label, .agency a.active").removeClass("active");
		$(this).parent().find("label").toggleClass("active");
		$(this).toggleClass("active");
       e.preventDefault();
       $("#choose-agencies dl.show").removeClass('show');
       $(this).parent().find("dl").addClass('show');
   });
   $("select option", "#ft").click(function() {
       var destination = $(this).val();
       window.location = destination;
   });
   
   
   $("input[type=file]").click(function warn() {
       alert("SRNS Human Capital Management wants to help you protect your personnel information. Do not include your Social Security Number on this electronic form.");
       return true;
   })
   
      
   $("#resume-switcher").css("display", "block");
   $("#resume-upload, #resume-builder").css("display", "none");
   $("#choose-upload").click(function(e) {
       e.preventDefault();
       $("#resume-builder").css("display", "none");
       $("#resume-upload").css("display", "block");
       $.scrollTo($("#resume-upload"), {duration: 800});
   });
   $("#choose-builder").click(function(e) {
       e.preventDefault();
       $("#resume-upload").css("display", "none");
       $("#resume-builder").css("display", "block");
       $.scrollTo($("#resume-builder"), {duration: 800});
   });
   
   
   $("#clear-resume-upload").css("display", "inline").click(function() {
       $("#edit-field-resume-0-upload").val("");
       return false;
   });
   // Education application section
   var addSchool = $('<a href="#" class="form-add">Add an Institution</a>');
   var addWork = $('<a href="#" class="form-add">Add Experience</a>');
   var removeSchool = $('<a href="#" class="remove">×</a>');
   var removeWork = $('<a href="#" class="remove">×</a>');
   var schoolCount = 0;
   var workCount = 0;
   $("#education").append(removeSchool);
   $("#education").append(addSchool);
   $("#experience").append(removeWork);
   $("#experience").append(addWork);
   $("#education .institution").filter(":not(:first)").css('display', 'none');
   $("#experience .work-experience").filter(":not(:first)").css('display', 'none');
   
   // to do: add a 'remove' button for all the added institution sections
   addSchool.click(function(e) {
       e.preventDefault();
       if(schoolCount < 4) {
           var showThis = $("#education .institution:hidden:first");
           showThis.fadeIn();
           $.scrollTo(showThis, {duration: 800});
           $(this).parent().find("a.remove").css("display", "inline");
           schoolCount++;
       }
       
   });
   removeSchool.click(function(e) {
       e.preventDefault();
       if(schoolCount > 0) {
           var removeThis = $(this).parent().find('.institution:visible:last');
           removeThis.fadeOut();
           $.scrollTo(removeThis.prev(), {duration: 800});
           schoolCount--;
           if(schoolCount == 0) {
               $(this).parent().find('a.remove').css("display", "none");
           }
       }
       
   })
   addWork.click(function(e) {
       e.preventDefault();
       if(workCount < 4) {
           var showThis = $("#experience .work-experience:hidden:first");
           showThis.fadeIn();
           $.scrollTo(showThis, {duration: 800});
           $(this).parent().find("a.remove").css("display", "inline");
           workCount++;
       }
   })
   removeWork.click(function(e) {
       e.preventDefault();
       if(workCount > 0) {
           var removeThis = $(this).parent().find('.work-experience:visible:last');
           removeThis.fadeOut();
           $.scrollTo(removeThis.prev(), {duration: 800});
           workCount--;
           if(workCount == 0) {
               $(this).parent().find('a.remove').css("display", "none");
           }
       }
   });
   
   $("a#show-statement, a#network-srs-more-info").fancybox({
       frameWidth: 500,
       hideOnContentClick: false,
       padding: 20
   });
   
   // make external links open in new window
   $("a[rel=external]").click(function() {
   	   window.open(this.href);
   	   return false;
   });
   
   // abbreviation tooltips
   $("label[for=duns-number]").append($('<img src="http://216.36.51.195/recovery/sites/all/themes/srs/images/question-mark.png"/>').qtip({
       content: 'A D&B® D-U-N-S® Number is a unique nine-digit sequence recognized as the universal standard for identifying and keeping track of over 100 million businesses worldwide. Learn more at http://www.dnb.com',
       show: 'mouseover',
       hide: 'mouseout'
	}));
   
	// procurement table sorter
	$("#procurement").tablesorter({
		headers: {
			7: {
				sorter: false
			}
		}
	});
	$("#procurement .services-needed").each(function() {
		var index = $("#procurement tr:not(thead tr)").index($(this).parents('tr')) + 1;
		var content = $("#services .row" + index).html();
		if(content != null) {
			$(this).addClass('services-processed');
			$(this).qtip({
				content: '<ul class="procurement-services">' + content + '</ul>',
				show: 'mouseover',
				hide: 'mouseout',
				style: {
					name: 'light',
					tip: true,
					width: 200
				},
				position: {
					corner: {
						target: 'leftMiddle',
						tooltip: 'rightMiddle'
					}
				}
			});
		}
	}); // end procurement
	
	// Footprint reduction map
	$("#arra-map area").hover(
		function() {
			$("#" + $(this).attr('class')).show();
		}, function() {
			$("#" + $(this).attr('class')).hide();
		}
	);
	
	// past events table
	
	var pastEventExtras = $('h1#past-events + table tr:gt(9)').hide();
	$('#show-all-past a').toggle(
		function() {
			$(this).text("Collapse past events");
			pastEventExtras.show();
			return false;
		},
		function() {
			$(this).text("Show all past events");
			pastEventExtras.hide();
			return false;
		}
	);
	
	$('#marketing-box-controls').find('li').each(function() {
		var index = $('#marketing-box-controls').find('li').index(this);
		$(this).qtip({
			content: $('.marketing-box').eq(index).find('h2').text(),
			position: {
				corner: {
					tooltip: 'bottomLeft',
					target: 'topMiddle'
				}
				
			},
			style: {
				name: 'green',
				tip: 'bottomLeft'
			},
			show: 'mouseover',
			hide: 'mouseout'
		});
	})
});