/**
 * jQuery librairies generales
 * @name jquery.sliderColor.js
 * @author Corentin CROUVISIER
 * @version 0.1
 * @date 22/10/2009
 * @category jQuery plugin
 * @require librairies/LibGen.js
 */
(function($) {
	$.fn.roundedCorner = function(){
		this.each(function(){
			var options = {
				topleft:1,
				topcenter:1,
				topright:1,
				middleleft:1,
				middleright:1,
				bottomleft:1,
				bottomcenter:1,
				bottomright:1,
				top:1,
				left:1,
				right:1,
				bottom:1
			};
			var options_spe = 0;
			var regEx=new RegExp("(corner\-)","g");
			var sg = $(this).attr("class");
			if(sg.match(regEx)){
				options_spe = 1;
			}
			if(options_spe == 1){
				$.each(options,function(k,v){
					options[k] = 0;
				});
				var tab_options = sg.split(" ");
				$.each(tab_options,function(k,v){
					if(v.match(regEx)){
						var elt = v.split("corner-");
						options[elt[1]] = 1;
					}
				});
				if(options.top==1){options.topcenter=1;}
				if(options.left==1){options.middleleft=1;}
				if(options.top==1 && options.left==1){options.topleft=1;}
				if(options.right==1){options.middleright=1;}
				if(options.top==1 && options.right==1){options.topright=1;}
				if(options.bottom==1){options.bottomcenter=1;}
				if(options.bottom==1 && options.left==1){options.bottomleft=1;}
				if(options.bottom==1 && options.right==1){options.bottomright=1;}
			}
			var content = $(this).html();
			var id = $(this).attr('id');
			var tabClass = $(this).attr('class');
			$(this).replaceWith(
			'<div id="'+id+'" class="'+tabClass+'">\
				'+(
				(options.topleft>0 || options.topcenter>0 || options.topright>0)?
				'<div class="top">\
					'+((options.topleft>0)?'<div class="top-left"></div>':'')+'\
					'+((options.topcenter>0)?'<div class="top-center"></div>':'')+'\
					'+((options.topright>0)?'<div class="top-right"></div>':'')+'\
				</div>':'' 
				)+'\
				<div class="center">\
					'+((options.middleleft>0)?'<div class="center-left"></div>':'')+'\
					<div class="center-center">\
						<div class="rounded-div-content clearfix">\
							'+content+'\
						</div>\
					</div>\
					'+((options.middleright>0)?'<div class="center-right"></div>':'')+'\
				</div>\
				'+(
				(options.bottomleft>0 || options.bottomcenter>0 || options.bottomright>0)?
				'<div class="bottom">\
					'+((options.bottomleft>0)?'<div class="bottom-left"></div>':'')+'\
					'+((options.bottomcenter>0)?'<div class="bottom-center"></div>':'')+'\
					'+((options.bottomright>0)?'<div class="bottom-right"></div>':'')+'\
				</div>':'' 
				)+'\
			</div>'
			);
		});
	};
})(jQuery);
