// change $ to jQuery so it works with Prototype
jQuery.noConflict();

function toggleOverlay() {
	jQuery('#overlay').hide();
	
	var flashvars = {};
	var params = {bgcolor:"#FFFFFF", quality:"high", align:"middle", allowScriptAccess:"always", wmode:"transparent"};

	swfobject.embedSWF("/flash/panels.swf", "flash_object", "922", "385", "9.0.0","/flash/expressInstall.swf", flashvars, params);
}

jQuery(document).ready(function(){

	// clear out value of search box
	jQuery("input#SearchForm_SearchForm_action_results").val(" ");
	jQuery("div#landingform input#Form_Form_action_process").val(" ");
	
	jQuery("div#landingform p.checkbox input").attr("checked","checked");
	
	if ( jQuery("div#landingform form").length == 0 ) 
	{
		jQuery("div#landingform div#rightform span").css("display","none");
	}
	
	if ( jQuery("div#landingform form .field").length == 0 ) 
	{
		jQuery("div#landingform form").css("display","none");
		jQuery("div#landingform span#formtop").css("display","none");
		jQuery("div#landingform span#formbot").css("display","none");
	}
	
	// remove separator from right side of nav
	jQuery("ul#bottomleftnav > li:last").addClass("last");
	
	// initialize jqueryui tab containers
	jQuery('div#tabcontainer').tabs();
	
	// fix alignment of nav bar with selections
	if ( ( jQuery("ul#bottomleftnav li.current").length > 0 ) || ( jQuery("ul#bottomleftnav li.section").length > 0 ) ) 
	{
		jQuery("ul#bottomleftnav li").css("top","10px");
		jQuery("ul#bottomleftnav li li").css("top","auto");
	}
	
	if ( jQuery("div#error404").length > 0 ) 
	{
		jQuery("div#top").css("visibility","hidden");
	}


  //fields to show/hide content (if nothing is entered).
  var fields = {'SearchForm_SearchForm_Search': 'Search',
   'Form_NewsletterForm_Email': 'Email Address'};
  jQuery.each(fields, function(key, value) {
    var f = jQuery('#' + key);
    f.focus(function () {
      if(f.val().match(new RegExp(value, 'i'))) f.val('');
    });
    
    f.blur(function() {
      if(f.val() == '') f.val(value);
    });
  });
  
  jQuery('.toggleComments').click(function() {
    jQuery(this).find('~ div.comments').toggle();
    return false;
  });
  
  
  // THE FOLLOWING IS FOR THE FLASH OVERLAY

	if ( jQuery("div#home_centerpanel").length > 0 )
	{
			var flashvars = {};
			var params = {bgcolor:"#FFFFFF", quality:"high", align:"middle", allowScriptAccess:"always", wmode:"transparent"};
		
			swfobject.embedSWF("/flash/panels.swf", "flash_object", "922", "385", "9.0.0","/flash/expressInstall.swf", flashvars, params);
 	}
  
  //portal login form validation
  jQuery('#portallogin').validate({
    rules: {
      username: "required",
      password: "required"
    },
    messages: {
      username: "Username is required",
      password: "Password is required"
    }
  });
  var errMessages = {
    1: 'Invalid User name. Please enter valid user name.',
    2: 'Invalid Password. Please enter valid password',
    3: 'Your Account has been Locked after 3 invalid Login Attempts.',
    4: 'Your Password is Expired.Please contact Administrator.'
  };
  if(window.location.search.match(/LoginFailed=([1-4])/)) {
    jQuery('#errMsg').show().html(errMessages[window.location.search.match(/LoginFailed=(\d)/)[1]]);
  }
 	
});
