/************************************************
*   mooquee v.02                                 *
*   Http: WwW.developer.ps/moo/mooquee          *
*   Dirar Abu Kteish dirar@zanstudio.com        *
/***********************************************/
// Updated by G Wright www.wrightwaydesign.com.au

var mooquee = new Class({
    initialize: function(element, options) {
		this.setOptions({
			marHeight: 45,
			marWidth: 790, //or 100%...
			steps: 1,
			speed: 50,
			direction: 'left',
			pauseOnOver: true
	    }, options);
	    this.timer = null;
	    this.textElement = null;
	    this.textElement2 = null;
	    this.mooqueeElement = element;	    	    
	    this.constructMooquee();
	},
	constructMooquee: function() {
		var el = this.mooqueeElement;
		el.setStyles({
		    'width' : this.options.marWidth
		    ,'height' : this.options.marHeight		    
		});
		this.textElement = new Element('div',{
		    'class' : 'mooquee-text'
		    ,'id' : 'mooquee-text'
		}).setHTML(el.innerHTML);
		this.textElement2 = new Element('div',{
		    'class' : 'mooquee-text'
		    ,'id' : 'mooquee-text2'
		}).setHTML(el.innerHTML);
		el.setHTML('');
		this.textElement.injectInside(el);
		this.textElement2.injectInside(el);
		this.textElement = $('mooquee-text');
		this.textElement2 = $('mooquee-text2');
		this.textElement.setStyle('left', 0);
		this.textElement2.setStyle('left', (this.textElement.getCoordinates().width.toInt() + 1));
		if(this.options.pauseOnOver){this.addMouseEvents();}
		//start marquee
		this.timer = this.startMooquee.delay(this.options.speed, this);
	},
	addMouseEvents : function(){
	    this.textElement.addEvents({
	        'mouseenter' : function(me){
	            this.clearTimer();
	        }.bind(this),
	        'mouseleave' : function(me){
	            this.timer = this.startMooquee.delay(this.options.speed, this);
	        }.bind(this)
	    });
	    this.textElement2.addEvents({
	        'mouseenter' : function(me){
	            this.clearTimer();
	        }.bind(this),
	        'mouseleave' : function(me){
	            this.timer = this.startMooquee.delay(this.options.speed, this);
	        }.bind(this)
	    });
	},
    startMooquee: function(){
        var pos = this.textElement.getStyle('left').toInt();
        var pos2 = this.textElement2.getStyle('left').toInt();
        this.textElement.setStyle('left', ( pos + (-1 * this.options.steps) + 'px' ));
        this.textElement2.setStyle('left', ( pos2 + (-1 * this.options.steps) + 'px' ));
        this.checkEnd(pos);
        this.checkEnd2(pos2);
        this.timer = this.startMooquee.delay(this.options.speed, this);        
    },
    resumeMooquee: function(){
        this.stopMooquee();
        if(this.options.pauseOnOver){this.addMouseEvents();}
        this.timer = this.startMooquee.delay(this.options.speed, this);        
    },
    stopMooquee: function(){
        this.clearTimer();        
        this.textElement.removeEvents();        
        this.textElement2.removeEvents();        
    },
    clearTimer: function(){
        $clear(this.timer);
    },
    checkEnd: function(pos){
		if(pos < -1 * (this.textElement.getCoordinates().width.toInt())){
			this.textElement.setStyle('left', ((this.textElement2.getStyle('left').toInt() +this.textElement2.getCoordinates().width)+1));
		}
    },
    checkEnd2: function(pos2){
		if(pos2 < -1 * (this.textElement2.getCoordinates().width.toInt())){
			this.textElement2.setStyle('left', ((this.textElement.getStyle('left').toInt() +this.textElement.getCoordinates().width)+1));
		}
    }
});
mooquee.implement(new Options);

var obj;
function startMoorquee() {
	obj = new mooquee($('sponsor-footer'));
	//cancel on mouse over
	//obj = new mooquee($('mooquee1'), {pauseOnOver: false});
}
window.onDomReady(startMoorquee);    

