// Ce script permet de mettre les bords qu'on désire au coins d'un bloc
// pour cela, il faut créer l'image désirée sous la forme d'un bloc avec les bords désirés
// si il y a une bordure sur le reste de l'élément, il faut le détérminer avec borderWidth

function Corners_Manager(cssSelector, widthImage, heightImage, urlImage, borderWidth) {
	this.widthImage = widthImage;
	this.heightImage = heightImage;
	this.urlImage = urlImage;
	this.element = $(cssSelector);
	this.borderWidth = borderWidth;
}

Corners_Manager.prototype = {
	
	topLeft: function () {
		var size = this.element.length;
		for(i=0;i<size;i++) {
			var div = this.getTopLeft();
			$(this.element[i]).append($(div));
		}	
	},
	
	topRight: function () {
		var size = this.element.length;
		for(i=0;i<size;i++) {
			var div = this.getTopRight();
			$(this.element[i]).append($(div));
		}	
	},
	
	bottomRight: function () {
		var size = this.element.length;
		for(i=0;i<size;i++) {
			var div = this.getBottomRight();
			$(this.element[i]).append($(div));
		}	
	},
	
	bottomLeft: function () {
		var size = this.element.length;
		for(i=0;i<size;i++) {
			var div = this.getBottomLeft();
			$(this.element[i]).append($(div));
		}	
	},
	
	
	
	
	getTopLeft: function () {
		var div = this.getDiv();
		$(div).css('background-position', this.getZero() + 'px ' + this.getZero() + 'px');
		
		$(div).css('top', this.getDecal() + 'px');
		$(div).css('left', this.getDecal() + 'px');
		return $(div);
		
	},
	getTopRight: function () {
		var div = this.getDiv();
		$(div).css('background-position', this.getHalfWidth() + 'px ' + this.getZero() + 'px');
		
		$(div).css('top', this.getDecal() + 'px');
		$(div).css('right', this.getDecal() + 'px');
		return $(div);
		
	},
	getBottomRight: function () {
		var div = this.getDiv();
		$(div).css('background-position', this.getHalfWidth() + 'px ' + this.getHalfHeight() + 'px');
		
		$(div).css('bottom', this.getDecal() + 'px');
		$(div).css('right', this.getDecal() + 'px');
		return $(div);
		
	},
	getBottomLeft: function () {
		var div = this.getDiv();
		$(div).css('background-position', this.getZero() + 'px ' + this.getHalfHeight() + 'px');
		
		$(div).css('bottom', this.getDecal() + 'px');
		$(div).css('left', this.getDecal() + 'px');	
		return $(div);
		
	},
	
	getDiv: function () {
		var div = $('<div></div>');
		$(div).css('width', this.widthImage/2);
		$(div).css('font-size', '0px');
		$(div).css('line-height', '0px');
		$(div).css('height', this.heightImage/2);
		$(div).css('background-image', 'url(' + this.urlImage + ')');
		$(div).css('position', 'absolute');
		$(div).css('z-index', '100');	
		return $(div);
	},
	
	// correspond au décalage dû au borderWidth
	getDecal: function () {
		var decal = -this.borderWidth;
		return String(decal);
	},
	
	getZero: function () {
		var zero = 0;
		return String(zero);
	},
	
	getWidth: function () {
		var width = -this.widthImage;
		return String(width); 
	},
	
	getHeight: function () {
		var height = -this.heightImage;
		return String(height); 
	},
	
	// decal permet de prendre en compte un décalage dû au borderWidth
	getHalfWidth: function () {
		var halfWidth = -this.widthImage/2;
		return String(halfWidth); 
	},
	// decal permet de prendre en compte un décalage dû au borderWidth
	getHalfHeight: function () {
		var halfHeight = -this.heightImage/2;
		return String(halfHeight); 
	}	
}
