var TINY1 = {};

//function T$(i) { return document.getElementById(i) }
function T$$(e, p) { return p.getElementsByTagName(e) }

TINY1.slider = function() {
    function slide(SlideShowName, SlideShowStruct) {
        this.SlideShowName = SlideShowName;
        this.init(SlideShowStruct)
    }

    //----------------------------------------------------------------------------------------------------------------
    slide.prototype.init = function(SlideShowStruct) {
        var SlideSection = document.getElementById(SlideShowStruct.id),
        UnorderedList = this.UnorderedList = SlideSection.getElementsByTagName('ul')[0],
        ListItemsArray = UnorderedList.getElementsByTagName('li'),
        NumberOfListItems = ListItemsArray.length,
        i = this.CurrentListItem = this.Position = 0;

        if (SlideShowStruct.navid && SlideShowStruct.activeclass) {
            this.ListItemsArray = document.getElementById(SlideShowStruct.navid).getElementsByTagName('li');
            //T$$('li', document.getElementById(SlideShowStruct.navid));
            this.SlideShowStruct_ActiveClass = SlideShowStruct.activeclass
        }

        this.SlideShowStruct_Auto = SlideShowStruct.auto || 0;
        this.SlideShowStruct_Resume = SlideShowStruct.resume || 0;
        this.SlideShowStruct_Vertical = SlideShowStruct.vertical || 0;
        SlideSection.style.overflow = 'hidden';

        for (i; i < NumberOfListItems; i++) {
            if (ListItemsArray[i].parentNode == UnorderedList) {
                this.CurrentListItem++
            }
        }
        if (this.SlideShowStruct_Vertical) {
            UnorderedList.style.top = 0;
            this.Height = SlideShowStruct.height || ListItemsArray[0].offsetHeight;
            UnorderedList.style.height = (this.CurrentListItem * this.Height) + 'px'
        }
        else {
            UnorderedList.style.left = 0;
            this.Width = SlideShowStruct.width || ListItemsArray[0].offsetWidth;
            UnorderedList.style.width = (this.CurrentListItem * this.Width) + 'px'
        }
        this.pos(SlideShowStruct.position || 0, this.SlideShowStruct_Auto ? 1 : 0)
    },
    //----------------------------------------------------------------------------------------------------------------
	slide.prototype.auto = function() {
    this.UnorderedList.AutoInterval = setInterval(new Function(this.SlideShowName + '.move(1,1)'), this.SlideShowStruct_Auto * 1000)
	},

    //----------------------------------------------------------------------------------------------------------------
	slide.prototype.move = function(Direction, Auto) {
	var NewPosition = this.Position + Direction,
	NewerYetPosition = Direction == 1 ? NewPosition == this.CurrentListItem ? 0 : NewPosition : NewPosition < 0 ? this.CurrentListItem - 1 :            NewPosition;
	
	this.pos(NewerYetPosition, Auto)
	},

    //----------------------------------------------------------------------------------------------------------------
	slide.prototype.pos = function(Position, Auto) {
	    clearInterval(this.UnorderedList.AutoInterval);
	    clearInterval(this.UnorderedList.SetInterval);
	    var StyleTopOrLeft = this.SlideShowStruct_Vertical ? parseInt(this.UnorderedList.style.top) : parseInt(this.UnorderedList.style.left), //was 'o'
		HeightOrWidth = this.SlideShowStruct_Vertical ? Position * this.Height : Position * this.Width, //was 't'
		Direction = HeightOrWidth > Math.abs(StyleTopOrLeft) ? 1 : -1; 
		
		HeightOrWidth = HeightOrWidth * -1;
		this.Position = Position;
	    if (this.ListItemsArray) {
	        for (var i = 0; i < this.CurrentListItem; i++) {
	            this.ListItemsArray[i].className = i == Position ? this.SlideShowStruct_ActiveClass : ''
	        }
	    }
	    this.UnorderedList.SetInterval = setInterval(new Function(this.SlideShowName + '.slide(' + HeightOrWidth + ',' + Direction + ',' +                   Auto + ')'), 20)
	},

    //----------------------------------------------------------------------------------------------------------------
	slide.prototype.slide = function(HeightOrWidth, Direction, Auto) {
	    var TopOrLeft = this.SlideShowStruct_Vertical ? parseInt(this.UnorderedList.style.top) : parseInt(this.UnorderedList.style.left);
	    if (TopOrLeft == HeightOrWidth) {
	        clearInterval(this.UnorderedList.SetInterval);
	        if (Auto || (this.SlideShowStruct_Auto && this.SlideShowStruct_Resume)) { this.auto() }
	    }
	    else {
	        var v = TopOrLeft - Math.ceil(Math.abs(HeightOrWidth - TopOrLeft) * .15) * Direction + 'px';
	        this.SlideShowStruct_Vertical ? this.UnorderedList.style.top = v : this.UnorderedList.style.left = v
	    }
	};

    //----------------------------------------------------------------------------------------------------------------    
    return { slide: slide }
} ();
