﻿// 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

function newDesignAlert() {

    var $triLeft = $('<div id="tri-left"></div>');
    var $triRight = $('<div id="tri-right"></div>');

    $triLeft.appendTo('#nda-header')
    $triRight.appendTo('#nda-header')
    var $ndaContent = $('#new-design-alert #nda-content')
    $ndaContent.hide();
    var $toggleLink = $('#nda-header a.toggle-new-design');
    $toggleLink.bind('click',
        function () {
            $ndaContent.slideToggle();
            $(this).hide();
            $('<a class="close" href="#">Close X</a>')
            .css({
                'font-size': '1.2em',
                'font-weight': 'bold',
                'position': 'absolute',
                'right': '5px',
                'top': '7px'
            })
            .appendTo('#nda-header');
            return false;
        }
        );

    $('a.close').live('click',
        function () {
            $ndaContent.slideToggle();
            $(this).remove();
            $toggleLink.show();
            return false;
        });
}


$(document).ready(function () {

    newDesignAlert();

    // 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;
    });

    var projectBox = $("body").justModal();
    $("#projectDetailOpen").click(function () {
        projectBox.showWithElement($("#projectContent"));
    });





    // ----- start Text giving donation hover effect
    if ($('.text-giving-charge').length > 0) {
        $('.text-giving-charge div').each(function () {
            var height = '-' + $(this).height() / 2;
            $(this).css({ 'position': 'absolute', 'top': parseInt(height) });
        });

        $('.text-giving-charge span a').hover(function () {
            $(this).parent().next().delay(200).fadeIn();
        }, function () {
            $(this).parent().next().stop(true, true).fadeOut();
        });
    }
    // ----- end Text giving donation hover effect

    JustGiving.Analytics.SocialTracking.ExtendSettings({ target: 'fundraising_page' });

    $('#prompt-upgrade-to-atlas').show();

    //var model = 
});
