// Navigation Dropdown;
var NAV = {};
NAV.vars = {};
NAV.functions = {
  show:  function(){
    $(this)
    .addClass('open')
    .find('div.dropdownList')
    .stop(true, true)
    .slideDown(
    {
      duration: 200,
      queue: false
    }
    );
  },
  hide:  function(){
    $(this)
    .removeClass('open')
    .find('div.dropdownList')
    .stop(true, true)
    .slideUp(
    {
      duration: 75,
      queue: false
    }
    );
  }
};

var originalHeight = 0;

//main navigation bar
jQuery(function($){
  //Set up the event handler for the main navigation
  $('#navGlobal ul li').hoverIntent({
    sensitivity: 7,               /* number = sensitivity threshold (must be 1 or higher) */
    interval: 50,                  /* number = milliseconds for onMouseOver polling interval */
    over: NAV.functions.show, /* function = onMouseOver callback (REQUIRED) */
    timeout: 100,                 /* number = milliseconds delay before onMouseOut */
    out: NAV.functions.hide   /* function = onMouseOut callback (REQUIRED) */
  });

  //Checks the li items under #navGlobal and adds the dropdownTab class if they contain a nested list (wrapped in a dropdownList div)
  $('#navGlobal ul li div.dropdownList').parent().addClass('dropdownTab');

  //Add orange text to the top link in a tab that is moused over
  $('#navGlobal ul li').hover(function() {
    $(this).children('.navCategoryLink').toggleClass('orangeText');
  });

  //Remove the bottom border from the last li each nav dropdown
  $('#navGlobal ul li div.dropdownList ul').each(function() {
    $(this).children('li:last').addClass('borderBottomNone');
  });

  $('#navGlobal ul li div.dropdownList ol').each(function() {
    $(this).children('li:last').addClass('borderBottomNone');
  });

  //Also sets the width of each dropdownList div based on the number of nested lists contained inside
  $('#navGlobal ul li div.dropdownList').each(function() {
    if($(this).children().length > 1){
      $(this).addClass('dropdownList2Column');
    }
  });

  //Turns the numeric text portion of a link in an ordered list to orange when moused over
  $('#navGlobal ul li div.dropdownList ol li a').hover(function() {
    $(this).siblings('.numericNavLabel').toggleClass('orangeText');
  });
});

//Vertical Scroll
jQuery(function($){

  $(".textScrollBox").each(function(){ //loop through all the text scroll boxes

    var idPrefix = $(this).attr("id").split("ScrollBox").join(""); //all scroll box elements follow the naming convention [idPrefix]ScrollBox, [idPrefix]ScrollText, etc...

    var containerHeight = $("#" + idPrefix + "ScrollBox").css("height").split("px").join(""); //get the height of the outer box (shave off the "px" that css() will return)

    var textBoxHeight = 3000; //some boxes may be loading content dynamically via Javascript, so we won't know initially how big the inner text box might be.. use a large number initially and we will resize based on the content inside once the scroll down button is pressed

    var scrollDownLimit = containerHeight - textBoxHeight; //the down scroll limit will be the difference in the height of the inner box and the height of the outer box
    var scrollUpLimit = 0; //the up scroll limit is simply the top of the outer box (0px since the inner container is positioned absolutely in relation to the outer)

    var downButton = $("#" + idPrefix + "ScrollButtonDown");
    var upButton = $("#" + idPrefix + "ScrollButtonUp");
    var textBox = $("#" + idPrefix + "ScrollText");

    function scrollUpBoundaryCheck (textTopCurrentPosition) { //this function just checks to see if the inner element has hit the scroll up limit boundary
      if(textTopCurrentPosition == scrollUpLimit){
        return true;
      }
      else{
        return false;
      }
    }
    function scrollDownBoundaryCheck (textTopCurrentPosition) { //this function just checks to see if the inner element has hit the scroll down limit boundary
      if(textTopCurrentPosition == scrollDownLimit){
        return true;
      }
      else{
        return false;
      }
    }

    function scrollRate (boundaryPosition, textTopCurrentPosition) { //this function calculates the scroll rate based on how much is left to scroll
      difference = boundaryPosition - textTopCurrentPosition;
      if(difference < 0){
        difference *= -1;
      }

      return (difference * 5); //will scroll at a rate of 200px/second, no matter where the scroll starts
    }

    downButton.mousedown(function(){	//when the button is pressed, begin animating the inner box towards the scroll limit

      if(upButton.hasClass("inactive")){
        upButton.removeClass("inactive"); //if the up button is inactive when we start a downward scroll, make it active again
      }

      //get the current position of the top of the text box
      var textBoxTopCurrentPosition = textBox.css("top").split("px").join("");

      //and recalculate the size of the box (now that any dynamic content has had a chance to finish loading
      textBoxHeight = $("#" + idPrefix + "ScrollText").css("height").split("px").join("");
      //and recalculate the scrolldown limit
      scrollDownLimit = containerHeight - textBoxHeight;

      //the rate is calculated based on the distance from the boundary, so that no matter where we are, our animation will always go at about 200px per second
      rate = scrollRate(scrollDownLimit, textBoxTopCurrentPosition);

      textBox
      .stop()	//always want to stop any animation that may be going on to be safe
      .animate({
        'top': scrollDownLimit
      }, rate); //animate the box towards the end limit

      if(scrollDownBoundaryCheck(textBoxTopCurrentPosition)){
        downButton.addClass('inactive'); //if at the end of this animation, we have hit the boundary, make the button inactive
      }

    });
    downButton.mouseup(function(){
      var textBoxTopCurrentPosition = textBox.css("top").split("px").join("");
      textBox.stop();	//if the user stops pressing the button, stop the animation

      if(scrollDownBoundaryCheck(textBoxTopCurrentPosition)){
        downButton.addClass('inactive'); //this is a just-in-case check...  probably won't occur often
      }
    });
    downButton.mouseout(function(){
      var textBoxTopCurrentPosition = textBox.css("top").split("px").join("");
      textBox.stop(); //or if the user's mouse leaves the button before mouseup is detected, stop the animation

      if(scrollDownBoundaryCheck(textBoxTopCurrentPosition)){
        downButton.addClass('inactive'); //this is a just-in-case check...  probably won't occur often
      }
    });


    upButton.mousedown(function(){
      var textBoxTopCurrentPosition = textBox.css("top").split("px").join("");

      if(downButton.hasClass("inactive")){
        downButton.removeClass("inactive");	//if the down button is inactive when we start an upward scroll, make it active again
      }

      rate = scrollRate(scrollUpLimit, textBoxTopCurrentPosition); //the rate will change depending on how close we are to a boundary

      textBox
      .stop()
      .animate({
        'top': scrollUpLimit
      }, rate);

      if(scrollUpBoundaryCheck(textBoxTopCurrentPosition)){
        upButton.addClass('inactive'); //if at the end of this animation, we have hit the boundary, make the button inactive
      }
    });
    upButton.mouseup(function(){
      var textBoxTopCurrentPosition = textBox.css("top").split("px").join("");
      textBox.stop();

      if(scrollUpBoundaryCheck(textBoxTopCurrentPosition)){
        upButton.addClass('inactive');
      }
    });
    upButton.mouseout(function(){
      var textBoxTopCurrentPosition = textBox.css("top").split("px").join("");
      textBox.stop();

      if(scrollUpBoundaryCheck(textBoxTopCurrentPosition)){
        upButton.addClass('inactive');
      }
    });
  });
});

//Dropdown buttons
jQuery(function($){

  //this array stores the IDs of the special buttons that contain dropdown link lists


  // Kaverisoft Addition here: Added: helpTopicButtonATE

  var dropdownButtonIDs = ["selectAnotherTopicButton", "helpTopicButton", "helpTopicsRightRailButton", "helpTopicButtonATE"];

  //set up the event handlers for the special buttons that contain dropdown link lists
  // jQuery.each(dropdownButtonIDs, function(){
  //loop through the array of special button IDs and add the dropdown event handlers to each
  $("#selectAnotherTopicButton, #helpTopicButton, #helpTopicsRightRailButton, #helpTopicButtonATE, .helpTopicButton")
  .hoverIntent({
    sensitivity: 7,               /* number = sensitivity threshold (must be 1 or higher) */
    interval: 50,                  /* number = milliseconds for onMouseOver polling interval */
    over: NAV.functions.show, /* function = onMouseOver callback (REQUIRED) */
    timeout: 100,                 /* number = milliseconds delay before onMouseOut */
    out: NAV.functions.hide   /* function = onMouseOut callback (REQUIRED) */
  })
  .find("div.dropdownList ul li")
  .hover(function() {
    $(this).toggleClass('hover'); //give each individual li item in a dropdown menu a hover state
  })
  .end();

  // });

  //setup the mouseover event handlers for all other large color buttons, EXCLUDING the dropdown buttons
  $('.largeColorButton').each(function(){ //check all the large color buttons
    var id = $(this).attr('id'); // and check their id's
    // Kaverisoft Addition here: Added: helpTopicButtonATE
    if(id != "selectAnotherTopicButton" && id != "helpTopicButton" && id != "helpTopicsRightRailButton" && id != "helpTopicButtonATE"){ //if they are NOT a special case button that has a dropdown menu
      $(this).hover(function() {
        $(this).toggleClass('largeColorButtonHover'); //give them the hover function to turn their internal text to gray
      });
    }
  });
});

//Other MouseOver event handlers
jQuery(function($){

  /* this adds a hover event listener to images within links that have on/off image pairs
 * for example <a href="#" class="mouseOverBehavior_icon"><img src="icon-off.jpg" /> and some link text</a>
 * (this will swap the image path to icon-on.jpg when hovered over anywhere in the link)
 */
  $('.mousOverBehavior_icon').hover(
    //note that we're targeted a child image of the link, which may also contain text so that the mouseOver event will stay in the active state whether the user's mouse is over the image or the text
    function () {
      $(this)
      .children('img')
      .attr(
        "src",
        $(this)
        .children('img')
        .attr("src")
        .split('-off')
        .join('-on')
        );
    },
    function () {
      $(this)
      .children('img')
      .attr(
        "src",
        $(this)
        .children('img')
        .attr("src")
        .split('-on')
        .join('-off')
        );
    }
    );

  $('#blogSearchFormButton').hover(
    function () {
      $(this).attr(
        "src",
        $(this)
        .attr("src")
        .split('-off')
        .join('-on')
        );
    },
    function () {
      $(this).attr(
        "src",
        $(this)
        .attr("src")
        .split('-on')
        .join('-off')
        );
    }
    );

  //adds the grey color to moused over items in the left nav
  $('#leftNav ol li').hover(function() {
    $(this).toggleClass('active');
  });
  $('#leftNav ol li:last').addClass('last');

  //add hoverclass for other button
  $('#twitterHomeScrollButtonUp, #twitterHomeScrollButtonDown, #textCarouselBoxButtonLeft, #textCarouselBoxButtonRight').hover(function() {
    $(this).toggleClass('hover');
  });
});

//Add event handlers for form elements
jQuery(function($){
  $('.submitButton').each(function(){ //any image buttons with the class .submitButton . . .
    $(this).click(function(){
      $(this).parents('form').submit(); //will cause their parent form to be submitted when they are clicked
    });
  });

  $('.radioSubmit').each(function(){ //any radio buttons that have the class .radioSubmit . . .
    $(this).change(function(){
      $(this).parents('form').submit(); //will cause their parent form to be submitted when they are clicked
    });
  });

  $('#searchBoxFormInput').attr('value', 'search'); //make sure the search box has the default large "search" text when the page is loaded
  // (this prevents browsers from populating it with the text that was previously submitted after a user hits the back button, which looks funny at the larger starting size)
  $('#searchBoxFormInput').click(function(){
    $(this)
    .addClass('active') //change the size of the text in the search box, and modify css to keep box the right size for smaller text
    .attr('value', '') //clear the field
    .unbind('click'); //and remove the event handler (we only want to clear the form and change the css when first clicked)
  });
  $('#searchBoxFormInput').focusout(function(){
    if($(this).attr('value') == ""){ //if the user clicked on the search box but entered nothing . . .
      $(this)
      .attr('value', 'search') //set the value back to 'search'
      .removeClass('active') //take off the active class
      .click(function(){ //and put the event handler back into place
        $(this)
        .addClass('active') //change the size of the text in the search box, and modify css to keep box the right size for smaller text
        .attr('value', '') //clear the field
        .unbind('click'); //and remove the event handler (we only want to clear the form and change the css when first clicked)
      });
    }
  });

  $('#askYourQuestionFormInput').click(function(){
    $(this).attr('value', ''); //clear the field
    $(this).unbind('click'); //and remove the event handler (we only want to clear the form when first clicked)
  });
  $('#askYourQuestionFormInput').focusout(function(){
    if($(this).attr('value') == ""){ //if the user clicked on the input field but entered nothing . . .
      $(this)
      .attr('value', 'start by typing your question here...') //set the value back to default
      .click(function(){ //and put the event handler back into place
        $(this)
        .attr('value', '') //clear the field
        .unbind('click'); //and remove the event handler
      });
    }
  });

  $('#page-missing-search').click(function(){
    $(this).attr('value', ''); //clear the field
    $(this).unbind('click'); //and remove the event handler (we only want to clear the form when first clicked)
  });
  $('#page-missing-search').focusout(function(){
    if($(this).attr('value') == ""){ //if the user clicked on the input field but entered nothing . . .
      $(this)
      .attr('value', 'click to search') //set the value back to default
      .click(function(){ //and put the event handler back into place
        $(this)
        .attr('value', '') //clear the field
        .unbind('click'); //and remove the event handler
      });
    }
  });

  $('#feedback-user-name').click(function(){
    $(this).attr('value', ''); //clear the field
    $(this).unbind('click'); //and remove the event handler (we only want to clear the form when first clicked)
  });
  $('#feedback-user-name').focusout(function(){
    if($(this).attr('value') == ""){ //if the user clicked on the input field but entered nothing . . .
      $(this)
      .attr('value', 'Name') //set the value back to default
      .click(function(){ //and put the event handler back into place
        $(this)
        .attr('value', '') //clear the field
        .unbind('click'); //and remove the event handler
      });
    }
  });

  $('#feedback-user-email').click(function(){
    $(this).attr('value', ''); //clear the field
    $(this).unbind('click'); //and remove the event handler (we only want to clear the form when first clicked)
  });
  $('#feedback-user-email').focusout(function(){
    if($(this).attr('value') == ""){ //if the user clicked on the input field but entered nothing . . .
      $(this)
      .attr('value', 'Email') //set the value back to default
      .click(function(){ //and put the event handler back into place
        $(this)
        .attr('value', '') //clear the field
        .unbind('click'); //and remove the event handler
      });
    }
  });

  $('#feedback-user-comment').click(function(){
    $(this).attr('value', ''); //clear the field
    $(this).unbind('click'); //and remove the event handler (we only want to clear the form when first clicked)
  });
  $('#feedback-user-comment').focusout(function(){
    if($(this).attr('value') == ""){ //if the user clicked on the input field but entered nothing . . .
      $(this)
      .attr('value', 'Comment') //set the value back to default
      .click(function(){ //and put the event handler back into place
        $(this)
        .attr('value', '') //clear the field
        .unbind('click'); //and remove the event handler
      });
    }
  });


});

//Print link event handler
jQuery(function($){
  $('.printLink').click(function(){
    window.print() ;
    return false;
  });
});

//Add event handler to display Facebook comment box when AddThis "like" link is mousedover
jQuery(function($){
  $('#realStoriesFBWrapper').mouseover(function(){ //note that we are using mouseover, not click, because you can't capture a click event in an iframe (which is how the Facebook content is loaded)
    $('#realStoriesFBCommentBox')
    .animate({
      height: 'show'
    }, 'slow');
  });
});

//Twitter Feed - (Home and Blog pages)
jQuery(function($){
  //initiate the twitter box for the home page
  $("#twitterHomeScrollBox .tweet").tweet({
    username: ["lifetuner"],
    avatar_size: 42,
    count: 10,
    template: "<div class='imageBox'>{avatar}</div><div class='textBox'><strong>{screen_name}</strong><br />{text}<br /><span class='smallGray'>{tweet_relative_time}</span></div><div class='clear'></div>",
    loading_text: "loading tweets...",
	refresh_interval: 120
  });

  //initiate the twitter box for the blog page
  $("#twitterBlogScrollBox .tweet").tweet({
    username: "lifetuner",
    avatar_size: 32,
    count: 10,
    template: "{text}<br /><span class='tweetFooterRow'>{time} &bull; {reply_action} &bull; {retweet_action}</span>",
    loading_text: "loading tweets...",
	refresh_interval: 120
  });
});


//left nav control
jQuery(function($){

  // define namespace for left navigation;
  var leftNav = {};
  // navigation functions;
  leftNav.f = {
    over: function() {
      $('#leftNav').animate(
      {
        width: 286
      },
      {
        duration : 500,
        easing   : 'easeInQuint'
      }
      );
    },
    out: function() {
      $('#leftNav').animate(
      {
        width: 16
      },
      {
        duration : 500,
        easing   : 'easeInOutQuint'
      }
      );
    }
  };
  // navigation variables;
  leftNav.v = {
    config: {
      over:    leftNav.f.over, // function = onMouseOver callback (REQUIRED)
      timeout: 500,        // number = milliseconds delay before onMouseOut
      out:     leftNav.f.out   // function = onMouseOut callback (REQUIRED)
    },
    delay: 1000
  };


  $('#leftNav')
  .hoverIntent(leftNav.v.config) // initialize hoverIntent plugin;
  .delay(leftNav.v.delay)        // wait, we want the navigation to be visible for a bit before closing it;
  .queue(function(){
    // if the user is hovering over the nav, don't close it;
    if($.browser.msie && $.browser.version < 8) {
      leftNav.f.out();
    }
    else {
      if($('#leftNav:hover').size() === 0 && $('#leftNav a:hover').size() === 0) {
        leftNav.f.out();
      }
    }

    $(this).dequeue();
  });
});

jQuery(function($){
  // loop through each slideshow
  $('#textCarouselBoxContent').each(function(i){
    var slideshow = {};

    // define the variables
    slideshow.vars = {
      // settings for the cycle plugin
      config: {
        fx:               'fade',                             // name of transition effect (or comma separated names, ex: fade,scrollUp,shuffle)
        speed:            1000,                             // speed of the transition (any valid fx speed value)
        timeout:          8000,                               // milliseconds between slide transitions (0 to disable auto advance)
        pager:            '#textCarouselBoxCircleButtonsRow', // selector for element to use as pager container
        prev:             '#textCarouselBoxButtonLeft',       // selector for element to use as click trigger for previous slide
        next:             '#textCarouselBoxButtonRight',      // selector for element to use as click trigger for next slide
        pause:            true,                               // true to enable "pause on hover"
        activePagerClass: 'activeButton'                      // class name used for the active pager link
      }
    };

    // add the necessary HTML and initialize the cycle plugin
    $(this).cycle(slideshow.vars.config);
  });
});

jQuery(function($){
  var speedOpen  = 1250; // how fast the carousel slides open;
  var speedClose = 500;  // how fast the carousel slides closed;

  // loop through each carousel;
  $('div.carouselHidden')
  .find('div.more a')
  .click(function(e){
    // open the carousel;
    e.preventDefault();
    $('div.carouselNav').css('height','12px')
    $(this)
    .parents('div.carouselHidden')
    .find('div.hiddenContainer')
    .slideDown(speedOpen);
  })
  .end()
  .find('div.carousel')
  .each(function(i){
    // assign a unique id;
    var id = 'carouselContainer' + i;
    // find the title of this carousel;
    var title = $(this).attr('data-title');

    var carousel = {
      // carousel navigation (previous, next);
      nav: '<div class="carouselNav"><a class="carouselNavPrev">Previous</a><a class="carouselNavNext">Next</a></div>',
      // settings for the cycle plugin;
      config: {
        fx:               'scrollHorz',                       // name of transition effect (or comma separated names, ex: fade,scrollUp,shuffle);
        speed:            1000,                               // speed of the transition (any valid fx speed value);
        timeout:          0,                                  // milliseconds between slide transitions (0 to disable auto advance);
        prev:             '#' + id + ' a.carouselNavPrev',    // selector for element to use as click trigger for previous slide;
        next:             '#' + id + ' a.carouselNavNext'     // selector for element to use as click trigger for next slide;
      }
    };

    // add the necessary HTML and initialize the cycle plugin;
    if ($(this).attr('id') == 'real-stories-carousel')
    {
      carousel.nav = '<div class="carouselNav"></div>';
    }
    $(this)
    .wrap('<div class="carouselContainer" id="' + id + '"></div>') // wrap the slideshow in a container;
    .after(carousel.nav)                                           // add the navigation to the container;
    .cycle(carousel.config)                                        // initialize the cycle plugin;
    .next()
    .append('<a class="close">X</a>')  // create a close button;
    .find('a.close')
    .click(function(e){                // make the close button functional;
      e.preventDefault();

      $(this)
      .parents('div.hiddenContainer')
      .slideUp(speedClose);
    })
    .end()
    .append('<p class="watching">You&rsquo;re watching Series title: <strong>' + title + '</strong></p>');
  })
  .end()
  .find('div.hiddenContainer')
  .hide(); // hide by default;

  //hook this up to the buttons added in config
  $('.carouselSwitchNavPrev').click(function(e){
    e.preventDefault();
    $('.carouselNavPrev').click();
  });
  $('.carouselSwitchNavNext').click(function(e){
    e.preventDefault();
    $('.carouselNavNext').click();
  });
});



//AddThis customization;
var addthis_config = {
  //"data_track_clickback":true,
  ui_offset_left: -200
};

/* Kaverisoft Additions */
Constants = {};
Constants.htmlCodes = {};
Constants.functions = {};
Constants.htmlCodes.youtubeEmbedCode = '<iframe width="560" height="349" src="http://www.youtube.com/embed/{ID}?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>';
Constants.functions.hideQuestion = function(){
  $('#askYourQuestionInputText').html($('#askYourQuestionFormInput').val());
  $('#askYourQuestionInputField').hide();
  $('#askYourQuestionInputText').show();
}

jQuery.ajaxSetup({
  'beforeSend': function(xhr) {
    xhr.setRequestHeader("Accept", "text/javascript")
  }
})


jQuery(document).ready(function($){
  $('a[rel*=facebox]').facebox();
  $('#navGlobal a.noLink').click(function(e){
    e.preventDefault();
  })
  $('div.toolsSummary').last().addClass('noBdr')

  /* ATE Javascript start */
  $('li.li-helpTopicExpert').click(function(e){
    e.preventDefault();
    $(this).closest('form').find('input[name*="topic_id"]').val($(this).data('id'))
    $(this).closest('form').submit()
  })

  $('a.helpTopicATE').click(function(e){
    e.preventDefault();
    $(this).closest('form').find('input[name*="topic_id"]').val($(this).data('id'))
    $(this).closest('form').submit()
  })

  $('div.helpTopicButton').click(function(e){
    e.preventDefault();
    $(this).closest('form').find('input[name*="topic_id"]').val($(this).data('id'))
    $(this).closest('form').submit()
  })

  $('li.li-helpTopicATE').click(function(e){
    $(this).closest('form').find('input[name*="topic_id"]').val($(this).data('id'))
    $(this).closest('form').submit()
  })

  $('a.helpTopicMTE').click(function(e){
    e.preventDefault();
    $(this).closest('form').find('input[name*="topic_id"]').val($(this).data('id'))
    $(this).closest('form').submit()
  })
  //adding color to in this checklist text(ticket 306)
  $('#in_this_ChecklistBox').find('li').each(function(index) {
    $(this).html('<span style="color:#666666;">'+$(this).html()+'</span>');
  });
  $('#in_this_ChecklistBox').find('ul').each(function(index) {
    $(this).addClass('displayBullets');
  });
  if($.browser.msie && $.browser.version < 8) {
    $('#in_this_ChecklistBox ol').find('li').each(function(index) {
      $(this).css({
        'margin':'0 0 3px 22px'
      });
    });
  }

  //feedback form email validation
  $('#submit_feedback').click(function() {

    $("#error").remove();
    var hasError = false;
    var emailReg = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;

    var emailaddressVal = $("#feedback-user-email").val();
    var feedbackVal = $("#feedback-user-comment").val();

    if(feedbackVal  == 'Comment') {
      hasError = true;
    }

    if(emailaddressVal == 'Email') {
      $("#feedback-user-email").after('<div id="error" style="text-align: center;margin: 5px; color: red;">Please enter your email ID</div>');
      hasError = true;
    }

    else if(!emailReg.test(emailaddressVal)) {
      $("#feedback-user-email").after('<div id="error" style="text-align: center;margin: 5px; color: red;">Please enter a valid email ID</div>');
      hasError = true;
    }
    if(hasError == true) {
      return false;
    }
    else{$("#feedback_form").submit();}
  });
  //end of email validation
  var path_expert = window.location.pathname
  if(path_expert == '/ask-a-question/meet-the-experts' || path_expert == '/ask-a-question/meet-the-experts/'){
    window.location.pathname = '/experts'
  } 
  $('.middleColumnContent').find('a').each(function(index){
    if($(this).attr('href') == null){

      $(this).css({
        'color':'inherit',
        'font-size':'inherit',
        'font-weight':'inherit',
        'text-decoration':'inherit'
      });//div.middleColumnContent a
    }
  });
  $('#submitFormB').click(function(index){

    $('#new_member_session').submit();

  });
  /* if(window.location.pathname == '/login' ){
      $('#loginBox').find('a').each(function(index) {
          if($(this).html() == 'Logout'){
              alert('');
           window.location.href = window.location.href;
          }
      });
  }*/
  /* $('#videoCarousel').find('embed').each(function(index){
      alert('before:'+$(this).attr('wmode'));
    $(this).attr({'wmode':'opaque'});
    alert('after:'+$(this).attr('wmode'));
 });*/
  var path = (window.location.pathname).split('/')
  //Individual Essentials page: Left rail "Related Help Topics" module displays "Homepage" within it(ticket 223)
  if(path[1] == 'the-essentials'){
    if(path.length >= 4){
      $('.leftRailBox').find('a').each(function(index) {
        if($(this).html() == 'Home Page'){
          $(this).hide();
        }
      });
    }
  }
  //life event detailed pages left rail should not have view all topics link (ticket 206)
  /*if(path[1] == 'life-events'){//as now it is not needed
        if(path.length >= 5){
            $('a[href$="/topics-a-z/"]').hide()
        }
    }*/
  /*if(path[1] == 'life-events'){
        
    if(path.length >= 4){
      $('.middleColumnContent').find('p').each(function(index) {
        var textarr = ($(this).text()).split(' ');
        if(textarr.length >= 50){
          var obj;
          var texthtml = '';
          for(var i = 0;i < 50 ;i++){

            texthtml = texthtml + ' ' + textarr[i]
          }
        
          var fulltext = $(this).text()
          $(this).html(texthtml +'...'+'<div><a style="cursor:pointer;" id='+ index +'>read More<img alt="" style="margin:0 0 1px;cursor:pointer;" src="/img/arrowLinkRight-on.jpg"/></a></div>');
          obj = $(this);
      
          $('#'+index).bind("click",(function(e){
            // var l = "less";
            // $(obj).html(fulltext +'<div><a style="cursor:pointer;" id='+ l + index +'>Read less</a></div>');
            $(obj).html(fulltext );
          /*$('#less'+index).live("click",(function(e){
                            $(obj).html(texthtml +'<div><a style="cursor:pointer;" id='+ index +'>Read more</a></div>');
                        }))*///this comment is needed
                
  /*    }))
        }
      });
    }
  }*/
  $('#continueBtn').click(function(e){
    e.preventDefault();
    $(this).hide()
    $('#tid').addClass("t")
    $('#mid').addClass("m")
    $('#bid').addClass("b")
    //$('#askYourQuestionFormInput').removeAttr('style');
    //$('#askYourQuestionflashingCursoraftercont').show();
    $('#askYourQuestionflashingCursor').hide();
    $(this).closest('form').find('.hiddenForm').show();
    //$('#askYourQuestionFormInput').css('background-color','#F2F8FF')
    var reg = /\S/
    var test_result  = reg.test($('#askYourQuestionFormInput').val()) && $('#askYourQuestionFormInput').val() != 'start by typing your question here...'
    if(test_result)
    {
      Constants.functions.hideQuestion();
    }

  })
  $('a.helpTopicATEQ').click(function(e){
    e.preventDefault();
    /* Put in some logic so that text-field turns text */
    //Constants.functions.hideQuestion();
    $(this).closest('form').find('input[name*="topic_id"]').val($(this).data('id'))
    $(this).closest('form').find('span.selection').html($(this).html());
    $(this)
    .closest('form')
    .find('div.dropdownList')
    .stop(true, true)
    .slideUp(
    {
      duration: 75,
      queue: false
    }
    );
  })

  $('li.helpTopicATEList').click(function(e){
    e.preventDefault();
    $(this).closest('form').find('input[name*="topic_id"]').val($(this).data('id'))
    $(this).closest('form').find('span.selection').html($(this).find('a.helpTopicATEQ').html());
    $(this)
    .closest('form')
    .find('div.dropdownList')
    .stop(true, true)
    .slideUp(
    {
      duration: 75,
      queue: false
    }
    );
  })

/* $('#askYourQuestionInputText').click(function(e){
        $('#askYourQuestionInputField').show();
        $('#askYourQuestionFormInput').focus();
        $('#askYourQuestionInputText').hide();
    })

    originalHeight = $('#askYourQuestionFormInput').height();

  $('#askYourQuestionFormInput').keyup(function(e) {
    if ($(this)[0].scrollHeight > $(this).height()) {
      $(this).height(originalHeight * Math.ceil($(this)[0].scrollHeight / originalHeight))
    }
  });
	
  $('#askYourQuestionFormInput').focusin(function(e) {
    if ($(this)[0].scrollHeight > $(this).height()) {
      $(this).height(originalHeight * Math.ceil($(this)[0].scrollHeight / originalHeight))
    }
  }); */

$('input.datepicker').datepicker(); /* If you want to comment this again - talk to Swanand first */
$('form.new_question').submit(function(e){
  e.preventDefault();
  var reg = /\S/
  var test_result  = reg.test($('#askYourQuestionFormInput').val()) && $('#askYourQuestionFormInput').val() != 'start by typing your question here...'
  if(test_result)
  {
    Constants.functions.hideQuestion();
  }
  $.ajax({
    url: $(this).attr('action'),
    data: $(this).serialize(),
    type: 'POST'
  })
});

$('#askYourQuestionBox-dropDown input.email').focusin(function(){
  if($(this).val() == 'Email address'){
    $(this).val('');
  }
})
$('#askYourQuestionBox-dropDown input.email').focusout(function(){
  if($(this).val() == ''){
    $(this).val('Email address');
  }
})
$('#askYourQuestionBox-dropDown input.username').focusin(function(){
  if($(this).val() == 'Screen name'){
    $(this).val('');
  }
})
$('#askYourQuestionBox-dropDown input.username').focusout(function(){
  if($(this).val() == ''){
    $(this).val('Screen name');
  }
})

/* ATE Javascript ends */

// Meet the expert page tool tip starts
$(".expert_biography").mouseover(function(){
  var id = $(this).attr('id');
  $("#flyout-holder"+id+" > .flyout").show();
})
$(".expert_biography").mouseout(function(){
  var id = $(this).attr('id');
  $("#flyout-holder"+id+" > .flyout").hide();
})

$(".expert_biography").click(function(){
  var expert_link = $(this).data('url');
  window.location = expert_link ;
})

// Meet the expert page tool tip ends
//Widget FAQ tab starts
$('.tab-content-right').hide();
$('#tab_1_content').show();

$('.tab').mouseover(function(){
  var id = $(this).attr('id');
  $('#'+id).addClass('li_hover');
});
$('.tab').mouseout(function(){
  var id = $(this).attr('id');
  $('#'+id).removeClass('li_hover');
});

$('.tab').click(function(){
  var id = $(this).attr('id');
  $('.tab-content-right').hide();
  $('.tab').removeClass('active');
  $('#'+id).addClass('active');
  $('#'+id+'_content').show();
});
//Widget FAQ tab ends

$('#show_answer_box a').click(function(e){
  e.preventDefault();
  $('#add_my_answers').show()
  $('#show_answer_box').hide()
  $('#hide_answer_box').show()
})

$('#hide_answer_box a').click(function(e){
  e.preventDefault();
  $('#add_my_answers').hide()
  $('#show_answer_box').show()
  $('#hide_answer_box').hide()
})

$('a.youtube-video').click(function(e){
  e.preventDefault();
  var embed_code = Constants.htmlCodes.youtubeEmbedCode.replace(new RegExp('\{ID\}', 'g'), $(this).data('id'));
  $.facebox(embed_code);
});
$('a.youtube-home-video').click(function(e){
  e.preventDefault();
  $.facebox('<object style="height: 390px; width: 640px"><param name="movie" value="http://www.youtube.com/v/7h8da8X0pEM?version=3"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed id="millenials" name="millenials" src="http://www.youtube.com/v/7h8da8X0pEM?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"></object>');
});

$('a.youtube-botright-video').click(function(e){
  e.preventDefault();
  $.facebox('<object style="height: 390px; width: 640px"><param name="movie" value="http://www.youtube.com/v/tvVAZARYYVs?version=3"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="http://www.youtube.com/v/tvVAZARYYVs?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"></object>');
});
// FAQs hide and show
$('div.aaqFaqRow .more-list').hide();
$('div.more-icon').click(function(e){
  e.preventDefault();
  $(this).hide();
  $(this).closest('.aaqFaqRow').find('div.more-list').show();
  $(this).siblings('div.less-icon').show();
});

$('div.less-icon').click(function(e){
  e.preventDefault();
  $(this).hide();
  $(this).closest('.aaqFaqRow').find('div.more-list').hide();
  $(this).siblings('div.more-icon').show();
});

// Toosl hide and show
$('div.toolsSummary .more-list').hide();
$('div.more-icon').click(function(e){
  e.preventDefault();
  $(this).hide();
  $(this).closest('.toolsSummary').find('div.more-list').show();
  $(this).siblings('div.less-icon').show();
});

$('div.less-icon').click(function(e){
  e.preventDefault();
  $(this).hide();
  $(this).closest('.toolsSummary').find('div.more-list').hide();
  $(this).siblings('div.more-icon').show();
});

//$('div.more').hide();
$('div.more').click(function(e)
{
  //e.preventDefault();
  $('div.carouselInfo').hide();
})
$('.close').click(function(e)
{
  e.preventDefault();
  $('div.carouselInfo').show(200);
})

$('#edit_question').click(function(e){
  $('#edit_my_question').show()
  $('#hide_question').show()
  $('#edit_question').hide()
  e.preventDefault();
})

$('#hide_question').click(function(e){
  $('#edit_my_question').hide()
  $('#hide_question').hide()
  $('#edit_question').show()
  e.preventDefault();
})

 
$('div.headerRow').find('div.dropdownList').find('ul')
if ($('div.headerRow').find('div.dropdownList').find('ul').length > 1)
{
  var width = $('div.headerRow').find('div.dropdownList').find('ul').width();
  $('div.headerRow').find('div.dropdownList').width((width*2)+2);
  $('div.headerRow').find('div.dropdownList').find('ul:odd > li:last').css('border-bottom','1px solid #C13F00')
}
else {
  $('div.headerRow').find('div.dropdownList').width('auto')
}
var char_count = 0
$('#askYourQuestionInputField textarea').bind('keypress input paste', function() {
  var count = $(this).val().split(/\w+/).length - 1;
  if (count <= 100)
  {
    char_count = $(this).val().length
  }
  else
  {
    $(this).val($(this).val().substring(0, char_count))
  }
})

var prev_page = '<div><div style="float:left;margin-right: 3px;margin-top: -1px;"><img src="/images/arrowLinkLeft-on.jpg" /></div><div style="float:left">Previous</div><div class="clear"></div></div>'
var next_page = '<div><div style="float:right;margin-left: 3px;margin-top: -1px;"><img src="/images/arrowLinkRight-on.jpg" /></div><div style="float:right">Next</div><div class="clear"></div></div>'

var disabled_prev_page = '<div><div style="float:left;margin-right: 3px;margin-top: -1px;"><img src="/images/arrowLinkLeft-off.jpg" /></div><div style="float:left">Previous</div><div class="clear"></div></div>'
var disabled_next_page = '<div><div style="float:right;margin-left: 3px;margin-top: -1px;"><img src="/images/arrowLinkRight-off.jpg" /></div><div style="float:right">Next</div><div class="clear"></div></div>'

$('div.pagination a.prev_page').html(prev_page)
$('div.pagination a.next_page').html(next_page)
$('div.pagination span.disabled.prev_page').html(disabled_prev_page)
$('div.pagination span.disabled.next_page').html(disabled_next_page)

$('div.pagination .next_page').insertBefore('div.pagination .prev_page')
$('div.pagination a.prev_page').after('<a class="pagination-left-arrow" href="#"><img src="/images/arrowLinkLeft-on.jpg" /></a>')
var href = $('div.pagination .prev_page').attr('href')
$('.pagination a.pagination-left-arrow').attr('href',href)

var obj = $('div.pagination a:last').next('span.current')
if (obj.html())
{
  $('div.pagination span.current').after('<a class="pagination-right-arrow" href="#"><img src="/images/arrowLinkRight-off.jpg" /></a>')
}
else
{
  $('div.pagination a:last').after('<a class="pagination-right-arrow" href="#"><img src="/images/arrowLinkRight-on.jpg" /></a>')
  href = $('div.pagination .next_page').attr('href')
  $('.pagination a.pagination-right-arrow').attr('href',href)
}
$('div.pagination span.disabled.prev_page').after('<a class="pagination-left-arrow" href="#"><img src="/images/arrowLinkLeft-off.jpg" /></a>')

// Ask a question pagination script
prev_page = '<div><div style="float:left;margin-right: 3px;margin-top: -1px;"><img src="/images/arrowLinkLeft-on.jpg" /></div><div style="float:left">Previous</div><div class="clear"></div></div>'
next_page = '<div><div style="float:right;margin-left: 3px;margin-top: -1px;"><img src="/images/arrowLinkRight-on.jpg" /></div><div style="float:right">Next</div><div class="clear"></div></div>'
$('.sitemap ul li').find('ul#has_child').hide();
$('.sitemap ul li').click(function(){
  $(this).children('ul').show();
})

$('.exit_preview').click(function(){
  window.close()
})

/* Tools & Widgets landing page tools list */
var dropdown_topic_name
$('div.tw-tools-list li').click(function(e){
  dropdown_topic_name = $(this).html()

  $('div.toolsSummary').each(function(){
    if ($(this).find('h2').html() == dropdown_topic_name)
    {
      $('div.toolsSummary').hide();
      $(this).show()
    }
  })
})


$('div.browse-by-topic-tools > a#current-topic-link').click(function(e) {
  e.preventDefault();
  $('div.toolsSummary').show();
})

/* Tools & Widgets landing page tools list ENDS HERE*/

$('#submit_feedback').click(function(e){
  $('#name_error').hide()
  $('#email_error').hide()
  $('#comment_error').hide()
  var filled = "true"
  var name = $('#feedback-user-name').val()
  var email = $('#feedback-user-email').val()
  var content = $('#feedback-user-comment').val()
  if( name == "Name" ){
    filled = "false"
    $('#name_error').show()
  }
  if( email == "Email" ){
    filled = "false"
    filled = "false"
    $('#email_error').show()
  }
  if( content == "Comment" ){
    filled = "false"
    filled = "false"
    $('#comment_error').show()
  }

  if (filled == "true")
  {
    return true
  }
  else
  {
    e.preventDefault();
  }
})

function login_validation(e)
{
  var filled = 'true'
  $('#e_blank').hide()
  $('#p_blank').hide()
  $('#member_session_password').css('background-color','white')
  $('#member_session_email').css('background-color','white')
  var email = $('#member_session_email').val()
  var password = $('#member_session_password').val()
  if( email == "" ){
    filled = "false"
    $('#e_blank').show()
    $('#member_session_email').css('background-color','#FFF17F')
    $('#errorMsgA-threeLine').hide();
  }
    
  if( password == "" ){
    filled = "false"
    $('#p_blank').show()
    $('#member_session_password').css('background-color','#FFF17F')
    $('#errorMsgA-threeLine').hide();
  }
  if (filled == "true")
  {
    $('#member_session_password').css('background-color','white')
    $('#member_session_email').css('background-color','white')
    $('#new_member_session').submit();
  }
  else
  {
    e.preventDefault();
  }
}

$('#submitFormLogin').click(function(e){
  login_validation(e)
})

$("#member_session_email, #member_session_password").keyup(function(e) {
  if(e.keyCode == 13) {
    login_validation(e)
  }
})

$(".expertSummaryWideBadge").click(function(){
  window.location = $(this).data('url')
})

})

// $j = jQuery.noConflict();
// $j(window).resize(function() {
//  $j('.showClosePreview').offset({top: ($j(window).scrollTop()+104), left: ($j('#container-main').offset().left+970)});
// });

 /* Kaverisoft Additions End */

