﻿$.fn.orphans = function() {
    var ret = [];
    this.each(function() {
        $.each(this.childNodes, function() {
            if (this.nodeType == 3 && $.trim(this.nodeValue)) ret.push(this)
        })
    });
    return $(ret);
}
jQuery.fn.blindToggle = function(speed, easing, callback) {
    var h = this.height() + parseInt(this.css('paddingTop')) + parseInt(this.css('paddingBottom'));
    return this.animate({ marginTop: parseInt(this.css('marginTop')) < 0 ? 0 : -h }, speed, easing, callback);
};
jQuery.fn.fadeToggle = function(speed, easing, callback) {
    return this.animate({ opacity: 'toggle', height: 'toggle' }, speed, easing, callback);
};
$(document).ready(function() {
    //s/jq/a
    $('.expand').css('cursor', 'pointer').orphans().wrap('<a href="#expand/collapse" title="expand/collapse"></a>');
    $('.showAll').css('cursor', 'pointer').orphans().wrap('<a href="#expand/collapse" title="expand/collapse"></a>');
    $('.collapse').hide();
    
    //drop content
    $('.expand').click(function() {
        $(this).toggleClass("arrow-up");
        $(this).next('.normal').fadeToggle();
        $(this).next('.slow').fadeToggle('slow');
    });
    //change text of anchor
    $('.expand a').click(function() {
        var tempString = $(this).text();
        if(tempString=="Show Me")
        {
            $(this).attr('innerHTML','Close Me')
        }
        if(tempString=="Close Me")
        {
            $(this ).attr('innerHTML','Show Me')
        }
    });
    
    $('.showAll').click(function() {
        
        //set clases so arrows opened
        $(this).toggleClass("arrow-up");
        $('#business').toggleClass("arrow-up");
        $('#further').toggleClass("arrow-up");
        // show the divs
        $('#generators').fadeToggle();
        $('#furtherSteps').fadeToggle();
        //check text
        var tempString = $(this).text();
        if(tempString=="Show All")
        {
            $('.showAll a').attr('innerHTML','Close All')
        }
        if(tempString=="Close All")
        {
            $('.showAll a').attr('innerHTML','Show All')
        }
    });
    
});
