/* ********************************************************************* */
/* Sprachwechsler */
/* ********************************************************************* */
window.addEvent('domready', function()
{
    //alert("hghgjkhg");
    var lang = $('lang');
    var langCurrent = $('lang').getElements('.current');
    var subLang = $('subLang');

    lang.addEvent('mouseenter', function(){
        langCurrent.set('class', 'currenthover');
        subLang.setStyle('visibility', 'visible');
        subLang.setStyle('display', 'block');
    });

    lang.addEvent('mouseleave', function(){
        langCurrent.set('class', 'current');
        subLang.setStyle('visibility', 'hidden');
        subLang.setStyle('display', 'none');
    });
});



/* ********************************************************************* */
/* Schriftgroe�e */
/* ********************************************************************* */

addEventExtended(window, 'unload', saveSTGSettings);
window.addEvent('domready',function(){
    setSTGUserOptions();
});  //FF IE7


function addEventExtended(obj, evType, fn){
    if (obj.addEventListener){
        obj.addEventListener(evType, fn, false);
        return true;
    } else if (obj.attachEvent){
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    } else {
        return false;
    }
}

var defaultFontSize = 75;
var currentFontSize = defaultFontSize;
var prefsLoaded = false;

function revertSTGStyles() {
    currentFontSize = defaultFontSize;
    changeSTGFontSize(defaultFontSize);
    setSTGActiveFontImage(defaultFontSize);
}

function changeSTGFontSize(sizeDifference) {
    currentFontSize = parseInt(sizeDifference);
    setSTGFontSize(currentFontSize);
    setSTGActiveFontImage(currentFontSize);
}

function setSTGFontSize(fontSize) {
    var stObj = (document.getElementById) ? document.getElementById('content_area') : document.all('content_area');
    document.body.style.fontSize = fontSize + '%';
}

function createSTGCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else
        expires = "";

    document.cookie = name+"="+value+expires+"; path=/";
};

function readSTGCookieie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0)
            return c.substring(nameEQ.length,c.length);
    }
    return null;
};

function saveSTGSettings() {
    createSTGCookie("fontSize", currentFontSize, 365);
}

function setSTGUserOptions() {
    if(!prefsLoaded){
        cookie = readSTGCookieie("fontSize");
        currentFontSize = cookie ? cookie : defaultFontSize;
        setSTGFontSize(currentFontSize);
        setSTGActiveFontImage(cookie);
        prefsLoaded = true;
    }
}

function setSTGActiveFontImage(fontSize)
{
    var reset = $('mod_fontsize').getElements('.reset');
    var big = $('mod_fontsize').getElements('.big');
    var bigger = $('mod_fontsize').getElements('.bigger');

    if(fontSize == 75 || fontSize == 'undefined')
    {
        reset.set('class', 'reset resetactive');
        big.set('class', 'big');
        bigger.set('class', 'bigger');
    }

    if(fontSize == 80)
    {
        reset.set('class', 'reset');
        big.set('class', 'big bigactive');
        bigger.set('class', 'bigger');
    }

    if(fontSize == 85)
    {
        reset.set('class', 'reset');
        big.set('class', 'big');
        bigger.set('class', 'bigger biggeractive');
    }
}

/* ********************************************************************* */
/* ddmenu */
/* ********************************************************************* */

window.addEvent('domready', function()
{
    //alert('ddmenu');
    autoMenuBackground.initialize();

});


var autoMenuBackground={
    initialize:function(){

        
        //if (is_old_ie){
        //alert('IE');
        autoMenuBackground.ieFix();
        //}
        //else{
        //alert('noIE');
        //}

        count = 0;
        menuSize = 0;
        Array.each(["ddmenu"],function(d){

            $(d).getElements("li").each(function(e){
                if((e.hasClass('sibling') || e.hasClass('active') || e.hasClass('submenu') || e.hasClass('submenu_no_link')) && (e.hasClass('level_1'))){
                    e.addClass('eventAdded');
                    /*
                    e.addEvent("mouseover",function(){
                        autoMenuBackground.autoBgOn(e,false)
                    })
                     */
                    e.addEvent("mouseenter",function(){
                        autoMenuBackground.autoBgOn(e,false)
                    })

                    e.addEvent("mouseleave",function(){
                        autoMenuBackground.autoBgOff(e)
                    })
                }
            })
        /*
            $(d).getElements("ul").each(function(f){
                if(f.hasClass('level_2') || f.hasClass('level_1')){
                    // f.setStyle('height', '1000px');
                   // f.setStyle('width', '1000px');
                }
            });

             */
        });
    },
    autoBgOn:function(item, reload){
        item.addClass('subActive');
        item.addClass('active');
        $(item).getElements("ul").each(function(f){
            if(f.hasClass('level_2')){
                f.setStyle('visibility','hidden');
                $(f).getElements("img").each(function(g){
                    g.setStyle('visibility','visible');              
                });
            }
        });
        autoMenuBackground.calcMenue(item);
        
        //item.border(20px);
        if(reload){
        //    autoMenuBackground.calcMenue(item);
        }

    },


    autoBgOff:function(e){
        var IE8 = false;
        var browserName = navigator.appName;
        var browserVersion = parseInt(navigator.appVersion);
        if (browserName == "Microsoft Internet Explorer" &&
            browserVersion == 4 &&
            navigator.appVersion.indexOf("MSIE 8.") != -1) {
            IE8 = true;
        }
        
        e.removeClass('subActive');
        e.removeClass('active');
        var agt=navigator.userAgent.toLowerCase();
        var is_old_ie = (agt.indexOf("mozilla/4.0") != -1);
        $(e).getElements("ul").each(function(f){
            if(f.hasClass('level_2')){
                if(!IE8){
                    f.setStyle('width', '0px');
                }
                // Tabs verstecken
                f.setStyle('visibility','hidden');
                $(f).getElements("img").each(function(g){
                    g.setStyle('visibility','hidden');              
                });
            }
        });
        $('ddLeftCorner').setStyle('visibility','hidden');
        $('ddRightCorner').setStyle('visibility','hidden');

    //alert('hide');
    },
    ieFix:function(e){
        //alert("Add IE Border");
        var setOverlay = false;
        Array.each(["ddmenu"],function(d){
            wrapperLeft = new Element('div', {
                'id': 'ddLeftCorner'
            });
            wrapperRight = new Element('div', {
                'id': 'ddRightCorner'
            });
            wrapperLeft.innerHTML = "&nbsp";
            wrapperRight.innerHTML = "&nbsp";
            wrapperLeft.inject(d);
            wrapperRight.inject(d);
            $('ddLeftCorner').setStyle('visibility','hidden');
            $('ddRightCorner').setStyle('visibility','hidden');
        });

        // Gif-Overlay für IE8
        var browserName = navigator.appName;
        var browserVersion = parseInt(navigator.appVersion);
        
        if (browserName == "Microsoft Internet Explorer" &&
            browserVersion == 4 &&
            navigator.appVersion.indexOf("MSIE 8.") != -1) {
            setOverlay = true;
        }
        /*
 * Overlay für alte Opera?
if(browserName == "Opera"){
            browserVersion = parseFloat(navigator.appVersion);
            if(browserVersion < 9.8){
                setOverlay = true;
            }
        }
  */      
        if(setOverlay){
            $($('header')).getElements("div").each(function(d){
                if(d.hasClass('mod_stg_coverpicture')){
                    coverPictureCorner = new Element('div', {
                        'id': 'coverpictureRoundBox'
                    });
                    coverPictureCorner.innerHTML = '<img alt="" src="tl_files/design/HeaderRoundBorderBottom.gif">';
                    coverPictureCorner.inject(d);
                }
            });
        }
       
    },
    calcMenue:function(e){
        //return;
        subcount = 0;
        height = 0;
        width = 0;
        arrHeight = new Array();
        arrWidth = new Array();
        hasSubmenu = false;
        readMinSize = true;
        minSize = 0;

        level_1_padding = 22;

        objects = 0;
        arrObject = new Array();
        arrVal = new Array();

        var IE6 = false;
        var IE7 = false;
        var IE8 = false;
        var is_old_ie = false;


        var browserName = navigator.appName;
        var browserVersion = parseInt(navigator.appVersion);
        
        if (browserName == "Microsoft Internet Explorer" &&
            browserVersion == 4 &&
            navigator.appVersion.indexOf("MSIE 6.") != -1) {
            IE6 = true;
        }
        if (browserName == "Microsoft Internet Explorer" &&
            browserVersion == 4 &&
            navigator.appVersion.indexOf("MSIE 7.") != -1) {
            IE7 = true;
        }
        if (browserName == "Microsoft Internet Explorer" &&
            browserVersion == 4 &&
            navigator.appVersion.indexOf("MSIE 8.") != -1) {
            IE8 = true;
        }
        if (browserName == "Microsoft Internet Explorer") {
            is_old_ie = true;
        }


        Array.each(["ddmenu"],function(d){
            minSize = 0;
            $(d).getElements("li").each(function(e){
                if(readMinSize && (e.hasClass('eventAdded') &&  e.hasClass('level_1'))){
                    ulSize = e.getSize();
                    minSize += ulSize.x;
                    e.addClass('li_size_' + ulSize.x);
                    e.addClass('ul_size_' + minSize);
                }
                if(e.hasClass('subActive')){
                    width = 0;
                    readMinSize = false;
                    $(e).getElements("ul").each(function(f){
                        hasSubmenu = false;
                        sizeMain = e.getSize();
                        if(f.hasClass('level_2')){
                            height = sizeMain.y;
                            $(f).getElements("li").each(function(g){
                                size = g.getSize();
                                if(g.hasClass('submenu')){
                                    // mit Unterpunkten
                                    hasSubmenu = true;
                                    subcount += 1;
                                    arrHeight[subcount] = size.y + 10;
                                    arrWidth[subcount] = size.x ;
                                    $(g).getElements("img").each(function(imgL2){
                                        imgsize = imgL2.getSize();
                                        arrHeight[subcount] += imgsize.y;
                                    });
                                //Zusatzelement für abgerundete Ecken
                                    
                                //$('ddLeftCorner').setStyle('visibility','visible');
                                //$('ddRightCorner').setStyle('visibility','visible');
                                }
                                else{
                                    if(!hasSubmenu){
                                        subcount += 1;
                                        heightNoSub = g.getSize();
                                        arrHeight[subcount] = heightNoSub.y;
                                        $(g).addClass("no_sub_found");
                                        $(g).getElements("img").each(function(imgL2){
                                            imgsize = imgL2.getSize();
                                            arrHeight[subcount] = imgsize.y + 10;
                                            $(g).addClass("pic_" + imgsize.y);
                                        });                                        
                                        if(!arrWidth[subcount]){
                                            arrWidth[subcount] = 0;
                                        }
                                        //arrWidth[subcount] = arrWidth[subcount] + size.x + 2;
                                        // Feste Breite ...
                                        arrWidth[subcount] = arrWidth[subcount] + 186;
                                    }
                                    $(g).addClass("tab_" + size.y);
                                    arrHeight[subcount] = arrHeight[subcount] + size.y + 1;
                                    $(g).addClass("l2_h_" + subcount + "_" + arrHeight[subcount]);
                                    $(g).addClass("l2_w_" + subcount + "_" + arrWidth[subcount]);
                                }
                            })
                            while(subcount){
                                if(height < arrHeight[subcount]){
                                    height = arrHeight[subcount];
                                }
                                width += arrWidth[subcount];
                                subcount -= 1;
                            }
                            if(hasSubmenu){
                                width += 20;
                            }
                            if(width <= minSize){
                                width = minSize;
                            }

                            level_1_padding += height;

                            $(d).getElements("ul").each(function(i){
                                if(i.hasClass('level_1')){
                                    i.addClass('level_1_y_' + level_1_padding);
                                    i.setStyle('height', level_1_padding+'px');
                                    // ##IE6
                                    if(is_old_ie){
                                        i.setStyle('visibility','visible');
                                        f.setStyle('left', '0');
                                        f.setStyle('top', '32px');
                                        $("ddmenu").setStyle('height', level_1_padding+'px');
                                    }
                                }
                            })
                            // ##IE6
                            f.setStyle('visibility','visible');
                            if(is_old_ie){
                                f.setStyle('left', '0');
                                f.setStyle('top', '32px');
                                if(IE6){
                                    height = height / 2 + 20;
                                    heightLC = height + 32;
                                }
                                else{
                                    heightLC = height + 22;
                                }
                                //if(IE8){
                                /*
                                if(true){
                                           $(f).getElements("img").each(function(imgL2){
                                              imgL2.setStyle('visibility','visible'); 
                                           }) 
                                    }
                                */
                                $('ddLeftCorner').setStyle('top', heightLC+'px');
                            }
                            // IE6##
                            $(f).addClass("ber_width_" + width);
                            if(width >= 928){
                                width = 928;
                            }
                            f.setStyle('width', width+'px');
                            f.setStyle('height', height+'px');
                            widthLC = width;
                            widthRC = 928 - width + 25;
                            $('ddLeftCorner').setStyle('width', widthLC+'px');
                            if(is_old_ie){
                                $('ddLeftCorner').setStyle('visibility','visible');  
                            }
                        }
                    });
                }
            })
        });
    }
};





/* ********************************************************************* */
/* Dropdown */
/* ********************************************************************* */
/**/
var disappeardelay=200  //menu disappear speed onMouseout (in miliseconds)
var appeardelay=250  //menu appear speed onMouseover (in miliseconds)
var enableanchorlink=0 //Enable or disable the anchor link when clicked on? (1=e, 0=d)
var hidemenu_onclick=0 //hide menu when user clicks within menu? (1=yes, 0=no)

/////No further editting needed

var ie5=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
    var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
    var parentEl=what.offsetParent;
    while (parentEl!=null){
        totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
        parentEl=parentEl.offsetParent;
    }
    return totaloffset;
}

function showhide(obj, e, visible, hidden){
    if (ie5||ns6)
        dropmenuobj.style.left=dropmenuobj.style.top=-500
    if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
        delayshowmenu()
    else if (e.type=="click")
        obj.visibility=hidden
}

function iecompattest(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
    var edgeoffset=0
    if (whichedge=="rightedge"){
        var windowedge=ie5 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
        dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
        if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
            edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
    }
    else{
        var topedge=ie5 && !window.opera? iecompattest().scrollTop : window.pageYOffset
        var windowedge=ie5 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
        dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
        if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
            edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
            if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
                edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
        }
    }
    return edgeoffset
}
/**/
function dropdownmenu(obj, e, dropmenuID){
    /**/
    if (window.event) event.cancelBubble=true
    else if (e.stopPropagation) e.stopPropagation()
    if (typeof dropmenuobj!="undefined") //hide previous menu
        dropmenuobj.style.visibility="hidden"
    clearhidemenu()
    if (ie5||ns6){
        obj.onmouseout=delayhidemenu
        dropmenuobj=document.getElementById(dropmenuID)
        if (hidemenu_onclick) dropmenuobj.onclick=function(){
            dropmenuobj.style.visibility='hidden'
        }
        dropmenuobj.onmouseover=clearhidemenu
        dropmenuobj.onmouseout=ie5? function(){
            dynamichide(event)
        } : function(event){
            dynamichide(event)
        }
        showhide(dropmenuobj.style, e, "visible", "hidden")
        dropmenuobj.x=getposOffset(obj, "left")
        dropmenuobj.y=getposOffset(obj, "top")
        dropmenuobj.style.left="0"
        dropmenuobj.style.top="29px"

    }

    return clickreturnvalue()
/**/
}
/**/
function clickreturnvalue(){
    if ((ie5||ns6) && !enableanchorlink) return false
    else return true
}

function contains_ns6(a, b) {
    while (b.parentNode)
        if ((b = b.parentNode) == a)
            return true;
    return false;
}

function dynamichide(e){
    if (ie5&&!dropmenuobj.contains(e.toElement))
        delayhidemenu()
    else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
        delayhidemenu()
}

function delayhidemenu(){
    clearhidemenu()
    delayhide=setTimeout("dropmenuobj.style.visibility='hidden'",disappeardelay)
}

function delayshowmenu(){
    delayshow=setTimeout("dropmenuobj.style.visibility='visible'",appeardelay)
}

function clearhidemenu(){
    if (typeof delayhide!="undefined")
        clearTimeout(delayhide)
    if (typeof delayshow!="undefined")
        clearTimeout(delayshow)
}



var script_element=0,heads=0;
function LoadJavaScript(file_url)
/* Laedt ein JavaScript mit dem spezifizierten Dateinamen
   Achtung: wurde bisher nur in MSIE und Mozilla/Netscape mit Erfolg getestet */
{
    /* wenn nicht schon getan:
   Array aller Head-Bereiche geben lassen (normalerweise gibt's nur einen): */
    if (heads==0)
        heads=document.getElementsByTagName("head");

    /* wenn schonmal geladen: altes Script-Element wegwerfen */
    if (script_element!=0)
    {
        heads[0].removeChild(script_element);
        delete script_element;
    }

    /* neues Script-Element erzeugen: */
    script_element=document.createElement("script");

    /* Skript-MimeType auf text/javascript setzen: */
    script_element.type="text/javascript";

    /* Quelldatei angeben: */
    script_element.src=file_url;

    /* Das Script in den ersten (der nullte ist der erste :-] ) Head-Bereich einbinden
   (veranlasst Ladevorgang und Ausfuehrung): */
    heads[0].appendChild(script_element);
}


/*
---
description: BorderRadius - Mootools plugin to round corners

license: MIT-style license.

authors: 
    - Bui Minh Long (http://minhlong139.plus.vn/) (minhlong139@gmail.com)
    
requires:
    core/1.2.3: '*'
    
provides: [Element, Elements, $, $$]

...
 */


var BorderRadius = new Class({
  
    Implements: [Options],

    options: {
        radiusTopLeft: 0,
        radiusTopRight: 0,
        radiusTop: 0,
        radiusBottomLeft: 0,
        radiusBottomRight: 0,
        radiusBottom: 0,
        radius: 0,
        borderWidth: null,
        borderStyle: null,
        borderColor: null,
        parentBgColor: 'transparent',
        css3: true,
        wrapperClass: 'border-radius-wrapper',
        key: 'border-radius-lDwEgapDpDOIasdlWERSDFxclvkjs234oiSDFSDFsadg@#$098t356sgdlfgjsDFGS@dsfgkyoire'
    },
  
    borderRadier: {},
  
    initialize: function(element, options) {
        this.element = element;
        this.initOptions(options);
        this.build();
    },
  
    initOptions: function(options) {
        var opts = JSON.decode(this.element.getProperty('options'));
        options = $merge(opts, options)
        this.setOptions(options);
        var parentBgColor = this.element.getParent().getStyle('background-color');
        parentBgColor = parentBgColor=='transparent'?this.options.parentBgColor:parentBgColor;
    
        this.options.borderWidth = this.options.borderWidth==null?parseInt(this.element.getStyle('border-top-width')):this.options.borderWidth;
        this.options.borderStyle = this.options.borderStyle==null?this.element.getStyle('border-top-style'):this.options.borderStyle;
        this.options.borderStyle = this.options.borderStyle=='none'?'solid':this.options.borderStyle;
        this.options.borderColor = this.options.borderColor==null?this.element.getStyle('border-top-color'):this.options.borderColor;
    
        if (options.radius) this.setOptions({
            'radiusBottomLeft': options.radius,
            'radiusTopLeft':    options.radius,
            'radiusBottomRight': options.radius,
            'radiusTopRight':    options.radius
        });
        if (options.radiusTop) this.setOptions({
            'radiusTopLeft':    options.radiusTop,
            'radiusTopRight':    options.radiusTop
        });
        if (options.radiusBottom) this.setOptions({
            'radiusBottomLeft': options.radiusBottom,
            'radiusBottomRight': options.radiusBottom
        });
        ['radiusBottomLeft', 'radiusTopLeft', 'radiusBottomRight', 'radiusTopRight'].each(function(pos) {
            if (options[pos]) this.options[pos] = options[pos];
        }.bind(this));
        this.setOptions({
            'parentBgColor': parentBgColor
        });
    },
  
    build: function() {
        if (this.element.hasClass(this.options.key)) return;
        this.element.addClass(this.options.key);
        if (this.options.css3) {
            if (!this.buildByCss3()) this.fixCss3();
        } else {
            this.fixCss3();
        }
    },
  
    wrap: function() {
        var paddingTop = Math.max(parseInt(this.element.getStyle('padding-top')), this.options.radiusTop);
        if (paddingTop>=this.options.radiusTop) paddingTop -= this.options.radiusTop
        this.paddingTop = paddingTop;
        var paddingBottom = Math.max(parseInt(this.element.getStyle('padding-bottom')), this.options.radiusBottom);
        if (paddingBottom>=this.options.radiusBottom) paddingBottom -= this.options.radiusBottom;
        this.paddingBottom = paddingBottom;
        var styles = {
            'padding': this.element.getStyle('padding'),
            'padding-top': paddingTop,
            'padding-bottom': paddingBottom,
            'display': 'block'
        }
        this.wrapper = new Element('div', {
            'class': this.options.wrapperClass
        });
        this.wrapper.innerHTML = this.element.innerHTML;
        this.element.innerHTML = '';
        this.wrapper.setStyles(styles).inject(this.element.setStyle('padding', 0), 'bottom');
    },
  
    fixCss3: function() {
        this.wrap();
    
        var hasBorder = false;
        var position = {
            'top': {
                'left': this.options.radiusTopLeft,
                'right': this.options.radiusTopRight
            },
            'bottom': {
                'left': this.options.radiusBottomLeft,
                'right': this.options.radiusBottomRight
            }
        };
    
        if (this.options.borderWidth>0) {
            this.element.setStyle('border', 'none');
            hasBorder = true;
            var styles = {
                'border-width': this.options.borderWidth,
                'border-style': this.options.borderStyle,
                'border-color': this.options.borderColor,
                'background-color': this.element.getStyle('background-color')
            }
            if (this.options.radiusBottomLeft!=0 || this.options.radiusBottomRight!=0) styles['border-bottom'] = 'none';
            if (this.options.radiusTopLeft!=0 || this.options.radiusTopRight!=0) styles['border-top'] = 'none';
            this.wrapper.setStyles(styles);
        }
    
        for (var id in position) {
            var el = new Element('div').setStyles({
                'display': 'block'
            });
            el.inject(this.element, id);
            this.borderRadier[id] = el;
            for (var i=0;i<Math.max(position[id].left, position[id].right);i++){
                var roundNumLeft = Math.round(Math.sqrt(Math.max(position[id].left*position[id].left-i*i, 0)));
                var floorNumLeft = Math.floor(Math.sqrt(Math.max(position[id].left*position[id].left-i*i, 0)));
                var roundNumRight = Math.round(Math.sqrt(Math.max(position[id].right*position[id].right-i*i, 0)));
                var floorNumRight = Math.floor(Math.sqrt(Math.max(position[id].right*position[id].right-i*i, 0)));

                var borderLeft = position[id].left==0?0:Math.max(position[id].left - roundNumLeft, 0);
                var borderRight = position[id].right==0?0:Math.max(position[id].right - roundNumRight, 0);
                var bgCornerStyles = {
                    'display': 'block',
                    'overflow': 'hidden',
                    'height': 1,
                    'position': 'relative',
                    'border-color': this.options.parentBgColor,
                    'border-style': 'solid',
                    'border-left-width': borderLeft,
                    'border-right-width': borderRight,
                    'border-top-width': 0,
                    'border-bottom-width': 0,
                    'background-color': this.element.getStyle('background-color')
                };
        
                var opacityStyles = {
                    'height': 1,
                    'border-color': this.options.parentBgColor,
                    'border-style': this.options.borderStyle,
                    'border-width': '0px 1px'
                };
                var borderStyles = {
                    'height': 1,
                    'border-color': this.options.borderColor,
                    'border-style': this.options.borderStyle,
                    'border-width': '0px ' + this.options.borderWidth+ 'px',
                    'border-top-width': i>=Math.max(position[id].left, position[id].right)-this.options.borderWidth?this.options.borderWidth:0
                };
                var bgCorner = (new Element('div', {
                    'class': i
                })).setStyles(bgCornerStyles)
                .inject(el, id);
                // TODO: Make corners more smoothly
                //var opacityBorder = (new Element('div')).setStyles(opacityStyles).setOpacity(0.5).inject(bgCorner);
                if (hasBorder) (new Element('div')).setStyles(borderStyles)
                    .inject(bgCorner);
            }
        }
        this.autoResize();
    },
  
    autoResize: function() {
        var h = 0;
        for (var id in this.borderRadier)
            h+= this.borderRadier[id].getSize().y;
        var height = this.element.getSize().y - h - this.paddingTop - this.paddingBottom;
        if (height>0) this.wrapper.setStyle('height', height);
    },
  
    buildByCss3: function() {
        if (this.checkBorderRadius()) {
            var styles = {
                gecko: {
                    '-moz-border-radius-topleft': this.options.radiusTopLeft,
                    '-moz-border-radius-topright': this.options.radiusTopRight,
                    '-moz-border-radius-bottomleft': this.options.radiusBottomLeft,
                    '-moz-border-radius-bottomright': this.options.radiusBottomRight
                },
                webkit: {
                    '-webkit-border-top-left-radius': this.options.radiusTopLeft,
                    '-webkit-border-top-right-radius': this.options.radiusTopRight,
                    '-webkit-border-bottom-left-radius': this.options.radiusBottomLeft,
                    '-webkit-border-bottom-right-radius': this.options.radiusBottomRight
                }
            }
            if (styles[Browser.Engine.name]) {
                this.element.setStyles(styles[Browser.Engine.name]);
                return true;
            }
        }
        return false;
    },
  
    /*
     * Many thanks to the Arian Stolwijk (http://www.aryweb.nl/) for checkBorderRadius() idea.
     */
    checkBorderRadius: function(){
        var docEl = document.documentElement, s;
        if (docEl && (s = docEl.style)) {
            return (typeof s.borderRadius == 'string'
                || typeof s.MozBorderRadius == 'string'
                || typeof s.WebkitBorderRadius == 'string'
                || typeof s.KhtmlBorderRadius == 'string');
        }
        return null;
    }

});

Element.implement({
    borderRadius: function (options) {
        var br = new BorderRadius(this, options);
        this.store('br', br);
        return br;
    }
});



/**/
