
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


function getRandomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var len = 11;
	var randomstring = '';
	for (var i=0; i<len; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}


var roundedCornersPanelScriptsFolder = 'js';

var abtRounded = {};



function renderpanel(a, b, c, d, e, f, g) {
	if ($get(a) == null) {
		alert('ABTRounded Warning:\n\nElement with ID "' + a + '" does not exist on the page. Please, set correct ID of an element you would like to round.');
		return false
	}
	if ($get(a).rel == 'abtRounded') {
		return false
	}
	$stylesheet(roundedCornersPanelScriptsFolder + '/RoundedCornersPanel.JS/RoundedCornersPanel.JS.css', 'abtRoundedBaseStyleSheet');
	var h = $get(a).innerHTML;
	var i = $get(a).offsetHeight;
	if (window.attachEvent) {
		var j = $get(a).currentStyle.backgroundColor;
		var k = $get(a).parentNode.currentStyle.backgroundColor
	} else {
		var l = window.getComputedStyle;
		var m = window.getComputedStyle($get(a).parentNode, '');
		var j = l($get(a), '').getPropertyValue('background-color');
		var k = m.getPropertyValue('background-color')
	}
	$get(a).className += ' roundedCornersPanel';
	$get(a).rel = 'abtRounded';
	$get(a).style.background = k;
	$get(a).innerHTML = '';
	if (b == 'small') {
		$get(a).innerHTML = ['<div style="position: relative;" id="' + a + '_TopPanel">' + '<div class="roundedCornerElement" style="margin-left: 1px; margin-right: 1px; background: ' + j + '; width: auto;">&nbsp;</div>' + '<div class="SkipCorner" style="background: ' + j + '; width: 1px; height: 1px; top: 0; left: 0;" id="' + a + '_HidePanelTopLeftCorner">&nbsp;</div>' + '<div class="SkipCorner" style="background: ' + j + '; width: 1px; height: 1px; top: 0; right: 0;" id="' + a + '_HidePanelTopRightCorner">&nbsp;</div>' + '</div>' + '<div class="roundedCornersPanelContent" id="' + a + '_content" style="background: ' + j + '; padding-left: 5px; padding-right: 5px;">' + h + '</div>' + '<div style="position: relative;" id="' + a + '_BottomPanel">' + '<div class="roundedCornerElement" style="margin-left: 1px; margin-right: 1px; background: ' + j + '; width: auto;">&nbsp;</div>' + '<div class="SkipCorner" style="background: ' + j + '; width: 1px; height: 1px; bottom: 0; right: 0;" id="' + a + '_HidePanelBottomRightCorner">&nbsp;</div>' + '<div class="SkipCorner" style="background: ' + j + '; width: 1px; height: 1px; bottom: 0; left: 0;" id="' + a + '_HidePanelBottomLeftCorner">&nbsp;</div>' + '</div>']
	}
	if (b == 'medium') {
		$get(a).innerHTML = ['<div style="position: relative;" id="' + a + '_TopPanel">' + '<div class="roundedCornerElement" style="border-left: solid 1px ' + c + '; border-right: solid 1px ' + c + '; margin-left: 2px; margin-right: 2px; background: ' + j + '; width: auto;">&nbsp;</div>' + '<div class="roundedCornerElement" style="border-left: solid 1px ' + c + '; margin-left: 1px; border-right: solid 1px ' + c + '; margin-right: 1px; background: ' + j + '; width: auto;">&nbsp;</div>' + '<div class="roundedCornerElement" style="border-left: solid 1px ' + c + '; margin-left: 0px; border-right: solid 1px ' + c + '; margin-right: 0px; background: ' + j + '; width: auto;">&nbsp;</div>' + '<div class="SkipCorner" style="background: ' + j + '; width: 3px; height: 3px; top: 0; left: 0;" id="' + a + '_HidePanelTopLeftCorner">&nbsp;</div>' + '<div class="SkipCorner" style="background: ' + j + '; width: 3px; height: 3px; top: 0; right: 0;" id="' + a + '_HidePanelTopRightCorner">&nbsp;</div>' + '</div>' + '<div class="roundedCornersPanelContent" id="' + a + '_content" style="background: ' + j + '; padding-left: 5px; padding-right: 5px;">' + h + '</div>' + '<div style="position: relative;" id="' + a + '_BottomPanel">' + '<div class="roundedCornerElement" style="border-left: solid 1px ' + c + '; margin-left: 0px; border-right: solid 1px ' + c + '; margin-right: 0px; background: ' + j + '; width: auto;">&nbsp;</div>' + '<div class="roundedCornerElement" style="border-left: solid 1px ' + c + '; margin-left: 1px; border-right: solid 1px ' + c + '; margin-right: 1px; background: ' + j + '; width: auto;">&nbsp;</div>' + '<div class="roundedCornerElement" style="border-left: solid 1px ' + c + '; border-right: solid 1px ' + c + '; margin-left: 2px; margin-right: 2px; background: ' + j + '; width: auto;">&nbsp;</div>' + '<div class="SkipCorner" style="background: ' + j + '; width: 3px; height: 3px; bottom: 0; right: 0;" id="' + a + '_HidePanelBottomRightCorner">&nbsp;</div>' + '<div class="SkipCorner" style="background: ' + j + '; width: 3px; height: 3px; bottom: 0; left: 0;" id="' + a + '_HidePanelBottomLeftCorner">&nbsp;</div>' + '</div>']
	}
	if (b == 'large') {
		$get(a).innerHTML = ['<div style="position: relative;" id="' + a + '_TopPanel">' + '<div class="roundedCornerElement" style="border-left: solid 2px ' + c + '; border-right: solid 2px ' + c + '; margin-left: 3px; margin-right: 3px; background: ' + j + '; width: auto;">&nbsp;</div>' + '<div class="roundedCornerElement" style="border-left: solid 1px ' + c + '; margin-left: 2px; border-right: solid 1px ' + c + '; margin-right: 2px; background: ' + j + '; width: auto;">&nbsp;</div>' + '<div class="roundedCornerElement" style="border-left: solid 1px ' + c + '; margin-left: 1px; border-right: solid 1px ' + c + '; margin-right: 1px; background: ' + j + '; width: auto;">&nbsp;</div>' + '<div class="roundedCornerElement" style="border-left: solid 1px ' + c + '; margin-left: 0px; border-right: solid 1px ' + c + '; margin-right: 0px; background: ' + j + '; width: auto; height: 2px;">&nbsp;</div>' + '<div class="SkipCorner" style="background: ' + j + '; width: 5px; height: 5px; top: 0; left: 0;" id="' + a + '_HidePanelTopLeftCorner">&nbsp;</div>' + '<div class="SkipCorner" style="background: ' + j + '; width: 5px; height: 5px; top: 0; right: 0;" id="' + a + '_HidePanelTopRightCorner">&nbsp;</div>' + '</div>' + '<div class="roundedCornersPanelContent" id="' + a + '_content" style="background: ' + j + '; padding-left: 5px; padding-right: 5px;">' + h + '</div>' + '<div style="position: relative;" id="' + a + '_BottomPanel">' + '<div class="roundedCornerElement" style="border-left: solid 1px ' + c + '; margin-left: 0px; border-right: solid 1px ' + c + '; margin-right: 0px; background: #c6c3de; background: ' + j + '; width: auto; height: 2px;">&nbsp;</div>' + '<div class="roundedCornerElement" style="border-left: solid 1px ' + c + '; margin-left: 1px; border-right: solid 1px ' + c + '; margin-right: 1px; background: ' + j + '; auto;">&nbsp;</div>' + '<div class="roundedCornerElement" style="border-left: solid 1px ' + c + '; margin-left: 2px; border-right: solid 1px ' + c + '; margin-right: 2px; background: ' + j + '; auto;">&nbsp;</div>' + '<div class="roundedCornerElement" style="border-left: solid 2px ' + c + '; border-right: solid 2px ' + c + '; margin-left: 3px; margin-right: 3px; background: ' + j + '; auto;">&nbsp;</div>' + '<div class="SkipCorner" style="background: ' + j + '; width: 5px; height: 5px; bottom: 0; right: 0;" id="' + a + '_HidePanelBottomRightCorner">&nbsp;</div>' + '<div class="SkipCorner" style="background: ' + j + '; width: 5px; height: 5px; bottom: 0; left: 0;" id="' + a + '_HidePanelBottomLeftCorner">&nbsp;</div>' + '</div>']
	}
	if (b == 'small') {
		$get(a + '_content').style.height = i - parseInt('2') + 'px'
	}
	if (b == 'medium') {
		$get(a + '_content').style.height = i - parseInt('6') + 'px'
	}
	if (b == 'large') {
		$get(a + '_content').style.height = i - parseInt('10') + 'px'
	}
	if (!d) {
		$get(a + '_HidePanelTopLeftCorner').style.display = 'block'
	}
	if (!e) {
		$get(a + '_HidePanelTopRightCorner').style.display = 'block'
	}
	if (!f) {
		$get(a + '_HidePanelBottomRightCorner').style.display = 'block'
	}
	if (!g) {
		$get(a + '_HidePanelBottomLeftCorner').style.display = 'block'
	}
}


abtRounded.pageload = function(theClassName, cornerstyle, dithercolor, topleftcorner, toprightcorner, bottomrightcorner, bottomleftcorner)
{

	v = getElementsByClass(theClassName);


for(var count=0; count < v.length; count++){

	theId = v[count].id;
	if(theId == "" || theId == null || theId == undefined){
		theId = getRandomString();
		v[count].setAttribute("id",theId);
	}

 renderpanel(theId, cornerstyle, dithercolor, topleftcorner, toprightcorner, bottomrightcorner, bottomleftcorner);


}

}

abtRounded.demand = function(elementid, cornerstyle, dithercolor, topleftcorner, toprightcorner, bottomrightcorner, bottomleftcorner)
{
	renderpanel(elementid, cornerstyle, dithercolor, topleftcorner, toprightcorner, bottomrightcorner, bottomleftcorner);
}

function $stylesheet(file, id)
{
	var stylesheet = document.createElement('link');

	stylesheet.setAttribute('type', 'text/css');
	stylesheet.setAttribute('rel', 'stylesheet');
	stylesheet.setAttribute('href', file);
	stylesheet.setAttribute('id', id);

	if($get(id) == null)
	{
		document.getElementsByTagName('head')[0].appendChild(stylesheet);
	}
}

function $get(stringId)
{
	return document.getElementById(stringId);
}