var myAjax ;
function moins(post_number) {
    var number = post_number;
    var url = './moins.php';
    myAjax = new Ajax.Request(
       url, 
       {
	method: 'get',
	  parameters: "post="+post_number,
	  'onLoading': loading(post_number),
	  'onComplete': function (transport){
	    $("moins_"+number).appear({ duration: 3.0  , from: 0, to: 1 });
	    $("moins_"+number).innerHTML = transport.responseText;
	   },
	  'onFailure': function(post_number){
	   
	  },
	})
}
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}
function plus(post_number) {
    var number = post_number;
    var url = './plus.php';
    myAjax = new Ajax.Request(
       url, 
       {
	method: 'get',
	  parameters: "post="+post_number,
	  'onLoading': loading(post_number),
	  'onComplete': function (transport){
	    $("plus_"+number).appear({ duration: 3.0  , from: 0, to: 1 });
	    $("plus_"+number).innerHTML = transport.responseText;
	   },
	  'onFailure': function(post_number){
	   
	  },
	})
}
function abus(post_id,comment_id){
  var url = './abus.php';
  myAjax = new Ajax.Request(
    url, 
      {
	method: 'get',
	parameters: "post="+post_id+"&comment="+comment_id,
	'onLoading': loading(post_id),
	'onComplete': function (transport){
	//   $("plus_"+number).hide();
	    $("abus_"+comment_id).appear({ duration: 3.0  , from: 0, to: 1 });
	    $("abus_"+comment_id).innerHTML = transport.responseText;
	   },
	  'onFailure': function(post_number){
	  },
	})
}
function loading(id_post){
}
function res(id_post){
}
function showDeny(id_post){
}
var resizeDelay = 10;
var resizeIncrement = 5;
var imgCache = new Object();
function getCacheTag (imgElement) {
	return imgElement.src + "~" + imgElement.offsetLeft + "~" + imgElement.offsetTop;
}
function cachedImg (imgElement, increment) {
	this.img = imgElement;
	this.cacheTag = getCacheTag(imgElement);
	this.originalSrc = imgElement.src;
	
	var h = imgElement.height;
	var w = imgElement.width;
	this.originalHeight = h;
	this.originalWidth = w;
	
	increment = (!increment) ? resizeIncrement : increment;
	this.heightIncrement = Math.ceil(Math.min(1, (h / w)) * increment);
	this.widthIncrement = Math.ceil(Math.min(1, (w / h)) * increment);
}
function resizeImg (imgElement, percentChange, newImageURL) {
	var pct = (percentChange) ? percentChange / 100 : 1;
	var cacheTag = imgElement.getAttribute("cacheTag");
	if (!cacheTag) {
		cacheTag = getCacheTag(imgElement);
		imgElement.setAttribute("cacheTag", cacheTag);
	}
	var cacheVal = imgCache[cacheTag];
	if (!cacheVal) {
		imgCache[cacheTag] = new Array(new cachedImg(imgElement), pct);
	} else {
		cacheVal[1] = pct;
	}
		if (newImageURL)
		imgElement.src = newImageURL;
	resizeImgLoop(cacheTag);
	return true;
}
function resizeImgLoop (cacheTag) {
	var cacheVal = imgCache[cacheTag];
	if (!cacheVal)
		return false;
	var cachedImageObj = cacheVal[0];
	var imgElement = cachedImageObj.img;
	var pct = cacheVal[1];
	var plusMinus = (pct > 1) ? 1 : -1;
	var hinc = plusMinus * cachedImageObj.heightIncrement;
	var vinc = plusMinus * cachedImageObj.widthIncrement;
	var startHeight = cachedImageObj.originalHeight;
	var startWidth = cachedImageObj.originalWidth;
	var currentHeight = imgElement.height;
	var currentWidth = imgElement.width;
	var endHeight = Math.round(startHeight * pct);
	var endWidth = Math.round(startWidth * pct);
	if ( (currentHeight == endHeight) || (currentWidth == endWidth) )
		return true;
	var newHeight = currentHeight + hinc;
	var newWidth = currentWidth + vinc;
	if (pct > 1) {
		if ((newHeight >= endHeight) || (newWidth >= endWidth)) {
			newHeight = endHeight;
			newWidth = endWidth;
		}
	} else {
		if ((newHeight <= endHeight) || (newWidth <= endWidth)) {
			newHeight = endHeight;
			newWidth = endWidth;
		}
	}
	imgElement.height = newHeight;
	imgElement.width = newWidth;
	if ((newHeight == cachedImageObj.originalHeight) || (newWidth == cachedImageObj.originalwidth)) {
		imgElement.src = cachedImageObj.originalSrc;
	}
	setTimeout("resizeImgLoop('" + cacheTag + "')", resizeDelay);
}

