jQuery.noConflict();
jQuery(document).ready(function() {
	jQuery('.banner-image').wrap("<li></li>");
	jQuery('#top').append("<div class=\"shadow\"></div>");
	jQuery("#page table tr:nth-child(even)").addClass('even');
	jQuery("a.read-more-inline").wrapInner('<span></span>');
	jQuery("p.action-button a").wrapInner('<span></span>');
	// jQuery("#page a[href^='http://kb.rspca.org.au]'").addClass('knowledgebase');
	jQuery("#page a[href^=mailto]").addClass('email');
	jQuery("#page p:has(img)").addClass('imagepara');
	jQuery('.banners ul').innerfade({
		animationtype: 'fade',
		speed: 'slow',
		timeout: 5000,
		containerheight: '220px' 
	});
	jQuery("img.alignleft").each(function(){
/* 		var imgTitle = jQuery(this).attr("alt"); */
		var imgTitle = jQuery(this).attr("title");
		var imgLongDesc = jQuery(this).attr("longdesc");
		jQuery(this).wrap("<div class=\"image-wrapper\"></div>");
		jQuery(this).after("<span class=\"image-description\"></span>");
		jQuery("span.image-description").html("<a href=\"" + imgLongDesc + "\">" + imgTitle + "</a>");
	});
	
	jQuery('.slider li:gt(0)').hide();
	setInterval(function(){
		jQuery('.slider li:first-child').fadeOut(1000).next('li').fadeIn(1000).end().appendTo('.slider');
	}, 6000);
	jQuery('#donation_container').before('<ul id="donation_menu"><li class="active"><span id="creditcard">Credit Card</span></li><li><span id="directdebit">Direct Debit</span></li><li><span id="bpay">BPay</span></li><li><span id="cheque">Cheque</span></li><li><span id="phone">Phone</span></li></ul>');
    jQuery('.donation_container:not(#creditcard_container)').addClass('tabbed');
    jQuery('#donation-methods').scrollTop(0);
	jQuery("#donation_menu li").click( function(){
		var donation_type = jQuery("span", this).attr("id");
		
		// Change tab classes
		jQuery("#donation_menu .active").removeClass("active");
		jQuery(this).addClass("active");
		
		// Change container calsses
		jQuery("#donation_container .donation_container").hide();
		jQuery("#" + donation_type + "_container").fadeIn(300);
		
	});
	jQuery('[name="behalf-of"]').each(function () {
		jQuery(this).change(function () {
			if (jQuery(this).attr('id') == 'dbehalfof') {
				jQuery('#behalfof').val(jQuery(this).val());
			} else if (jQuery(this).attr('id') == 'behalfof') {
				jQuery('#dbehalfof').val(jQuery(this).val());
			}
			if (jQuery(this).val() == 'individual') {
				jQuery('.donator-details [id*="name"]').parent('li').show();
				jQuery('.donator-details [id*="organisation"]').parent().hide();
			} else if (jQuery(this).val() == 'organisation') {
				jQuery('.donator-details [id*="name"]').parent('li').hide();
				jQuery('.donator-details [id*="organisation"]').parent().show();						
			}
		});
	});
    if(jQuery('[name="behalf-of"]').val() == 'individual') {
        jQuery('.donator-details [id*="name"]').parent('li').show();
	    jQuery('.donator-details [id*="organisation"]').parent().hide();
    } else if (jQuery('[name="behalf-of"]').val() == 'organisation') {
        jQuery('.donator-details [id*="name"]').parent('li').hide();
		jQuery('.donator-details [id*="organisation"]').parent().show();
    } else {
        jQuery('.donator-details [id*="organisation"]').parent().hide();
    }
    jQuery('#damount').click(function () {
        jQuery('#dother-sum').click();
    });
    jQuery('#amount').click(function () {
        jQuery('#other-sum').click();
    });
    
    jQuery('#donation_comments').keyup(function () {
        if (jQuery(this).val().length >= 256) {
            jQuery(this).parent().find('.counter').html('limit is 255 characters, please shorten your message');
        } else {
            jQuery(this).parent().find('.counter').html((255 - jQuery(this).val().length));
        }
    });
});	
