jQuery.fn.extend({ scramble :  function() { 
    var i = this.size(); 
    if (!i) return this; 
    while (--i) { 
        var j = Math.floor(Math.random() * (i+1)); 
        var tmp1 = this.slice(i, i+1); 
        this.slice(j, j+1).after(tmp1).insertAfter(tmp1); 
    } 
    return this; 
}}); 

$(document).ready(function(){

	// Join Us Panel //
	
	




	// charitypicker -------------------
	
	
	//scramble (randomise)
	$('#mycarousel li').scramble();

	// tips
	$("#charityinfo").fadeTo("fast", 0.1);

	$(".arrow a img").mouseover(function(){
		$("#charityinfo").fadeTo("fast", 0.66);
		var charityinfo = $(this).attr("alt");
		$("#charityinfo").text("Click to "+charityinfo);
	});
	$(".arrow a img").mouseout(function(){
		$("#charityinfo").fadeTo(0.1, 0.1);
		$("#charityinfo").html("&nbsp;");
	});
	$(".charitylogo a img").mouseover(function(){
		$("#charityinfo").fadeTo("fast", 0.66);
		var charityinfo = $(this).attr("alt");
		$("#charityinfo").html("Click to find out more about <strong>"+charityinfo+"</strong>");
	});
	$(".charitylogo a img").mouseout(function(){
		$("#charityinfo").fadeTo(0.1, 0.1);
		$("#charityinfo").html("&nbsp;");
	});
	
	// carousel	
	$('#mycarousel').jcarousel();
	
	
	// add wrapper around blockquotes
	// this makes it possible to have the speech bubble triangle thing
	
	$("#bodytext blockquote").wrap("<div class=\"blockquotewrap\"></div>");
	
	// add quotes on the charitiespage to blockquote
	$(".charitiespage blockquote p").prepend("&ldquo;");
	$(".charitiespage blockquote p").append("&rdquo;");
	
	// adds external links icons and makes them open new windows
	
	$("#main a[href^='http://']").not("a[href^='http://princescharities.org']").not("a[href^='http://www.princescharities.org']").not("a[href^='http://maps.google.co.uk']").append("&nbsp;<img src=\"http://princescharities.org/assets/externallink.gif\" alt=\"external link\" class=\"externallinkicon\" />");
	
	$("#main a[href^='http://']").not("a[href^='http://princescharities.org']").not("a[href^='http://www.princescharities.org']").click(function(){
		window.open(this.href,'external');
		return false;
	});
	
	
	
	// user profile editing page rearrange ----------

	$('label#edit-picture-uploadas').parent().addClass('edit-profile-picture');

	// move the fiedlset holding the region/nation dropdown to the bottom
	//$('#edit-taxonomy-2').parent().clone().appendTo('div.standard');
	//$('#edit-taxonomy-2').parent().remove();
	
	// hide log messages stuff
	//$('#edit-log').prev('label').remove();
	//$('#edit-log').next('div.description').remove();
	//$('#edit-log').remove();
	
	// hide preview changes
	//$('#edit-preview-changes').remove();
	
	// move messages div to where i want it to be
	// $('div.messages').clone().insertBefore('#navigation3');
	// $('div.messages').remove();
	
	/* fix ie6 and IE7 bug when you do things with jQuery and it makes pos: relative items 'stay' in the same place - so we switch it on and off again */
	if (jQuery.browser.msie) {
		/* alert(parseInt(jQuery.browser.version)); */
		// $("#footer").append("THIS IS IE"+jQuery.browser.version);
		$("#contentfeed").hide(1, function () {
			$("#contentfeed").show(0);
		});
	}
	
	
	//$("#edit-field-position-0-value").remove();
	//$("#edit-field-position-0-valueas").remove();
	//$("#edit-bodyas").remove();
	
		

	
});