$(document).ready(function(){
	setTimeout(initOverLabels, 50);
	/*$('.tabnav').tabz();
	$('#fontsize').fontz();
	$('a[rel*=facebox]').facebox(); */
	initSubMenus();

	/*Table Striping*/
	$(".stripeMe tr:odd").addClass("alt");
	
	/*Corny faux AJAX loader*/
	//$("#loading").fadeOut("slow");
	
	$("#answers").hide();
	
	answerTimer =''
	answerTimer = setTimeout(function(){
			$("#loading").hide();
			$("#answers").slideDown("slow");
		},3000)

});


function initSubMenus(){
	timer = '';
	$('li#topStrategy').mouseover(function(){
		hideAllMenus();
		$("#sub1").show();
	});
	$('li#topStrategy').mouseout(function(){
		timer = setTimeout(function(){
			$("#sub1").hide();
		},500)
	});
	
	$('li#topOperations').mouseover(function(){
		hideAllMenus();
		$("#sub2").show();
	});
	$('li#topOperations').mouseout(function(){
		timer = setTimeout(function(){
			$("#sub2").hide();
		},500)
	});

	$('li#topRegulatory').mouseover(function(){
		hideAllMenus();
		$("#sub3").show();
	});
	$('li#topRegulatory').mouseout(function(){
		timer = setTimeout(function(){
			$("#sub3").hide();
		},500)
	});

	$('li#topTechnology').mouseover(function(){
		hideAllMenus();
		$("#sub4").show();
	});
	$('li#topTechnology').mouseout(function(){
		timer = setTimeout(function(){
			$("#sub4").hide();
		},500)
	});

	$('li#topSkill').mouseover(function(){
		hideAllMenus();
		$("#sub5").show();
	});
	$('li#topSkill').mouseout(function(){
		timer = setTimeout(function(){
			$("#sub5").hide();
		},500)
	});

	/*$('li#memorials').mouseover(function(){
		hideAllMenus();
		$("#sub5").show();
	});
	$('li#memorials').mouseout(function(){
		setTimeout(function(){$("#sub5").hide();},2000)
	});
	
	$('li#home').mouseover(function(){
		hideAllMenus();
	});
	$('li#submit').mouseover(function(){
		hideAllMenus();
	});		*/			
	
	$('.dropdown').mouseover(function(){
		clearTimeout(timer);
	});
	
	$('#sub1.dropdown').mouseout(function(){
		timer = setTimeout(function(){
			$("#sub1").hide();
		},500)		
	});
		
	$('#sub2.dropdown').mouseout(function(){
		timer = setTimeout(function(){
			$("#sub2").hide();
		},500)		
	});	
	
	$('#sub3.dropdown').mouseout(function(){
		timer = setTimeout(function(){
			$("#sub3").hide();
		},500)		
	});
	
	$('#sub4.dropdown').mouseout(function(){
		timer = setTimeout(function(){
			$("#sub4").hide();
		},500)		
	});
	
	$('#sub5.dropdown').mouseout(function(){
		timer = setTimeout(function(){
			$("#sub5").hide();
		},500)		
	});
		
}

function hideAllMenus(){
	clearTimeout(timer);
	$('#sub1').hide();
	$('#sub2').hide();
	$('#sub3').hide();
	$('#sub4').hide();
	$('#sub5').hide();
}

/* for the switching labels on the login form, should probably rewrite in Jquery... */

function initOverLabels () {
  if (!document.getElementById) return;  	

  var labels, id, field;
  labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
	
    if (labels[i].className == 'overlabel') {

      id = labels[i].htmlFor || labels[i].getAttribute('for');
      if (!id || !(field = document.getElementById(id))) {
        continue;
      }

      labels[i].className = 'overlabel-apply';

      if (field.value !== '') {
        hideLabel(field.getAttribute('id'), true);
      }

      field.onfocus = function () {
        hideLabel(this.getAttribute('id'), true);
      };
      field.onblur = function () {
        if (this.value === '') {
          hideLabel(this.getAttribute('id'), false);
        }
      };

      labels[i].onclick = function () {
        var id, field;
        id = this.getAttribute('for');
        if (id && (field = document.getElementById(id))) {
          field.focus();
        }
      };

    }
  }
};

function hideLabel (field_id, hide) {
  var field_for;
  var labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
    field_for = labels[i].htmlFor || labels[i].getAttribute('for');
    if (field_for == field_id) {
      labels[i].style.textIndent = (hide) ? '-10000px' : '0px';
      return true;
    }
  }
}







//Fix for IE6 CSS Flicker Bug
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

function RUSure(href,object_name,object_type){
		var message = "Are you sure you want to Delete " + object_name + " from " + object_type + "?";
		var yon = window.confirm(message);
		if (yon == 1){
			window.location.href = href;
		}
	}
