﻿//-----------------------------------------------------------------------------------------------------------
// CCC_FadeTicker.js
//
// Copyright 2008, Crystal Creek Consulting.  All rights reserved.
// www.crystalcreekconsulting.com
// 
//-----------------------------------------------------------------------------------------------------------
// Description: Ticker-style display with fade effect
// Created:     06/20/08 MWD
// Updates:     
// 
// Notes:       Due to a problem with IE7's conflict between of DXImageTransform and ClearType fonts, the
//              fade effect is not used.
//-----------------------------------------------------------------------------------------------------------
var FadeTicker = new Class({
	Implements: Options,
    options: {
            duration: 'long',
			delay: 10000,
			onComplete: Class.empty,
			onStart: Class.empty
    },
	initialize: function(el,itemClass,options){
		this.setOptions(options);
		this.el = $(el);
		this.items = $$('div.' + itemClass);  //if no items, no news. if one, no effect
		this.isScrollPaused = false;
		this.isIE7 = Browser.Engine.trident5;
		this.el.addEvent('mouseenter', function(){
            this.pauseScroll(true);
        }.bind(this));
		this.el.addEvent('mouseleave', function(){
            this.pauseScroll(false);
        }.bind(this));
        this.items.each(function(div,index) {
			div.setStyles({
			    position: 'absolute',
			    width: this.el.getSize().x,
			    height: this.el.getSize().y,
			    visibility: 'hidden'
			});
			if (!this.isIE7)
		    {
		        div.setStyle('opacity', 0);
			    div.set('tween', {duration: this.options.duration});
			}
		}.bind(this));
		this.current = -1;
		this.next();
	},
	next: function() {
		if (!this.isScrollPaused)
		{
		    var pos;
		    if (this.current >= 0)
		    {
		        pos = this.items[this.current];
		        if (this.isIE7)
		            pos.setStyles({visibility:'hidden'});
		        else
	                pos.fade('out');
		    }
		    
		    this.current++;
		    if (this.current >= this.items.length) this.current = 0;
		    pos = this.items[this.current];
	        if (this.isIE7)
	            pos.setStyles({visibility:'visible'});
	        else
                pos.fade('in');
	    }
		this.next.bind(this).delay(this.options.delay);
	},
	pauseScroll: function(pause) { 
	    this.isScrollPaused = pause;
	}
});

//window.addEvent('domready', function()
//{
//    var ticker = new FadeTicker('headlines','headline',{delay:8000});
//});
