/* Author: Tim Brook
*/

$(document).ready(function() {


    //=== Form Rollouts
    $('.rollout').slideUp('slow');

    $('.widget-form .expand').click(function() {
        var showID = $(this).attr('href');
        $('#' + showID).slideDown('slow');
        return false;
    });

    $('.widget-form .close').click(function() {
        var showID = $(this).attr('href');
        $('#' + showID).slideUp('slow');
        return false;
    });
    //==== End Form Rollouts

    if (!Modernizr.input.placeholder) {
        $("input").each(function() {
            if ($(this).val() == "" && $(this).attr("placeholder") != "") {
                $(this).val($(this).attr("placeholder"));
                $(this).focus(function() {
                    if ($(this).val() == $(this).attr("placeholder")) $(this).val("");
                });
                $(this).blur(function() {
                    if ($(this).val() == "") $(this).val($(this).attr("placeholder"));
                });
            }
        });
    }

  

  
  $('.expanding-div').hide();
  $('.expand-content').toggle(
    function(){
      $('.expanding-div').slideDown();
      $(this).html('Hide video transcript');
      return false;
    },
    function(){
      $('.expanding-div').slideUp();
      $(this).html('Show video transcript');
      return false;
    }
  );

    // THIS IS THE DIRTY HACKY CODE THAT YOU MIGHT WANT TO CHANGE TOM

    var paraHeight = new Array();
    for (i = 1; i <= $(".column-wrap div div").length; i++) {
        paraHeight[i] = $(".column-wrap div div#expandingdiv-" + i).innerHeight();
    }
    $('.column-wrap div div').each(function() {
        var strlen = $(this).text().length;
        if (strlen > 80) {
            $(this).css({ 'height': '55px', 'overflow': 'hidden' });
        } else {
            $(this).siblings('.expand').css({ 'display': 'none' });
        }
    });
    $('.expand').toggle(function() {
        var theSiblingID = $(this).siblings('div').attr('id').split('-');
        $(this).siblings('div#expandingdiv-' + theSiblingID[1]).animate({ height: paraHeight[theSiblingID[1]] + "px" });
        $(this).html('Show Less');
        return false
    }, function() {
        var theSiblingID = $(this).siblings('div').attr('id').split('-');
        $(this).siblings('div#expandingdiv-' + theSiblingID[1]).animate({ 'height': '55px' });
        $(this).html('Show More');
        return false
    });

    // END OF DIRTY HACKY CODE


    var cur = 1;
    $('.widget-faq-list div section li a').each(function() {
        $(this).attr({ 'href': '#faq' + cur });
        cur++;
    });

    var cur = 1;
    $('.widget-faq-list article').each(function() {
        $(this).attr({ 'id': 'faq' + cur });
        cur++;
    });

    $('a[href*=#]').click(function() {
        if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
        && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({ scrollTop: targetOffset }, 700);
                return false;
            }
        }
    });
});






















