/************************************************************************************************************<br>
<br>
	@fileoverview
	Rounded corners class<br>
	(C) www.dhtmlgoodies.com, September 2006<br>
	<br>
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	<br>
	<br>
	Terms of use:<br>
	Look at the terms of use at http://www.dhtmlgoodies.com/index.html?page=termsOfUse<br>
	<br>
	Thank you!<br>
	<br>
	www.dhtmlgoodies.com<br>
	Alf Magne Kalleland<br>
<br>
************************************************************************************************************/

// {{{ Constructor
function DHTMLgoodies_roundedCorners()
{
	
}

// }}}
DHTMLgoodies_roundedCorners.prototype = {

	// {{{ addTarget()
    /**
     *
	 *
     *  Add rounded corners to an element
     *
     *	@param String divId = Id of element on page. Example "leftColumn" for &lt;div id="leftColumn">
     *	@param Int cornerSize = Size of rounded corners in pixels., example 10
     *  @param String color = Background color of element, example #FFF or #AABBCC
     *  @param Int padding = Padding of content - This will be added as left and right padding(not top and bottom)
     *  @param String heightOfContent = Optional argument. You can specify a fixed height of your content. example "15" which means pixels, or "50%". 
     *  @param String whichCorners = Optional argument. Commaseparated list of corners, example "top_left,top_right,bottom_left"
     * 
     * @public
     */		
	addTarget : function(divId,cornerSize,color,padding,heightOfContent,whichCorners)
	{
		var cornerArray = new Array();
		if(!whichCorners || whichCorners=='all'){
			cornerArray['top_left'] = true;
			cornerArray['top_right'] = true;
			cornerArray['bottom_left'] = true;
			cornerArray['bottom_right'] = true;
		}else{
			cornerArray = whichCorners.split(/,/gi);
			for(var prop in cornerArray)cornerArray[cornerArray[prop]] = true;
		}
			
		
		var obj = document.getElementById(divId);
		obj.style.backgroundColor=null;
		obj.style.backgroundColor='transparent';
		var content = obj.innerHTML;
		obj.innerHTML = '';
		
		var contentDiv = document.createElement('DIV');
		
		// Adding top corner div.
		
		if(cornerArray['top_left'] || cornerArray['top_right']){
			var topBar_container = document.createElement('DIV');
			topBar_container.style.height = cornerSize + 'px';
			topBar_container.style.overflow = 'hidden';	
	
			obj.appendChild(topBar_container);		
	
			for(no=1;no<=cornerSize;no++){
				var el = document.createElement('DIV');
				el.style.overflow='hidden';
				el.style.height = '1px';			
				if(cornerArray['top_left'])el.style.marginLeft = (cornerSize - (this.getY((cornerSize - no),cornerSize))) + 'px';				
				if(cornerArray['top_right'])el.style.marginRight = (cornerSize - (this.getY((cornerSize - no),cornerSize))) + 'px';				
				el.style.backgroundColor=color;			
				topBar_container.appendChild(el);
			}

		}
		// Add content
		var contentDiv = document.createElement('DIV');
		contentDiv.className = obj.className;
		contentDiv.style.border='1px solid ' + color;
		contentDiv.innerHTML = content;
		contentDiv.style.backgroundColor=color;
		contentDiv.style.paddingLeft = padding + 'px';
		contentDiv.style.paddingRight = padding + 'px';

		if(!heightOfContent)heightOfContent = '';
		heightOfContent = heightOfContent + '';
		if(heightOfContent.length>0 && heightOfContent.indexOf('%')==-1)heightOfContent = heightOfContent + 'px';
		if(heightOfContent.length>0)contentDiv.style.height = heightOfContent;
		
		obj.appendChild(contentDiv);

		if(cornerArray['bottom_left'] || cornerArray['bottom_right']){
			// Add bottom cornered div
			var bottomBar_container = document.createElement('DIV');
			bottomBar_container.style.height = cornerSize + 'px';
			bottomBar_container.style.overflow = 'hidden';	
	
			obj.appendChild(bottomBar_container);		
	
			for(no=cornerSize;no>1;no--){
				var el = document.createElement('DIV');
				el.style.overflow='hidden';
				el.style.height = '1px';			
				if(cornerArray['bottom_left'])el.style.marginLeft = (cornerSize - (this.getY((cornerSize - no),cornerSize))) + 'px';				
				if(cornerArray['bottom_right'])el.style.marginRight = (cornerSize - (this.getY((cornerSize - no),cornerSize))) + 'px';				
				el.style.backgroundColor=color;			
				bottomBar_container.appendChild(el);
			}	
		}	
		return;	
	}		
	// }}}
	,		
	// {{{ getY()
    /**
     *
	 *
     *  Add rounded corners to an element
     *
     *	@param Int x = x Coordinate
     *	@param Int maxX = Size of rounded corners
	 *
     * 
     * @private
     */		
	getY : function(x,maxX){
		// y = sqrt(100 - x^2)			
		return Math.round(Math.sqrt((maxX*maxX) - (x*x)));
		
	}
	
	
}				
