
// Start Rounded Corner //
function custom_make_corners(className){
	var $i;	
	var $elements;
	if( className === undefined ){
		$elements=find_class(document.body,"custom_rounded");
	}
	else{
		$elements=find_class(document.body,className);
	}
	if(!(navigator.appName=="Microsoft Internet Explorer" && navigator.appVersion.indexOf("5.5")>-1))
		for($i = 0; $i <Number($elements.length) ; ++$i){
			custom_rounded_corners($elements[$i]);
		}
}

function custom_rounded_corners($element)
	{
	//$rc_left=true, $rc_right=true, 
	var $rc_radius=7, $rc_top=true, $rc_bottom=true, $rc_self_color, $rc_parent_color, $rc_antialiased,$rc_antialiased_cf=0.33,$rc_compact,$rc_auto_margin,$rc_method="margin",$rc_border,$border_color;
	var	$property,$container,$el_container,$el_inner,$j,$i,$ang,$ang_last,$bw,$width,ee,$err_alert;
	var $classes=$element.className.split(" ");
	var $rc_top_left=true, $rc_top_right=true,$rc_bottom_left=true,$rc_bottom_right=true;
	var $rc_float_right=false;
	
	$rc_self_color=get_current_style($element,"background-color","(transparent)|(rgba)");
	$rc_parent_color=get_current_style($element.parentNode,"background-color","(transparent)|(rgba)");
	$border_color=get_current_style($element,"border-top-color");	
	
	if( navigator.appName=="Microsoft Internet Explorer" ) {
		$rc_float_right = get_current_style($element.parentNode,"styleFloat");
	}else{
		$rc_float_right = get_current_style($element.parentNode,"float");
	}
	if( $rc_float_right == null || $rc_float_right != "right") $rc_float_right = false;
	
	var $top_container = find_class($element,"rc-container-top");
	if( $top_container.length > 0 )	return;
	var $bottom_container = find_class($element,"rc-container-bottom");
	if( $bottom_container.length > 0 )	return;
	
	for ($i= 0; $i < $classes.length; ++$i){
		$property=$classes[$i].split("-");
		
		if($property[0]=="rc"){	
				switch ($property[1]){
				case "radius":
					$rc_radius=$property[2];
					break;
				case "top":
					$rc_top=$property[2]!="0"?true:false;
					break;
				case "topleft":
					$rc_top_left=$property[2]!="0"?true:false;
					break;
				case "topright":
					$rc_top_right=$property[2]!="0"?true:false;
					break;
				case "bottomleft":
					$rc_bottom_left=$property[2]!="0"?true:false;
					break;
				case "bottomright":
					$rc_bottom_right=$property[2]!="0"?true:false;
					break;
				case "bottom":
					$rc_bottom=$property[2]!="0"?true:false;
					break;
				case "selfcolor":
					$rc_self_color="#"+$property[2];
					break;
				case "parentcolor":
					$rc_parent_color=$property[2]=="transparent"?"transparent":"#"+$property[2];
					break;
				case "inheritstylecolors":
					$rc_parent_color=$property[2]!="0"?false:true;
					$rc_self_color=$property[2]!="0"?false:true;
					break;
				case "antialiased":
					$rc_antialiased=$property[2]!="0"?true:false;
					break;
				case "antialiasedcf":
					$rc_antialiased_cf=parseFloat($property[2]);
					break;
				case "compact":
					$rc_compact=$property[2]!="0"?true:false;
					break;
				case "automargin":
					$rc_auto_margin=$property[2]!="0"?true:false;
					break;
				case "method":
					$rc_method=$property[2];
					break;
				case "border":
					$rc_method="margin";
					$rc_border=true;
					$element.style.border="none";
					break;
				}
			}
		}
		
		//flip the corner if top_left=true && top_right=false
		if( $rc_float_right && ( ($rc_top_left && !$rc_top_right) || (!$rc_top_left && $rc_top_right)) ){
			$rc_top_left = ($rc_top_left==true)? false:true;
			$rc_top_right = ($rc_top_right==true)? false:true;
		}
	
		if( $rc_float_right && ( ($rc_bottom_left && !$rc_bottom_right) || (!$rc_bottom_left && $rc_bottom_right)) ){
			$rc_bottom_left = ($rc_bottom_left==true)? false:true;
			$rc_bottom_right =($rc_bottom_right==true)? false:true;
		}
		
		
		
	if($rc_antialiased && $rc_method=="margin")
		{
		var $arr_self_color=color2array($rc_self_color);
		var $arr_parent_color=$rc_border?color2array($border_color):color2array($rc_parent_color);
		if($arr_self_color!=false && $arr_parent_color!=false) var $rc_antialiased_color="rgb("+Math.round(($arr_parent_color[0]-$arr_self_color[0])*$rc_antialiased_cf+$arr_self_color[0])+","+Math.round(($arr_parent_color[1]-$arr_self_color[1])*$rc_antialiased_cf+$arr_self_color[1])+","+Math.round(($arr_parent_color[2]-$arr_self_color[2])*$rc_antialiased_cf+$arr_self_color[2])+")";
		else $rc_antialiased=false;
		}
	var $containers=new Array();
	if($rc_top)$containers[0]="top";
	if($rc_bottom)$containers[$containers.length]="bottom";
	if(!$rc_parent_color)$rc_parent_color=get_current_style(document.body,"background-color");
	for($j = 0 ; $j<$containers.length ; ++$j)
		{
		if($j == 'extend'){
		continue;
		}
		$container=$containers[$j];
		$el_container=document.createElement("div");
		$el_container.className="rc-container-"+$container;
		if($rc_parent_color && $rc_method=="margin")
		    {
		    try
		      {
		      $el_container.style.backgroundColor=$rc_parent_color;
		      }
		     catch(ee){self.status="Chyba nastaveni pozadi."}
		    }
		$el_container.style.height=$rc_radius+"px";
		for($i=0;$i<$rc_radius;$i++)
			{
			$el_inner=document.createElement("span");
			if($rc_self_color && $rc_method=="margin")$el_inner.style.backgroundColor=$rc_self_color;
			$el_inner.style.display="block";
			$el_inner.className="rc-inner rc-level-"+$i;
			$ang=Math.asin($i/$rc_radius);
			$el_inner.style.height="1px";
			$el_inner.style.overflow="hidden";
			$width=($rc_radius-Math.round($rc_radius*Math.cos($ang)));
			if($rc_method=="margin")
				{
				
				if( $container=="top" ){
					$el_inner.style.margin="0 "+($rc_top_right?$width:"0")+"px 0 "+($rc_top_left?$width:"0")+"px";					
				}else{
					$el_inner.style.margin="0 "+($rc_bottom_right?$width:"0")+"px 0 "+($rc_bottom_left?$width:"0")+"px";
				}
				
				if($rc_antialiased || $rc_border)
					{
					$bw=Math.ceil($rc_radius*Math.cos(Math.asin(($i-1)/$rc_radius))-$rc_radius*Math.cos($ang));
					if($bw==0)$bw=1;
					//[comments-20080621:start] fix the gap problem
					$el_inner.style.borderWidth="0 "+($bw)+"px 0 "+($bw)+"px";
					//$el_inner.style.borderWidth="0 "+($bw)+"px 0 "+($bw)+"px";
					//[comments-20080621:end] fix the gap problem
					
					if(!$rc_border)
						{
						try{$el_inner.style.borderColor=$rc_antialiased_color;}
						catch($ee){if(!$err_alert)alert("There's probably a wrong CSS declaration of color used (use '#000000' instead of 'black' or '#000'.");$err_alert=true;}
						}
					else
						{
						$el_inner.style.borderColor=($rc_antialiased && $width) ? $rc_antialiased_color : $border_color;
						if($i==$rc_radius-1)
							{
							$el_inner.style.backgroundColor=$border_color;
							}
						}
						$el_inner.style.borderStyle="solid";
					}
				}
			else
				{
				if($rc_parent_color)$el_inner.style.borderColor=$rc_parent_color;
				$el_inner.style.borderStyle="solid";
				//$el_inner.style.borderWidth="0 "+($rc_right?$width:"0")+"px 0 "+($rc_left?$width:"0")+"px";
				
				if( $container=="top" ){
					$el_inner.style.borderWidth="0 "+($rc_top_right?$width:"0")+"px 0 "+($rc_top_left?$width:"0")+"px";
				}else{
					$el_inner.style.borderWidth="0 "+($rc_bottom_right?$width:"0")+"px 0 "+($rc_bottom_left?$width:"0")+"px";
				}
				
				}
			if($container=="top" && $el_container.firstChild)$el_container.insertBefore($el_inner.cloneNode(true),$el_container.firstChild);
			else $el_container.appendChild($el_inner.cloneNode(true));
			delete $el_inner;
			}
		if($rc_compact)
			{
			if($container=="top") $el_container.style.marginBottom="-"+$rc_radius+"px";
			else $el_container.style.marginTop="-"+$rc_radius+"px";
			}
		if($rc_auto_margin)
			{
			$el_container.style.marginLeft="-"+get_current_style($element,"padding-left");
			$el_container.style.marginRight="-"+get_current_style($element,"padding-right");
			if($container=="top") $el_container.style.marginTop="-"+get_current_style($element,"padding-top");
			else $el_container.style.marginBottom="-"+get_current_style($element,"padding-bottom");
			}
		if($container=="top" && $element.firstChild)$element.insertBefore($el_container.cloneNode(true),$element.firstChild);
		else $element.appendChild($el_container.cloneNode(true));
		delete $container;
		}

	}
