		var currentLeftRef = 1;
        var refContent = new Array();
        var processing = 0;

        function setAttribute(node, name, value) {
            var i;
            for (i = 0; i < node.attributes.length; i++){
                if (node.attributes[i].name == name){
                    node.attributes[i].value = value;
                }
            }
        }

        function setOpacity(elem,level) {
            //if filters then IE
            //use alpha opacity
            if (elem.filters) {
                elem.style.filter = 'alpha(opacity=' + level + ')';
            } else {
                //else use W3C opacity CSS
                elem.style.opacity = level / 100;
            }
        }

        /**
         * Fade out the required element over time using CSS
         */

        function fadeOut(elemName) {
            //20 frame animation
            elem = document.getElementById(elemName);
            for ( var i = 0; i <= 100; i += 5 ) {
                //anonymous closure makes sure correct i is used
                //for each iteration
                (function(){
                    //opacity is i
                    var opacity = i;
                    //animation
                    setTimeout(function(){
                        // Set the new opacity of the element
                        setOpacity( elem, 100 - opacity );
                        //completely hide the element at 95%
                        if ( opacity == 100 ){
                            elem.innerHTML = "";
                            if(elemName == 'ref' + currentLeftRef){
                                slideOut(elem.parentNode, getWidth(elem), 0, 50, 15, 3);
							}
                            else {
                                var newChild = document.createElement('div');
                                //newChild.setAttribute('id', 'ref' + (currentLeftRef - 1));
                                //newChild.setAttribute('class', 'ref');
                                //newChild.setAttribute('style', 'width:0;');
                                newChild.innerHTML = '<div id="ref'+ (currentLeftRef - 1) + '" class="ref" style="width:0;"></div>';
                                elem.parentNode.parentNode.insertBefore(newChild, document.getElementById('ref' + currentLeftRef).parentNode);
                                newChildElem = document.getElementById('ref' + (currentLeftRef - 1));
                                setOpacity(newChildElem, 0);
                                var elemWidth = getWidth(elem);
                                elem = elem.parentNode;
                                var parentNode = elem.parentNode
                                parentNode.removeChild(elem);
                                slideIn(newChildElem, 0, elemWidth, 50, 15, 3);
                            }
                        }
                        //for smooth animation change the timeout delay
                        //proportionately with opacity
                    }, ( i + 1 ) * 10 );
                })();
            }
        }

        function fadeIn(elemName) {
            //20 frame animation
            elem = document.getElementById(elemName);
            for ( var i = 0; i <= 100; i += 5 ) {
                //anonymous closure makes sure correct i is used
                //for each iteration
                (function(){
                    //opacity is i
                    var opacity = i;
                    //animation
                    setTimeout(function(){
                        // Set the new opacity of the element
                        setOpacity( elem, opacity );
                        //completely hide the element at 95%
                        if ( opacity == 100 ){
                            processing = 0;
                        }
                        //for smooth animation change the timeout delay
                        //proportionately with opacity
                    }, ( i + 1 ) * 10 );
                })();
            }
        }

        function slideOut(elem,startWidth,endWidth,steps,intervals,powr) {
            //Width changer with Memory by www.hesido.com
            if (elem.widthChangeMemInt)
                window.clearInterval(elem.widthChangeMemInt);
            var actStep = 0;
            elem.widthChangeMemInt = window.setInterval(
            function() {
                elem.currentWidth = easeInOut(startWidth,endWidth,steps,actStep,powr);
                elem.style.width = elem.currentWidth + "px";
                actStep++;
                if (actStep > steps) {
                    window.clearInterval(elem.widthChangeMemInt);
                    //elem = elem.parentNode;
                    var parentNode = elem.parentNode;
                    parentNode.removeChild(elem);
                    currentLeftRef++;
                    popOutNewRight(parentNode);
                }
            }
            ,intervals)
        }

        function slideIn(elem,startWidth,endWidth,steps,intervals,powr) {
            //Width changer with Memory by www.hesido.com
            if (elem.widthChangeMemInt)
                window.clearInterval(elem.widthChangeMemInt);
            var actStep = 0;
            elem.widthChangeMemInt = window.setInterval(
            function() {
                elem.currentWidth = easeInOut(startWidth,endWidth,steps,actStep,powr);
                elem.style.width = elem.currentWidth + "px";
                actStep++;
                if (actStep > steps) {
                    window.clearInterval(elem.widthChangeMemInt);
                    currentLeftRef--;
                    popOutNewLeft(elem);
                }
            }
            ,intervals)
        }

        function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) {
            //Generic Animation Step Value Generator By www.hesido.com
            var delta = maxValue - minValue;
            var stepp = minValue+(Math.pow(((1 / totalSteps) * actualStep), powr) * delta);
            return Math.ceil(stepp)
        }

        function getStyle(el, style) {
            if(!document.getElementById) return;
            var value = el.style[toCamelCase(style)];

            if(!value)
                if(document.defaultView)
                    value = document.defaultView.
                getComputedStyle(el, "").getPropertyValue(style);
            else if(el.currentStyle)
                value = el.currentStyle[toCamelCase(style)];
            return value;

        }

        function toCamelCase( sInput ) {
            var oStringList = sInput.split('-');
            if(oStringList.length == 1)
                return oStringList[0];
            var ret = sInput.indexOf("-") == 0 ?
                oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
            for(var i = 1, len = oStringList.length; i < len; i++){
                var s = oStringList[i];
                ret += s.charAt(0).toUpperCase() + s.substring(1)
            }
            return ret;
        }

        function getWidth(theDiv){
            return parseInt(getStyle(theDiv, "width"));
        }

        function popOutNewRight(elem){
            //if last div is cleaner
            var children = elem.childNodes;
            var cleanerClass = "";
            if(children[children.length - 1].className == 'clear') cleanerClass = 'clear';
            else if(children[children.length - 1].className == 'cleaner') cleanerClass = 'cleaner';
            if(cleanerClass != ""){
                elem.removeChild(children[children.length - 1]);
            }
            if(cleanerClass == ""){
                if(children[children.length - 2].className == 'clear') cleanerClass = 'clear';
                else if(children[children.length - 2].className == 'cleaner') cleanerClass = 'cleaner';
                if(cleanerClass != ""){
                    elem.removeChild(children[children.length - 2]);
                }
            }

            var newChild = document.createElement('div');
            //newChild.setAttribute('id', 'ref' + (currentLeftRef + 2));
            //newChild.setAttribute('class', 'ref');
            newChild.innerHTML = '<div id="ref'+ (currentLeftRef + 2) + '" class="ref"></div>';
            elem.appendChild(newChild);
            newChildElem = document.getElementById('ref' + (currentLeftRef + 2));
            setOpacity(newChildElem, 0);
            if(cleanerClass != ""){
                var newCleaner = document.createElement('div');
                newCleaner.setAttribute('class', cleanerClass);
                elem.appendChild(newCleaner);
            }

            var checkTimer = setInterval(function(){
                if(refContent[currentLeftRef + 2] != undefined){
                    clearInterval(checkTimer);
                    newChildElem.innerHTML = refContent[currentLeftRef + 2];
                    fadeIn('ref' + (currentLeftRef + 2));
                }
            }, 100);
        }

        function popOutNewLeft(elem){
            var checkTimer = setInterval(function(){
                if(refContent[currentLeftRef] != undefined){
                    clearInterval(checkTimer);
                    elem.innerHTML = refContent[currentLeftRef];
                    fadeIn('ref' + currentLeftRef);
                }
            }, 100);
        }

        function getRefContent(right){
            if(!processing){
                processing = 1;
                if(right){
				    var url = "php/references/getref.php?nr="+(currentLeftRef + 3);
				    var rq = new SZN.HTTPRequest();
				    rq.setMethod("get");
				    rq.setFormat("txt");
				    rq.setMode("async");
				    rq.send(url,window,"_getRefCallback");
                    fadeOut('ref' + currentLeftRef);
                }
                else {
				    var url = "php/references/getref.php?nr="+(currentLeftRef - 1);
				    var rq = new SZN.HTTPRequest();
				    rq.setMethod("get");
				    rq.setFormat("txt");
				    rq.setMode("async");
				    rq.send(url,window,"_getRefCallback");
                    fadeOut('ref' + (currentLeftRef + 2));
                }
            }
        }

        function _getRefCallback(txt, status){
	        if (status == 200) {
	           var arr = txt.split("#@#");
	           refContent[arr[0]] = arr[1];
	        }
			else alert("Chyba při komunikaci se serverem.");
        }
