jQuery(function() {
  jQuery(".tab_content").hide(); //Hide all content
  if (ReadCookie('activeSelectedTab')) {
    var activeSelectedTab=ReadCookie('activeSelectedTab');
    var size=jQuery("ul.tabs li").size();
    if (activeSelectedTab == "#tab1") { var n=1;}
    if (activeSelectedTab == "#tab2") { var n=2;}
    if (activeSelectedTab == "#tab3") { var n=3;}
    if (activeSelectedTab == "#tab4") { var n=4;}
    if (activeSelectedTab == "#tab5") { if (size==6) {var n=4;} else {var n=5;}}
    if (activeSelectedTab == "#tab6") { if (size==6) {var n=5;} else {var n=6;}}
    if (activeSelectedTab == "#tab7") { var n=7;}
  
    if (n ==7) {
      jQuery("ul.tabs li:last").addClass("active");
    } else {
      jQuery("ul.tabs li:nth-child("+n+")").addClass("active"); //Remove any "active" class
    }
  
    jQuery(activeSelectedTab).show(); //Show first tab content

  } else {
    jQuery("ul.tabs li:first").addClass("active").show(); //Activate first tab
    jQuery(".tab_content:first").show(); //Show first tab content
  }

  //On Click Event
  jQuery("ul.tabs li").click(function() {

          jQuery("ul.tabs li").removeClass("active"); //Remove any "active" class
          jQuery(this).addClass("active"); //Add "active" class to selected tab
          jQuery(".tab_content").hide(); //Hide all tab content

          var activeTab = jQuery(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
          jQuery(activeTab).show(); //Fade in the active ID content
          CreateCookie('activeSelectedTab',activeTab);

          return false;
  });
});


