$(document).ready(function(){

  var oPageTab = $("ul.toplevel li.active");
  var pagetabsubnav = $("ul.toplevel li.active").children('a').attr('rel');

  var activetab;
  // Top Nav Toggles
  $('ul.toplevel li').mouseover(function(){
    //get the id of this category
    var subnavid = $(this).children('a').attr('rel');
    $('ul.toplevel li').removeClass('active')
    $(this).addClass('active');


    if(subnavid!='hometab' && subnavid!=activetab) {
      $('div.subnav:not(#'+subnavid+')').addClass('hide');
      $('#'+subnavid).removeClass('hide');
      activetab = subnavid;
    }

  });

  // if mousing out of the header reset the active tab and sub menu to be that of the current page
  $('#page-content').mouseover(function(){

    $('ul.toplevel li').removeClass('active');
    oPageTab.addClass('active');
    $('div.subnav:not(#'+pagetabsubnav+')').addClass('hide');
    $('#'+pagetabsubnav).removeClass('hide');
    activetab = pagetabsubnav;

  });


  $('div.slide').each(function(){
    var scb = $(this).children('div.captionblanket');
    var sc  = $(this).children('div.caption');
    var sch = sc.height();
    if(sch && sch>84) {
      scb.css({ height: sch+'px' });
      scb.height(sch);
    }
  });


  //landingpage slideshows
  var cycle_exists = $('#slideshow-inner');

  if (cycle_exists.length != 0) {
    $mainslideshow = $('#slideshow-inner').cycle({
  		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
  		//fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
  		cleartype:  true, // disable cleartype corrections
  		startingSlide: 0,
  		speed:750,
  		timeout:8000
    });
  }
    //carousels

  var carousel_exists = $('#carouselcontainer .carousel');

  if (carousel_exists.length != 0) {
    $("#carouselcontainer .carousel").jCarouselLite({
      btnNext: "#carouselcontainer .next",
      btnPrev: "#carouselcontainer .prev",
      visible: 3,
      speed: 800,
      scroll:1,
      circular: false,
      targetul: '.jcarousel',
  		timeout:8000
    });
  }

  var homepage_exists = $('#homepagecarouselcontainer .carousel');

  if (homepage_exists.length != 0) {
    $("#homepagecarouselcontainer .carousel").jCarouselLite({
      btnNext: "#homepagecarouselcontainer .next",
      btnPrev: "#homepagecarouselcontainer .prev",
      visible: 3,
      speed: 800,
      scroll:1,
      circular: false,
      targetul: '#hpscroller',
  		timeout:8000
    });
  }


  $('a.disabled').click(function(){
    return false;
  });



}); // end document.ready
