$(document).ready(function() {

   $('#header div.nav-holder #nav li:first').addClass('first');

   $('#sidebar #HMSidebarMenu').addClass('accordion');
   $('#sidebar2 #HMSidebarMenu li a').prepend('<span class="ui-icon"></span>');

   $('#sidebar #HMSidebarMenu').children('li').find('a:first').attr('href', '#');
   $('#HMSidebarMenu').children('li').find('a:first').addClass('opener');
   $('#HMSidebarMenu').children('li').find('a:first').wrapInner("<em><span class='holder'><strong></strong></span></em>");

   $('#HMSidebarMenu li ul').wrap("<div class='slide'></div>");

   $('ul.accordion').accordion({
      active: ".selected",
      autoHeight: false,
      header: ".opener",
      collapsible: true,
      event: "click"
   });

   $('ul.accordion2').accordion({
      autoHeight: false,
      header: ".opener",
      collapsible: true,
      fillSpace: true,
      event: "click"
   });

   $('#HMSidebarMenuCurrentItem').addClass('active');
   $('#HMSidebarMenuCurrentItem').parent().parent().parent().find('a:first').addClass('selected');
   $('#HMSidebarMenuCurrentItem').parent().parent().css('display','block');
   $('#HMSidebarMenu').children('#HMSidebarMenuCurrentItem ').find('a:first').addClass('selected');
   
   /* script for freeflyer overview page table */
   $('#FreeFlyerOverview #TD1 div').addClass('displayNone');
   $('#FreeFlyerOverview #TD1 #div1').addClass('displayBlock');
   $('#FreeFlyerOverview #TD2 li a').click(function()
   {
       divId = $(this).attr("id");
       $('#FreeFlyerOverview #TD1 div').addClass('displayNone');
       $('#FreeFlyerOverview #TD1 div').removeClass('displayBlock');
       $('#FreeFlyerOverview #TD1 #div'+divId).addClass('displayBlock');
   });
   /* end script */
  
  var pathname = location.pathname;
  if ('div.footer-nav div ul li a[href= "' + pathname + '"]')
  {
     $('div.footer-nav div ul li a[href= "' + pathname + '"]').parent().addClass("active");
  }
  
  $('#sidebar2 li a[href $= "' + pathname + '"]').addClass('selected');
  
  //Script for Career Fair Schedule //
  $('table.CareerFairSchedule tr:even').css('background-color','#bcbec0');
  
  $('table.ArchivedWebcasts tr:even').css('background-color','#bcbec0');
  
  $('table.FreeFlyerWebcasts tr:even').css('background-color','#bcbec0');
  
  // sitemap script to hide sub ul with only overview page
  $('#HMSiteMap li ul li').each(function(index) {
      var childrenCount = $('ul',this).children().length;
      if(childrenCount < 2)
      {
         $('ul',this).addClass('displayNone');
      }
   });
   
   // Script for Job module //
   
   $('#JobState').change(function () {
         if ($('#JobDept option:selected').text().trim() == '- -')
         {
            $("input[id$='ViewJobQuest_tbSearch']").val($('#JobState option:selected').text()+",Dept:");
         }
         else 
         {
            $("input[id$='ViewJobQuest_tbSearch']").val($('#JobState option:selected').text() + ",Dept:" + $('#JobDept option:selected').text().trim());
         }
   } );
   
   $('#JobDept').change(function () {
         if ($('#JobState option:selected').text().trim() == '- -')
         {
            $("input[id$='ViewJobQuest_tbSearch']").val(",Dept:"+$('#JobDept option:selected').text().trim());
         }
         else
         {
            $("input[id$='ViewJobQuest_tbSearch']").val($('#JobState option:selected').text() + ",Dept:" + $('#JobDept option:selected').text().trim());
         }
   } );
   
   if ($('td.ToolTipSection input.tool_tip').length != 0) {
      var JobSelectedState = $('td.ToolTipSection input.tool_tip').val().substring(0, 2);
      $("td.ToolTipSection #EditJobState").find('option[text=' + JobSelectedState + ']').attr("selected", "selected");
   }

   $("td select[id$='ddlDepartements']").change(function () {
      if($('option:selected',this).text() != '') {
         $('td.ToolTipSection input.tool_tip').val($('td.ToolTipSection #EditJobState option:selected').text()+",Dept:"+$('option:selected',this).text());
      }
   } );
   
   $('td.ToolTipSection #EditJobState').change(function () {
      if($(this).val() != '') {
         $('td.ToolTipSection input.tool_tip').val($(this).val()+",Dept:"+$("td select[id$='ddlDepartements'] option:selected").text());
      }
   } );
   
   // End job module //
   
   $('table.JobApplication tr td').attr('align','left');
   $('table.JobApplication tr td').attr('width','350px');
   $('table.JobApplication tr:nth-child(23)').before('<tr><td colspan="2" style="width:595px;">In accordance with the Federal Immigration and Reform Act of 1986, if you are employed by a.i. solutions, Inc. you will be asked to provide documentation that verifies your legal right to work in the United States. If you cannot provide acceptable documentation, we cannot legally employ you. </td></tr>');
   $('table.JobApplication tr:nth-child(63)').before('<tr><td colspan="2" style="width:595px;"><b>Voluntary Information</b><br/> We consider applicants for all positions without regard to race, color, religion, sex, national origin, marital or veteran status, the presence of a non-job-related medical condition or handicap, or any other legally protected status. As required, a.i. solutions, Inc. must comply with the federal government under Executive Order 11246 including Affirmative Action and ADA obligations where they apply. In an effort to comply with government record keeping and other legal obligations, we ask that you complete this applicant data survey. Please be advised that your survey is not a part of your official application for employment. Submission of information is voluntary, and failure to provide it will not subject you to any adverse treatment. It is considered confidential information that will not be used in any hiring decisions. Your cooperation is greatly appreciated. </td></tr>')
   
   $('table.JobApplication tr:nth-child(10)').insertBefore('table.JobApplication tr:nth-child(3)');
   $('table.JobApplication tr:nth-child(11)').insertBefore('table.JobApplication tr:nth-child(4)');
   $('table.JobApplication tr:nth-child(70)').insertAfter('table.JobApplication tr:nth-child(74)');
   
   $('table.JobApplication tr:nth-child(74)').before('<tr><td colspan="2" style="width:595px;"><b>Important Information</b><br/>' +
   'Under Maryland Law, an employer may not require or demand, as a condition of '+
   'employment, prospective employment, or continued employment, that an individual' +
   'submit to or take a lie detector or similar test. An employer who violates this law is '+
   'guilty of a misdemeanor and subject to a fine not exceeding $100.<br/><br/>' +
    
   'To submit your application you must agree to the following terms:<br/><br/>' +
    
   'I certify that all answers given by me are true, accurate and complete to the best of my' +
   'knowledge. I understand that falsification, misrepresentation or omission of fact on this '+
   'application (or anything accompanying or required documents) is sufficient cause for' +
   'denial of employment or immediate termination of employment, regardless of when or '+
   'who discovered. <br/>'+
    
   'I authorize a.i. solutions, Inc. to investigate all information contained in this application. '+
   'The employers, schools, or individuals named are authorized to give information '+
   'regarding my employment, character and qualifications and are hereby released from '+
   'all liability from issuing such information.<br/><br/> '+
    
   'I understand that if hired, my employment is not for any definite period of time, is not '+
   'governed by any written or oral contract, and is considered an at-will arrangement. This'+
   'means I am free to terminate my employment for any reason, as is a.i. solutions, Inc. so' +
   'long as there is no violation of applicable federal, state or local law. </td></tr>');
   
   $('table.JobApplication tr a[id$="lnkSave"]').click(function() {
      $.cookie('AIS_App_Name', $('table.JobApplication tr td input[id$="txtName"]').val().trim(), { expires: null, path: '/' });
      $.cookie('AIS_App_Email', $('table.JobApplication tr td input[id$="txtEmail"]').val().trim(), { expires: null, path: '/' });
      $.cookie('AIS_App_JobCode', $('table.JobApplication tr td input[id$="txtJobCode"]').val().trim(), { expires: null, path: '/' });
      //alert($.cookie('AIS_App_Name')+","+'AIS_App_Email');
   });

  // Chnage search link from search to >>
  $('#dnn_dnnSEARCH_cmdSearch').html('>>');
  
   if ($('#slideshow').length != 0) {
      $('#slideshow').cycle({
           fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
      });
      
      // redefine Cycle's updateActivePagerLink function 
      $.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex){
         $(pager).find('li').removeClass('active').filter('li:eq(' + currSlideIndex + ')').addClass('active');
      };
      
      $('#slideshow').cycle({
         timeout: 6000,
         pager: '#subnav',
         pagerAnchorBuilder: function(idx, slide){
            return '';
         }
      });
      
      $("#subnav li").hover(
         function () {
            $('#slideshow').cycle('pause');
            $("#subnav li").removeClass('active');
            var LiIndex = ($(this).parent().children().index(this))+1;
            //$('div.intro #slideshow a:nth-child('+LiIndex+')').removeAttr('style').addClass('shwImage');
            $('div.intro #slideshow a').css('z-index','').css('display','none');
            $('div.intro #slideshow a:nth-child('+LiIndex+')').css('z-index','4').css('display','block').css('opacity','1');
         }, 
         function () {
            $('div.intro #slideshow a').removeClass('showImage');
            $('#slideshow').cycle('resume');
         }
      );
      
      $("#subnav2 li").hover(
         function () {
            $('#slideshow').cycle('pause');
            var LiIndex = ($(this).parent().children().index(this))+1;
            //$('td #slideshow div:nth-child('+LiIndex+')').removeAttr('style').addClass('shwImage');
            $('td #slideshow div').css('z-index','').css('display','none');
            $('td #slideshow div:nth-child('+LiIndex+')').css('z-index','4').css('display','block').css('opacity','1');
         }, 
         function () {
            $('td #slideshow div').removeClass('showImage');
            $('#slideshow').cycle('resume');
         }
      );


   }

  
});
