// plugins
jQuery.fn.extend({  scrollTo : function(speed, adjust, easing) {    return this.each(function() {      var targetOffset = $(this).offset().top;      $('html,body').animate({scrollTop: targetOffset - adjust}, speed, easing);    });  },  highlight : function(data, color, color2, speed, easing) {    return this.each(function() {
			color='#f7931d';
			speed=500;
			color2='#fdffcc';	      	$(this).html(data).css('background-color', color ).animate({backgroundColor: color2 }, speed, easing);    });  },

  roundCorners : function(data) {    return this.each(function() {
	      $(this).css('position','relative').prepend('<div class="ed-rounded-tl"></div><div class="ed-rounded-tr"></div><div class="ed-rounded-bl"></div><div class="ed-rounded-br"></div>');    });  },

  inputEdit : function(type) {
	return this.each(function(){
			var data = $(this).html();
			var w = $(this).width();
			w = w+45;
			if(w>650){w=650;};
			if(type!='textarea'){
			$(this).html('<input type="text" value="'+data+'" style="padding:2px;width:'+w+'px">');
			$(this).attr('onClick','').find('input').focus().attr('onBlur','$(this).inputEditReturn()');
			} else {
			$(this).html('<textarea style="padding:2px;width:100%">'+data+'</textarea>');
			$(this).attr('onClick','').find('textarea').focus().attr('onBlur','$(this).inputEditReturn(\''+type+'\')');					}
	});
  },
  inputEditReturn : function(type) {
	return this.each(function(){
			var data = $(this).val();
			if(type!='textarea'){
			$(this).parent().html(data).attr('onClick','$(this).inputEdit()');
			} else {
			$(this).parent().html(data).attr('onClick','$(this).inputEdit(\''+type+'\')');
			}
	});
  }



});
//end plugins


//my code begins...

$(document).ready(function(){


  	$(".leftmenu").hover(      function () {        $( this ).addClass('leftmenuhover');
      },       function () {
        $( this ).removeClass('leftmenuhover');
       });


	$(".slide").each(function (i) {
        var w = $(this).find(".text").outerWidth();
        var h = $(this).find(".text").outerHeight();
		$(this).find(".box").css({'height': h+'px','width':w+'px'});
      });

  	$("#donatelink").hover(      function () { $(this).css('background-position','bottom left'); },       function () { $(this).css('background-position','top left'); });

});


function listmenu(t) {
	q = $(t).val();
	$.get('http://www.educateforlife.org.uk/admin/listmenu.php',{q:q},function(data) {$(t).next().html(data); });
}
function addtoMenu(t) {
	par = $('#pageid').html();
	ht = $(t).html();
	id = $(t).attr('id');
	link = $(t).attr('title');
	$.get('http://www.educateforlife.org.uk/admin/set-menu-link.php',{par:par,chi:id},function(data) {
		li = $('<li></li>').html('<a href="http://www.educateforlife.org.uk/'+link+'">'+ht+'</a>').addClass('leftmenu').appendTo('#leftmenu');
	});

}

function sharepage() {
	var e = $('#shareemail').val();
	var f = $('#sharername').val();
	var n = $('#note').val();
	var a = $('#address').html();
	$.get('http://www.educateforlife.org.uk/src/sharepage.php', {a:a,e:e,f:f,n:n}, function(data) {$('#shared').html(data); });
}

function sendMessage(ta) {
	$(ta).val('sending message...').css('color','#666666').attr('onclick','').next().html('<img src="http://www.educateforlife.org.uk/admin/loading1.gif">');
	var n = $('#fromname').val();
	var e = $('#fromemail').val();
	var s = $('#fromsubject').val();
	var m = $('#message').val();
	$.get('http://www.educateforlife.org.uk/_pages/mailtous.php', {n:n,e:e,s:s,m:m}, function(data) {$('#sent').html(data); });
}

function addComment(page,thi) {
	if($(thi).val() != 'Adding...'){

		$(thi).val('Adding...').css('color','#999999'); 
		var p = page;
		var e = $('#commentemail').val();
		var n = $('#commentname').val();
		var c = $('#comment').val();

		if(e!=''&&n!=''&&c!=''){
		$.get('../add-comment.php',{c:c,e:e,n:n,p:p},function(data) {
				$('#commentdata').html(data);
				$('#commentemail').val('');
				$('#commentname').val('');
				$('#comment').val('');
				$(thi).val('Add another comment').css('color','#000000'); 
		});
		} else {
				$('#commentdata').html('Please fill in all fields');
				$(thi).val('Add comment').css('color','#000000'); 
		}

	}
}

