﻿function OzKarSlider(objName,IdsArray,delay)
        {
            this.currentOpacity = 100;
            this.currentElement = null;
            this.Items = IdsArray;
            this.ObjectName = objName;
            this.Index = 0;
            this.delay = delay || 1;
            this.onchange = null;
 
            for(var i=0;i<this.Items.length;i++)
            {
                var el = document.getElementById(IdsArray[i]);
                el.opacityValue = 0;
                el.style.position="absolute";
                el.style.zIndex = 100 + i;
                this.setOpacity(el);
            };
            this.currentElement = this.Items[0];
            var el1 = document.getElementById(this.currentElement);
            el1.opacityValue = 100;
            this.setOpacity(el1);
        };
        OzKarSlider.prototype.ChangeSlide = function(ShowElement)
        {
            if(ShowElement!=this.currentElement)
            {
                var firste = document.getElementById(ShowElement);
                var seconde = document.getElementById(this.currentElement);
                firste.opacityValue = 0;
                seconde.opacityValue = 100;
                this.fadeOut(this.ObjectName,ShowElement);
                this.fadeIn(this.ObjectName,this.currentElement);
                this.currentElement = ShowElement;
                if(this.onchange!=null)
                {
                    this.onchange();
                }
            };
        };
        OzKarSlider.prototype.fadeIn = function(objname,targetId)
        {
            var obj = eval("window." + objname);
            
            var targetElement = document.getElementById(targetId);
            targetElement.opacityValue -= this.delay;
            obj.setOpacity(targetElement);
            if(targetElement.opacityValue>0)
                setTimeout('eval("window.' + objname + '").fadeIn("' + objname + '","' + targetId + '")',this.delay);
            else
            {
                targetElement.opacityValue = 0;
                obj.setOpacity(targetElement);
                return;
            };
        };
        OzKarSlider.prototype.fadeOut = function(objname,targetId)
        {
            var obj = eval("window." + objname);
            
            var targetElement = document.getElementById(targetId);
            targetElement.opacityValue += this.delay;
            obj.setOpacity(targetElement);
            if(targetElement.opacityValue < 100)
            {
                setTimeout('eval("window.' + objname + '").fadeOut("' + objname + '","' + targetId + '")',this.delay);
            }
            else
            {
               targetElement.opacityValue = 100;
               obj.setOpacity(targetElement);
                return;
           };
        };
        OzKarSlider.prototype.setOpacity = function(Element)
        {
            if(document.all) Element.style.filter = "Alpha(opacity=" + Element.opacityValue + ")";
            else Element.style.opacity = Element.opacityValue / 100;
            if(Element.opacityValue>0 && Element.style.display=='none')
                Element.style.display='block';
            if(Element.opacityValue<=0  && Element.style.display!='none')
                Element.style.display='none';
        };
        OzKarSlider.prototype.Next = function()
        {
            this.Index++;
            if(this.Index==this.Items.length){this.Index = 0;};
            this.SetSelectedIndex(this.Index);
        };
        OzKarSlider.prototype.Previous = function()
        {
            this.Index--;
            if(this.Index==-1){this.Index = this.Items.length-1;};
            this.SetSelectedIndex(this.Index);
        };
        OzKarSlider.prototype.SetSelectedIndex = function(index)
        {
            this.Index = index
            this.ChangeSlide(this.Items[this.Index]);
        };
        OzKarSlider.prototype.OnChange = function(method)
        {
            this.onchange = method;
        };
