/* ------------------------------------------
ARTHRITIS RESEARCH UK
jQuery functions : source version
Author: Nicolas Gallagher
Updated: 2 November 2009
------------------------------------------ */

/* --------- GENERAL FUNCTIONS --------- */

// homepage essentials functionality
function essentials() {
	$(".essentials .section li")
	.css({cursor: "pointer"})
	.hover(function(){
		$(this).parent().children().removeClass('hover activity-donate-hover activity-event-hover activity-forum-hover');
		var elemClass = $(this).attr("class");
		if(elemClass != '') {
			var hoverElemClass = elemClass + '-hover';
		}
		else {
			var hoverElemClass = ''
		}
		$(this).addClass('hover '+hoverElemClass+'');
	})
	.click(function() {
		var url = $(this).find("a").attr("href");
		document.location.href = url;
	});
};

// conditions page
function conditionSections() {
    $('#condition-sections .section').hide();
    $('#condition-sections .intro').append('<p class="rightAlign"><a class="readMore" href="#non">Read more &raquo</a></p>');
    $('#condition-sections .intro a.readMore').click(
	    function() {
	        if ($(this).parent().parent().next('.section').css("display") == "none") {
	            $(this).parent().parent().next('.section').slideDown();
	            $(this).html('Read less &raquo');
	        }
	        else {
	            $(this).parent().parent().next('.section').slideUp();
	            $(this).html('Read more &raquo');
	        }
	    }
	);

	$('#content a.readAll').toggle(
	    function() {
	        $('#condition-sections .section').slideDown();
	        $(this).html('Hide article &raquo');
	        $('#condition-sections .intro a.readMore').html('Read less &raquo');
	    },
	    function() {
	        $('#condition-sections .section').slideUp();
	        $(this).html('Read entire article &raquo');
	        $('#condition-sections .intro a.readMore').html('Read more &raquo');
	    }
	);
	};

	function bindEvents() {
	
	    // Bind the donation submit event on to the buttons
	    $('.donation-submit').click(function() {
            try {
                var pageTracker = _gat._getTracker("UA-8580322-2");
                pageTracker._initData()
	            pageTracker._trackEvent('Donate', 'click', 'Page', window.location);
	        }
	        catch (err) { }
	    });
	}



/* ------------------------------------------------------------------------------------
--  DOM READY
------------------------------------------------------------------------------------ */

	jQuery(document).ready(function() {
	    essentials();

	    switch (document.body.id) {
	        case "conditions":
	            conditionSections();
	            break;
	        default:
	            break;
	    }
	    bindEvents();
	    $(".videos li a").prettyPhoto({ hideflash: true });
	});
