var clientQuotes = function () {

    // private properties
    var quotes = new Array();
    var quoteCount = 0; 
    var currentQuote = 0; 
    // private methods
    var updateQuoteCount = function () { 
        quoteCount = quotes.length;
    };
    var addEventListeners = function() {
        var c = $('clientList').getElementsBySelector('DIV.prevnext A');
        for (var i = 0;  i < c.length; i++) {
            Event.observe(c[i], "mousedown",
                handleClick.bindAsEventListener(this), true);
        }
    };
    var handleClick = function(e) {
        Event.stop(e);
        var elem = Event.findElement(e, 'A');
        if (toolkit.element.hasClassName(elem, 'left')) {
            getPrev();
        } else if (toolkit.element.hasClassName(elem, 'right')) {
            getNext();
        } else {
            return false;
        }
        showQuote(); 
    };
    var showQuote = function() {
        updateControls();
        var q = $('quote');
        q.innerHTML = quotes[currentQuote];
        if (currentQuote == 0) {
            q.style.background = ''; 
            q.childNodes[l].style.background = ''; 
            q.childNodes[l].style.paddingBottom = ''
        } else {
            q.style.background	= 'url(\'images/quotes_left.png\') no-repeat 15px 0';
            q.style.position	= 'relative';
            q.style.zIndex		= 5;
            l = q.childNodes.length - 1;
            q.childNodes[l].style.background = 'url(\'images/quotes_right.png\') no-repeat bottom right';
            q.childNodes[l].style.paddingBottom = '15px';
            q.childNodes[l].style.height = '32px';
            q.childNodes[l].style.bottom = '-10px';
            q.childNodes[l].style.position = 'absolute';
            q.childNodes[l].style.right = 0;
            q.childNodes[l].style.width = '45px';
            q.childNodes[l].style.zIndex = 1;
if(typeof(fixPng) != 'undefined') {
	q.style.backgroundImage = 'none';
	q.style.width = '350px';
	q.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="images/quotes_left.png", sizingMethod="crop", enabled="true")';
	l = q.childNodes.length - 1;
	q.childNodes[l].style.backgroundImage = 'none';
	q.childNodes[l].style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="images/quotes_right.png", sizingMethod="crop", enabled="true")';
}
        }

    }
    var getNext = function() {
        currentQuote = 
            currentQuote == quoteCount - 1 ? 0 : currentQuote + 1;
        return quotes[currentQuote];
    };
    var getPrev = function() {
        currentQuote = 
            currentQuote == 0 ? quoteCount - 1 : currentQuote - 1;
        return quotes[currentQuote];
    };
    var updateControls = function() {
        var l = quotes.length - 1;
        var c = $('clientList').getElementsBySelector('DIV.prevnext A');
        if (currentQuote != 0 && currentQuote != l) {
            c[0].style.visibility = 'visible';
            c[1].style.visibility = 'visible';
        }
        if (currentQuote == 0) {
            c[0].style.visibility = 'hidden';
            c[1].style.visibility = 'visible';
        }
        if (currentQuote == l) {
            c[0].style.visibility = 'visible';
            c[1].style.visibility = 'hidden';
        }
    }

    return {
        // public methods
        addQuote: function(quote) {
            quotes.push(quote);
            updateQuoteCount();
            return quoteCount;
        },
        init: function () {
            addEventListeners();
            updateControls();
        }
    };

}();

