﻿// notes -     Pagination.ascx + #viewMore has jS for the loading of other pages through the more button on line 19
// Also Thermometer.ascx has the height values calculated to animate the thermometer




$(document).ready(function () {

    // hide the images that'll get larger
    $('#video').hide();
    $('#photos').hide();

    FullTeamList = $('.box-team p span').text();
    TeamListCharNr = FullTeamList.length;

    if (TeamListCharNr > 260) {
        TruncatedTeamList = FullTeamList.substr(0, 250) + '... ';
        $('.box-team p span').text(TruncatedTeamList);
        $('.box-team p').append('<a href="#" class="lnk_view_full">view full list &gt;</a>');
        var status = true;
    };
    // shorten fundraiser msg 

    var heightFull = $('.frp-message-body').height();
    var heightCollpsd = "200px";
    var heightCollpsdInt = 200 + 70;
    var $msg = $('.frp-message-body');
    if (heightFull > heightCollpsdInt) {

        $msg.css("height", heightCollpsd).after('<span class="grdnt">&nbsp;</span>');
        $('.frp-message').after('<a class="lnk_readmore" href="#">Read more</a>');
        heightCollpsd = $msg.height();

        $('.box-msg a.lnk_readmore').click(function () {
            if ($msg.height() == heightCollpsd) {
                $msg.css({ height: 'auto' });
                $(this).text('Close');
                $('.frp-message .grdnt').toggle();

            }
            else {
                $msg.animate({ height: heightCollpsd }, "normal", function () { $('.frp-message .grdnt').toggle() });
                $(this).text('Read more');

            };
            return false;
        }
		 	);

    };

    // charity short msg
    $('.lnk_view_full').click(function () {
        if (status) {
            $('.box-team p span').html(FullTeamList + ' &nbsp; ');
            $(this).html('minimize &gt;');
            status = false;
        }
        else {
            $('.box-team p span').html(TruncatedTeamList);
            $(this).html('view full list &gt;');
            status = true;
        };
        return false;
    }
		 );
    var boxheightFull = $('.char-descr').height();
    var boxheightCollpsd = "70px";
    var boxheightCollpsdInt = 70 + 20;
    var $boxmsg = $('.char-descr');
    if (boxheightFull > boxheightCollpsdInt) {
        $boxmsg.css("height", boxheightCollpsd);
        $('.char-descr').append('<span class="grdnt">&nbsp;</span><a class="lnk_readmore_charity" href="#">Read more</a>');
        boxheightCollpsd = $boxmsg.height();
        $('a.lnk_readmore_charity').click(function () {
            if ($boxmsg.height() == boxheightCollpsd) {
                $boxmsg.css({ height: 'auto' });
                $(this).text('Close');
            }
            else {
                $boxmsg.animate({ height: boxheightCollpsd });
                $(this).text('Read more')
            };
            $(this).toggleClass('lnk_readless');
            $('.char-descr .grdnt').toggleClass('hidden');
            return false;
        }
		 	    );
    };

    // calender drop down
    var $block = $('#calendarOptions');
    $block.hide();
    $('#fundraisingInfo #reminder').click(function () {
        if ($block.css('display') == 'none') {
            $block.fadeIn('fast');
            $(this).text('Hide donate reminder');
        }
        else {
            $(this).text('Remind me to donate later');
            $block.fadeOut('fast');
        }
        return false;
    });

    // twitter + justgiving clientside url match - I promise to move this script into it's own jS file.  Dib dib.  - KCV        
    $(".tbl_donations tr:odd").addClass("odd");
    $('#donationHistory .by-time strong').each(function (element) {
        content = $(this).html();
        content = content.replace(/^@([a-z0-9\_\-]+)$/i, "<a href='http://www.twitter.com/$1'>@$1</a>");
        content = content.replace(/^(?:http:\/\/)??(?:www\.)??justgiving.com\/([a-z0-9\_\-\/]+)$/i, "<a href='http://www.justgiving.com/$1' title='Go to this person\'s fundraising page'>justgiving.com/$1</a>");
        $(this).html(content);
    });

    $('#firstImageLink').click(function () {
        $('#photoGallery a:first').trigger('click');
        return false;
    });
    // end jQ

    $('#imageMain').css('cursor', 'pointer').click(function () {
        $('#highslideGalleryFirstPic').trigger('click');
        return false;
    });

});